From 758cca60367672e745e9c82d82dcdc6408129ccd Mon Sep 17 00:00:00 2001 From: Sebastiaan van Stijn Date: Mon, 16 Sep 2024 10:22:30 +0200 Subject: [PATCH] internal/opts: SetOpts,NamedSetOpts: test for optional value The value is optional for SetOpts (and NamedSetOpts), and implied "true" when omitted. This patch adds a test-case for this. Signed-off-by: Sebastiaan van Stijn --- internal/opts/opts_test.go | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/internal/opts/opts_test.go b/internal/opts/opts_test.go index 954c5baab3..17edeb5f98 100644 --- a/internal/opts/opts_test.go +++ b/internal/opts/opts_test.go @@ -14,11 +14,12 @@ func TestSetOpts(t *testing.T) { assert.NilError(t, o.Set("feature-b=true")) assert.NilError(t, o.Set("feature-c=0")) assert.NilError(t, o.Set("feature-d=false")) + assert.NilError(t, o.Set("feature-e")) - expected := "map[feature-a:true feature-b:true feature-c:false feature-d:false]" + expected := "map[feature-a:true feature-b:true feature-c:false feature-d:false feature-e:true]" assert.Check(t, is.Equal(expected, o.String())) - expectedValue := map[string]bool{"feature-a": true, "feature-b": true, "feature-c": false, "feature-d": false} + expectedValue := map[string]bool{"feature-a": true, "feature-b": true, "feature-c": false, "feature-d": false, "feature-e": true} assert.Check(t, is.DeepEqual(expectedValue, o.GetAll())) err := o.Set("feature=not-a-bool") @@ -34,11 +35,12 @@ func TestNamedSetOpts(t *testing.T) { assert.NilError(t, o.Set("feature-b=true")) assert.NilError(t, o.Set("feature-c=0")) assert.NilError(t, o.Set("feature-d=false")) + assert.NilError(t, o.Set("feature-e")) - expected := "map[feature-a:true feature-b:true feature-c:false feature-d:false]" + expected := "map[feature-a:true feature-b:true feature-c:false feature-d:false feature-e:true]" assert.Check(t, is.Equal(expected, o.String())) - expectedValue := map[string]bool{"feature-a": true, "feature-b": true, "feature-c": false, "feature-d": false} + expectedValue := map[string]bool{"feature-a": true, "feature-b": true, "feature-c": false, "feature-d": false, "feature-e": true} assert.Check(t, is.DeepEqual(expectedValue, o.GetAll())) err := o.Set("feature=not-a-bool")