Skip to content

Commit

Permalink
fix(tests): Skip "undeleteable" store types during tests
Browse files Browse the repository at this point in the history
Signed-off-by: spbsoluble <[email protected]>
  • Loading branch information
spbsoluble committed Sep 5, 2024
1 parent d451c41 commit eb4fecd
Show file tree
Hide file tree
Showing 3 changed files with 38 additions and 0 deletions.
35 changes: 35 additions & 0 deletions cmd/storeTypes_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -242,6 +242,14 @@ func deleteStoreTypeTest(t *testing.T, shortName string, allowFail bool) {
testCmd.SetArgs([]string{"store-types", "delete", "--name", shortName})
deleteStoreOutput := captureOutput(
func() {
undeleteables := []string{"F5-CA-REST", "F5-WS-REST", "F5-SL-REST"}
for _, v := range undeleteables {
if v == shortName {
t.Skip("Not processing un-deletable store-type: ", shortName)
return
}
}

err := testCmd.Execute()
if !allowFail {
assert.NoError(t, err)
Expand All @@ -266,10 +274,24 @@ func deleteStoreTypeTest(t *testing.T, shortName string, allowFail bool) {
)
}

func checkIsUnDeleteable(shortName string) bool {
undeleteables := []string{"F5-CA-REST", "F5-WS-REST", "F5-SL-REST"}
for _, v := range undeleteables {
if v == shortName {
return true
}
}
return false
}

func createStoreTypeTest(t *testing.T, shortName string) {
t.Run(
fmt.Sprintf("CreateStore %s", shortName), func(t *testing.T) {
testCmd := RootCmd
if checkIsUnDeleteable(shortName) {
t.Skip("Not processing un-deletable store-type: ", shortName)
return
}
deleteStoreTypeTest(t, shortName, true)
testCmd.SetArgs([]string{"store-types", "create", "--name", shortName})
createStoreOutput := captureOutput(
Expand All @@ -278,6 +300,19 @@ func createStoreTypeTest(t *testing.T, shortName string) {
assert.NoError(t, err)
},
)
exceptions := []string{
"F5-CA-REST: Certificate Store Type with either short name 'F5-CA-REST' or name 'F5 CA Profiles REST' already exists.",
"F5-WS-REST: Certificate Store Type with either short name 'F5-WS-REST' or name 'F5 WS Profiles REST' already exists.",
"F5-SL-REST: Certificate Store Type with either short name 'F5-SL-REST' or name 'F5 SSL Profiles REST' already exists.",
}

// check if any of the exceptions are in the output
for _, exception := range exceptions {
if strings.Contains(createStoreOutput, exception) {
t.Skip("Not processing un-deletable store-type: ", exception)
return
}
}

if strings.Contains(createStoreOutput, "already exists") {
assert.Fail(t, fmt.Sprintf("Store type %s already exists", shortName))
Expand Down
1 change: 1 addition & 0 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ require (
github.com/Keyfactor/keyfactor-go-client/v2 v2.2.10-rc.1
github.com/Netflix/go-expect v0.0.0-20220104043353-73e0943537d2
github.com/creack/pty v1.1.21
github.com/golang-collections/collections v0.0.0-20130729185459-604e922904d3
github.com/google/go-cmp v0.6.0
github.com/google/uuid v1.6.0
github.com/hinshun/vt10x v0.0.0-20220301184237-5011da428d02
Expand Down
2 changes: 2 additions & 0 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,8 @@ github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSs
github.com/dnaeon/go-vcr v1.2.0 h1:zHCHvJYTMh1N7xnV7zf1m1GPBF9Ad0Jk/whtQ1663qI=
github.com/dnaeon/go-vcr v1.2.0/go.mod h1:R4UdLID7HZT3taECzJs4YgbbH6PIGXB6W/sc5OLb6RQ=
github.com/godbus/dbus/v5 v5.0.4/go.mod h1:xhWf0FNVPg57R7Z0UbKHbJfkEywrmjJnf7w5xrFpKfA=
github.com/golang-collections/collections v0.0.0-20130729185459-604e922904d3 h1:zN2lZNZRflqFyxVaTIU61KNKQ9C0055u9CAfpmqUvo4=
github.com/golang-collections/collections v0.0.0-20130729185459-604e922904d3/go.mod h1:nPpo7qLxd6XL3hWJG/O60sR8ZKfMCiIoNap5GvD12KU=
github.com/golang-jwt/jwt/v5 v5.0.0 h1:1n1XNM9hk7O9mnQoNBGolZvzebBQ7p93ULHRc28XJUE=
github.com/golang-jwt/jwt/v5 v5.0.0/go.mod h1:pqrtFR0X4osieyHYxtmOUWsAWrfe1Q5UVIyoH402zdk=
github.com/google/go-cmp v0.6.0 h1:ofyhxvXcZhMsU5ulbFiLKl/XBFqE1GSq7atu8tAmTRI=
Expand Down

0 comments on commit eb4fecd

Please sign in to comment.