-
Notifications
You must be signed in to change notification settings - Fork 2.4k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[Release-1.24] CLI + Config Enhancement (#7407)
* Handle multiple arguments with StringSlice flags (#7380) * Add helper function for multiple arguments in stringslice * Cleanup server setup with util function Signed-off-by: Derek Nola <[email protected]> * Enable FindString to search dotD config files (#7323) * Enable FindString to search dotD config files * Address multiple arg cases Signed-off-by: Derek Nola <[email protected]>
- Loading branch information
Showing
8 changed files
with
198 additions
and
42 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
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 |
---|---|---|
@@ -1,4 +1,5 @@ | ||
foo-bar: baz | ||
alice: bob | ||
a-slice: | ||
- 1 | ||
- "2" | ||
|
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 |
---|---|---|
|
@@ -11,4 +11,5 @@ c-slice: | |
- two | ||
d-slice: | ||
- one | ||
- two | ||
- two | ||
f-string: beta |
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,51 @@ | ||
package deps | ||
|
||
import ( | ||
"net" | ||
"reflect" | ||
"testing" | ||
|
||
certutil "github.com/rancher/dynamiclistener/cert" | ||
) | ||
|
||
func Test_UnitAddSANs(t *testing.T) { | ||
type args struct { | ||
altNames *certutil.AltNames | ||
sans []string | ||
} | ||
tests := []struct { | ||
name string | ||
args args | ||
want certutil.AltNames | ||
}{ | ||
{ | ||
name: "One IP, One DNS", | ||
args: args{ | ||
altNames: &certutil.AltNames{}, | ||
sans: []string{"192.168.205.10", "192.168.205.10.nip.io"}, | ||
}, | ||
want: certutil.AltNames{ | ||
IPs: []net.IP{net.ParseIP("192.168.205.10")}, | ||
DNSNames: []string{"192.168.205.10.nip.io"}, | ||
}, | ||
}, | ||
{ | ||
name: "Two IP, No DNS", | ||
args: args{ | ||
altNames: &certutil.AltNames{}, | ||
sans: []string{"192.168.205.10", "10.168.21.15"}, | ||
}, | ||
want: certutil.AltNames{ | ||
IPs: []net.IP{net.ParseIP("192.168.205.10"), net.ParseIP("10.168.21.15")}, | ||
}, | ||
}, | ||
} | ||
for _, tt := range tests { | ||
t.Run(tt.name, func(t *testing.T) { | ||
addSANs(tt.args.altNames, tt.args.sans) | ||
if !reflect.DeepEqual(*tt.args.altNames, tt.want) { | ||
t.Errorf("addSANs() = %v, want %v", *tt.args.altNames, tt.want) | ||
} | ||
}) | ||
} | ||
} |
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,39 @@ | ||
package util | ||
|
||
import ( | ||
"reflect" | ||
"testing" | ||
|
||
"github.com/urfave/cli" | ||
) | ||
|
||
func Test_UnitSplitSliceString(t *testing.T) { | ||
tests := []struct { | ||
name string | ||
arg cli.StringSlice | ||
want []string | ||
}{ | ||
{ | ||
name: "Single Argument", | ||
arg: cli.StringSlice{"foo"}, | ||
want: []string{"foo"}, | ||
}, | ||
{ | ||
name: "Repeated Arguments", | ||
arg: cli.StringSlice{"foo", "bar", "baz"}, | ||
want: []string{"foo", "bar", "baz"}, | ||
}, | ||
{ | ||
name: "Multiple Arguments and Repeated Arguments", | ||
arg: cli.StringSlice{"foo,bar", "zoo,clar", "baz"}, | ||
want: []string{"foo", "bar", "zoo", "clar", "baz"}, | ||
}, | ||
} | ||
for _, tt := range tests { | ||
t.Run(tt.name, func(t *testing.T) { | ||
if got := SplitStringSlice(tt.arg); !reflect.DeepEqual(got, tt.want) { | ||
t.Errorf("SplitSliceString() = %+v\nWant = %+v", got, tt.want) | ||
} | ||
}) | ||
} | ||
} |