mirror of
https://github.com/ahmetb/kubectx.git
synced 2025-08-10 11:41:59 +00:00
Fix UnsupportedOp tests through custom comparer
Signed-off-by: Ahmet Alp Balkan <ahmetb@google.com>
This commit is contained in:
parent
077d8a829d
commit
562631ad2b
@ -60,22 +60,23 @@ func Test_parseArgs_new(t *testing.T) {
|
|||||||
want: RenameOp{"a", "."}},
|
want: RenameOp{"a", "."}},
|
||||||
{name: "unrecognized flag",
|
{name: "unrecognized flag",
|
||||||
args: []string{"-x"},
|
args: []string{"-x"},
|
||||||
want: UnsupportedOp{Err: fmt.Errorf("unsupported option \"-x\"")}},
|
want: UnsupportedOp{Err: fmt.Errorf("unsupported option '-x'")}},
|
||||||
{name: "too many args",
|
{name: "too many args",
|
||||||
args: []string{"a", "b", "c"},
|
args: []string{"a", "b", "c"},
|
||||||
want: UnsupportedOp{Err: fmt.Errorf("too many arguments")}},
|
want: UnsupportedOp{Err: fmt.Errorf("too many arguments")}},
|
||||||
// TODO add more UnsupportedOp cases
|
|
||||||
|
|
||||||
// TODO consider these cases
|
|
||||||
// - kubectx foo --help
|
|
||||||
// - kubectx -h --help
|
|
||||||
// - kubectx -d foo --h
|
|
||||||
}
|
}
|
||||||
for _, tt := range tests {
|
for _, tt := range tests {
|
||||||
t.Run(tt.name, func(t *testing.T) {
|
t.Run(tt.name, func(t *testing.T) {
|
||||||
got := parseArgs(tt.args)
|
got := parseArgs(tt.args)
|
||||||
|
|
||||||
if diff := cmp.Diff(got, tt.want); diff != "" {
|
var opts cmp.Options
|
||||||
|
if _, ok := tt.want.(UnsupportedOp); ok {
|
||||||
|
opts = append(opts, cmp.Comparer(func(x, y UnsupportedOp) bool {
|
||||||
|
return (x.Err == nil && y.Err == nil) || (x.Err.Error() == y.Err.Error())
|
||||||
|
}))
|
||||||
|
}
|
||||||
|
|
||||||
|
if diff := cmp.Diff(got, tt.want, opts...); diff != "" {
|
||||||
t.Errorf("parseArgs(%#v) diff: %s", tt.args, diff)
|
t.Errorf("parseArgs(%#v) diff: %s", tt.args, diff)
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
|
Loading…
Reference in New Issue
Block a user