-
Notifications
You must be signed in to change notification settings - Fork 344
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add support repetitive arguments to operand #1434
Changes from 5 commits
864e940
4048e37
a62d5e4
2d48777
eae65f7
014d50c
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -6,6 +6,7 @@ import ( | |
"testing" | ||
|
||
"github.com/stretchr/testify/assert" | ||
"github.com/stretchr/testify/require" | ||
) | ||
|
||
func TestSimpleOption(t *testing.T) { | ||
|
@@ -148,3 +149,38 @@ func TestUpdate(t *testing.T) { | |
// verify | ||
assert.Equal(t, o.opts["key"], "new") | ||
} | ||
|
||
func TestStringMap(t *testing.T) { | ||
o := NewOptions(nil) | ||
err := o.UnmarshalJSON([]byte(`{"firstsarg":"v1", "additional-headers":["whatever:thing", "access-control-allow-origin:blerg"]}`)) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Can you add an example with real values here? I'm failing to see why additional-headers should be removed instead of having something like There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I'll add some real examples, This is testing a new method I introduced in this PR. |
||
require.NoError(t, err) | ||
expected := map[string]string{"firstsarg": "v1"} | ||
strMap := o.StringMap() | ||
assert.Len(t, strMap, 1) | ||
assert.Equal(t, expected, strMap) | ||
} | ||
|
||
func TestDeepCopy(t *testing.T) { | ||
o1 := NewOptions(nil) | ||
err := o1.UnmarshalJSON([]byte(`{"firstsarg":"v1", "additional-headers":["whatever:thing", "access-control-allow-origin:blerg"]}`)) | ||
require.NoError(t, err) | ||
copy := o1.opts.DeepCopy() | ||
|
||
assert.Equal(t, copy, &(o1.opts)) | ||
} | ||
|
||
func TestRepetitiveArguments(t *testing.T) { | ||
o := NewOptions(nil) | ||
err := o.UnmarshalJSON([]byte(`{"firstsarg":"v1", "additional-headers":["whatever:thing", "access-control-allow-origin:blerg"]}`)) | ||
require.NoError(t, err) | ||
expected := []string{"--additional-headers=access-control-allow-origin:blerg", "--additional-headers=whatever:thing", "--firstsarg=v1"} | ||
|
||
args := o.ToArgs() | ||
sort.SliceStable(args, func(i, j int) bool { | ||
return args[i] < args[j] | ||
}) | ||
|
||
assert.Len(t, args, 3) | ||
assert.Equal(t, expected, args) | ||
|
||
} |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Don't we have a structure with this signature already?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I can't find it, We have
FreeForm
but that is a different structure withjson *[]byte