-
Notifications
You must be signed in to change notification settings - Fork 351
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Signed-off-by: Mustafa Abdelrahman <[email protected]>
- Loading branch information
1 parent
f6f9efb
commit 8760d94
Showing
3 changed files
with
78 additions
and
28 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,56 @@ | ||
package config | ||
|
||
import ( | ||
"testing" | ||
|
||
"github.com/stretchr/testify/assert" | ||
"github.com/stretchr/testify/require" | ||
"gopkg.in/yaml.v2" | ||
) | ||
|
||
func TestMultiFlagSet(t *testing.T) { | ||
for _, tc := range []struct { | ||
name string | ||
args string | ||
values string | ||
wantErr bool | ||
}{ | ||
{ | ||
name: "single value", | ||
args: "foo=bar", | ||
values: "foo=bar", | ||
wantErr: false, | ||
}, | ||
{ | ||
name: "multiple values", | ||
args: "foo=bar foo=baz foo=qux bar=baz", | ||
values: "foo=bar foo=baz foo=qux bar=baz", | ||
wantErr: false, | ||
}, | ||
} { | ||
t.Run(tc.name, func(t *testing.T) { | ||
multiFlag := &multiFlag{} | ||
err := multiFlag.Set(tc.args) | ||
require.Condition(t, func() bool { | ||
if (err != nil) && tc.wantErr == false { | ||
t.Logf("set error: %v", err) | ||
return false | ||
} else if (err == nil) && tc.wantErr == true { | ||
t.Logf("expected error, got nil") | ||
return false | ||
} else if err != nil { | ||
return false | ||
} | ||
return true | ||
}, "error: %v, wantErr: %v", err, tc.wantErr) | ||
|
||
assert.Equal(t, tc.values, multiFlag.String()) | ||
}) | ||
} | ||
} | ||
|
||
func TestMultiFlagYamlErr(t *testing.T) { | ||
m := &multiFlag{} | ||
err := yaml.Unmarshal([]byte(`-foo=bar`), m) | ||
require.Error(t, err, "Failed to get error on wrong yaml input") | ||
} |