refactor!: cobra migrate
All checks were successful
continuous-integration/drone/pr Build is passing
continuous-integration/drone/push Build is passing

This commit is contained in:
2024-12-26 17:53:25 +01:00
parent 0df2b15c33
commit 671e1ca276
76 changed files with 12042 additions and 2545 deletions

View File

@ -8,19 +8,19 @@ import (
func TestGetSpecificVersion(t *testing.T) {
tests := []struct {
input mockArgs
input []string
expectedOutput string
}{
// No specified version when command has one or less args
{mockArgs{}, ""},
{mockArgs{[]string{"arg0"}}, ""},
{[]string{}, ""},
{[]string{"arg0"}, ""},
// Second in arg (index-1) is the specified result when command has more than 1 args
{mockArgs{[]string{"arg0", "arg1"}}, "arg1"},
{mockArgs{[]string{"arg0", "arg1", "arg2"}}, "arg1"},
{[]string{"arg0", "arg1"}, "arg1"},
{[]string{"arg0", "arg1", "arg2"}, "arg1"},
}
for _, test := range tests {
if test.expectedOutput != getSpecifiedVersion(&test.input) {
if test.expectedOutput != getSpecifiedVersion(test.input) {
t.Fatalf("result for %s should be %s", test.input, test.expectedOutput)
}
}
@ -28,23 +28,23 @@ func TestGetSpecificVersion(t *testing.T) {
func TestValidateChaosXORVersion(t *testing.T) {
tests := []struct {
input mockArgs
input []string
isChaos bool
expectedResult bool
}{
// Chaos = true, Specified Version absent
{mockArgs{}, true, true},
{[]string{}, true, true},
// Chaos = false, Specified Version absent
{mockArgs{}, false, true},
{[]string{}, false, true},
// Chaos = true, Specified Version present
{mockArgs{[]string{"arg0", "arg1"}}, true, false},
{[]string{"arg0", "arg1"}, true, false},
// Chaos = false, Specified Version present
{mockArgs{[]string{"arg0", "arg1", "arg2"}}, false, true},
{[]string{"arg0", "arg1", "arg2"}, false, true},
}
for _, test := range tests {
internal.Chaos = test.isChaos
res, _ := validateChaosXORVersion(&test.input)
res, _ := validateChaosXORVersion(test.input)
if res != test.expectedResult {
t.Fatalf(
"When args are %s and Chaos mode is %t result needs to be %t",
@ -55,43 +55,3 @@ func TestValidateChaosXORVersion(t *testing.T) {
}
}
}
type mockArgs struct {
v []string
}
func (a *mockArgs) Get(n int) string {
if len(a.v) > n {
return a.v[n]
}
return ""
}
func (a *mockArgs) First() string {
return a.Get(0)
}
func (a *mockArgs) Tail() []string {
if a.Len() >= 2 {
tail := a.v[1:]
ret := make([]string, len(tail))
copy(ret, tail)
return ret
}
return []string{}
}
func (a *mockArgs) Len() int {
return len(a.v)
}
func (a *mockArgs) Present() bool {
return a.Len() != 0
}
func (a *mockArgs) Slice() []string {
ret := make([]string, len(a.v))
copy(ret, a.v)
return ret
}