Skip to content

Commit eb4fecd

Browse files
committed
fix(tests): Skip "undeleteable" store types during tests
Signed-off-by: spbsoluble <[email protected]>
1 parent d451c41 commit eb4fecd

File tree

3 files changed

+38
-0
lines changed

3 files changed

+38
-0
lines changed

cmd/storeTypes_test.go

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -242,6 +242,14 @@ func deleteStoreTypeTest(t *testing.T, shortName string, allowFail bool) {
242242
testCmd.SetArgs([]string{"store-types", "delete", "--name", shortName})
243243
deleteStoreOutput := captureOutput(
244244
func() {
245+
undeleteables := []string{"F5-CA-REST", "F5-WS-REST", "F5-SL-REST"}
246+
for _, v := range undeleteables {
247+
if v == shortName {
248+
t.Skip("Not processing un-deletable store-type: ", shortName)
249+
return
250+
}
251+
}
252+
245253
err := testCmd.Execute()
246254
if !allowFail {
247255
assert.NoError(t, err)
@@ -266,10 +274,24 @@ func deleteStoreTypeTest(t *testing.T, shortName string, allowFail bool) {
266274
)
267275
}
268276

277+
func checkIsUnDeleteable(shortName string) bool {
278+
undeleteables := []string{"F5-CA-REST", "F5-WS-REST", "F5-SL-REST"}
279+
for _, v := range undeleteables {
280+
if v == shortName {
281+
return true
282+
}
283+
}
284+
return false
285+
}
286+
269287
func createStoreTypeTest(t *testing.T, shortName string) {
270288
t.Run(
271289
fmt.Sprintf("CreateStore %s", shortName), func(t *testing.T) {
272290
testCmd := RootCmd
291+
if checkIsUnDeleteable(shortName) {
292+
t.Skip("Not processing un-deletable store-type: ", shortName)
293+
return
294+
}
273295
deleteStoreTypeTest(t, shortName, true)
274296
testCmd.SetArgs([]string{"store-types", "create", "--name", shortName})
275297
createStoreOutput := captureOutput(
@@ -278,6 +300,19 @@ func createStoreTypeTest(t *testing.T, shortName string) {
278300
assert.NoError(t, err)
279301
},
280302
)
303+
exceptions := []string{
304+
"F5-CA-REST: Certificate Store Type with either short name 'F5-CA-REST' or name 'F5 CA Profiles REST' already exists.",
305+
"F5-WS-REST: Certificate Store Type with either short name 'F5-WS-REST' or name 'F5 WS Profiles REST' already exists.",
306+
"F5-SL-REST: Certificate Store Type with either short name 'F5-SL-REST' or name 'F5 SSL Profiles REST' already exists.",
307+
}
308+
309+
// check if any of the exceptions are in the output
310+
for _, exception := range exceptions {
311+
if strings.Contains(createStoreOutput, exception) {
312+
t.Skip("Not processing un-deletable store-type: ", exception)
313+
return
314+
}
315+
}
281316

282317
if strings.Contains(createStoreOutput, "already exists") {
283318
assert.Fail(t, fmt.Sprintf("Store type %s already exists", shortName))

go.mod

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ require (
1111
github.com/Keyfactor/keyfactor-go-client/v2 v2.2.10-rc.1
1212
github.com/Netflix/go-expect v0.0.0-20220104043353-73e0943537d2
1313
github.com/creack/pty v1.1.21
14+
github.com/golang-collections/collections v0.0.0-20130729185459-604e922904d3
1415
github.com/google/go-cmp v0.6.0
1516
github.com/google/uuid v1.6.0
1617
github.com/hinshun/vt10x v0.0.0-20220301184237-5011da428d02

go.sum

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,8 @@ github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSs
3030
github.com/dnaeon/go-vcr v1.2.0 h1:zHCHvJYTMh1N7xnV7zf1m1GPBF9Ad0Jk/whtQ1663qI=
3131
github.com/dnaeon/go-vcr v1.2.0/go.mod h1:R4UdLID7HZT3taECzJs4YgbbH6PIGXB6W/sc5OLb6RQ=
3232
github.com/godbus/dbus/v5 v5.0.4/go.mod h1:xhWf0FNVPg57R7Z0UbKHbJfkEywrmjJnf7w5xrFpKfA=
33+
github.com/golang-collections/collections v0.0.0-20130729185459-604e922904d3 h1:zN2lZNZRflqFyxVaTIU61KNKQ9C0055u9CAfpmqUvo4=
34+
github.com/golang-collections/collections v0.0.0-20130729185459-604e922904d3/go.mod h1:nPpo7qLxd6XL3hWJG/O60sR8ZKfMCiIoNap5GvD12KU=
3335
github.com/golang-jwt/jwt/v5 v5.0.0 h1:1n1XNM9hk7O9mnQoNBGolZvzebBQ7p93ULHRc28XJUE=
3436
github.com/golang-jwt/jwt/v5 v5.0.0/go.mod h1:pqrtFR0X4osieyHYxtmOUWsAWrfe1Q5UVIyoH402zdk=
3537
github.com/google/go-cmp v0.6.0 h1:ofyhxvXcZhMsU5ulbFiLKl/XBFqE1GSq7atu8tAmTRI=

0 commit comments

Comments
 (0)