@@ -43,16 +43,15 @@ var _ = Describe("Environment API", func() {
4343
4444 BeforeEach (func () {
4545 var err error
46- systemID , _ , err = createTestSystem (ctx , apiClient , "env-no-filter" )
46+ systemID , err = createTestSystem (ctx , apiClient , "env-no-filter" )
4747 Expect (err ).NotTo (HaveOccurred (), "Failed to create test system" )
4848
4949 shortUUID := uuid .New ().String ()[:6 ]
5050 envName = fmt .Sprintf ("env-test-%s" , shortUUID )
5151 })
5252
5353 AfterEach (func () {
54- err := deleteTestSystem (ctx , apiClient , systemID )
55- Expect (err ).NotTo (HaveOccurred (), "Failed to delete test system" )
54+ safeDeleteTestSystem (ctx , apiClient , systemID )
5655 })
5756
5857 It ("should create an environment without a resource filter" , func () {
@@ -171,9 +170,10 @@ var _ = Describe("Environment API", func() {
171170 })
172171
173172 It ("should create an environment with comparison resource filter" , func () {
174- systemID , _ , err := createTestSystem (ctx , apiClient , "env-comparison" )
173+ systemID , err := createTestSystem (ctx , apiClient , "env-comparison" )
175174 Expect (err ).NotTo (HaveOccurred ())
176- defer deleteTestSystem (ctx , apiClient , systemID )
175+
176+ defer func () { safeDeleteTestSystem (ctx , apiClient , systemID ) }()
177177
178178 releaseChannels := []string {}
179179 envName := fmt .Sprintf ("env-comparison-%s" , uuid .New ().String ()[:6 ])
@@ -245,9 +245,9 @@ var _ = Describe("Environment API", func() {
245245 })
246246
247247 It ("should create an environment with metadata resource filter" , func () {
248- systemID , _ , err := createTestSystem (ctx , apiClient , "env-metadata" )
248+ systemID , err := createTestSystem (ctx , apiClient , "env-metadata" )
249249 Expect (err ).NotTo (HaveOccurred ())
250- defer deleteTestSystem (ctx , apiClient , systemID )
250+ defer safeDeleteTestSystem (ctx , apiClient , systemID )
251251
252252 releaseChannels := []string {}
253253 envName := fmt .Sprintf ("env-metadata-%s" , uuid .New ().String ()[:6 ])
@@ -321,9 +321,10 @@ var _ = Describe("Environment API", func() {
321321 })
322322
323323 It ("should create an environment with a simple filter" , func () {
324- systemID , _ , err := createTestSystem (ctx , apiClient , "env-simple-filter" )
324+ systemID , err := createTestSystem (ctx , apiClient , "env-simple-filter" )
325325 Expect (err ).NotTo (HaveOccurred ())
326- defer deleteTestSystem (ctx , apiClient , systemID )
326+
327+ defer func () { safeDeleteTestSystem (ctx , apiClient , systemID ) }()
327328
328329 releaseChannels := []string {}
329330 envName := fmt .Sprintf ("env-simple-filter-%s" , uuid .New ().String ()[:6 ])
@@ -394,9 +395,9 @@ var _ = Describe("Environment API", func() {
394395 })
395396
396397 It ("should create an environment with a complex filter" , func () {
397- systemID , _ , err := createTestSystem (ctx , apiClient , "env-complex-filter" )
398+ systemID , err := createTestSystem (ctx , apiClient , "env-complex-filter" )
398399 Expect (err ).NotTo (HaveOccurred ())
399- defer deleteTestSystem (ctx , apiClient , systemID )
400+ defer safeDeleteTestSystem (ctx , apiClient , systemID )
400401
401402 releaseChannels := []string {}
402403 envName := fmt .Sprintf ("env-complex-filter-%s" , uuid .New ().String ()[:6 ])
@@ -462,19 +463,21 @@ var _ = Describe("Environment API", func() {
462463 Expect (ok ).To (BeTrue (), "conditions should be an array" )
463464 Expect (conditions ).To (HaveLen (2 ), "should have 2 conditions" )
464465
465- condition1 := conditions [0 ].(map [string ]interface {})
466- Expect (condition1 ["type" ]).To (Equal ("metadata" ))
467- Expect (condition1 ["key" ]).To (Equal ("environment" ))
468- Expect (condition1 ["operator" ]).To (Equal ("equals" ))
469- Expect (condition1 ["value" ]).To (Equal ("staging" ))
466+ condition1Map , ok := conditions [0 ].(map [string ]interface {})
467+ Expect (ok ).To (BeTrue (), "condition1 should be a map" )
468+ Expect (condition1Map ["type" ]).To (Equal ("metadata" ))
469+ Expect (condition1Map ["key" ]).To (Equal ("environment" ))
470+ Expect (condition1Map ["operator" ]).To (Equal ("equals" ))
471+ Expect (condition1Map ["value" ]).To (Equal ("staging" ))
470472
471- condition2 := conditions [1 ].(map [string ]interface {})
472- Expect (condition2 ["type" ]).To (Equal ("kind" ))
473- Expect (condition2 ["operator" ]).To (Equal ("equals" ))
474- Expect (condition2 ["value" ]).To (Equal ("Deployment" ))
473+ condition2Map , ok := conditions [1 ].(map [string ]interface {})
474+ Expect (ok ).To (BeTrue (), "condition2 should be a map" )
475+ Expect (condition2Map ["type" ]).To (Equal ("kind" ))
476+ Expect (condition2Map ["operator" ]).To (Equal ("equals" ))
477+ Expect (condition2Map ["value" ]).To (Equal ("Deployment" ))
475478
476479 systemResp , err := apiClient .GetSystemWithResponse (ctx , systemID )
477- Expect (err ).NotTo (HaveOccurred ())
480+ Expect (err ).NotTo (HaveOccurred (), "Failed to get system" )
478481 Expect (systemResp .JSON200 ).NotTo (BeNil ())
479482 Expect (systemResp .JSON200 .Environments ).NotTo (BeNil ())
480483
@@ -493,9 +496,9 @@ var _ = Describe("Environment API", func() {
493496 })
494497
495498 It ("should create an environment with date condition resource filter" , func () {
496- systemID , _ , err := createTestSystem (ctx , apiClient , "env-date-filter" )
499+ systemID , err := createTestSystem (ctx , apiClient , "env-date-filter" )
497500 Expect (err ).NotTo (HaveOccurred ())
498- defer deleteTestSystem (ctx , apiClient , systemID )
501+ defer safeDeleteTestSystem (ctx , apiClient , systemID )
499502
500503 releaseChannels := []string {}
501504 envName := fmt .Sprintf ("env-date-filter-%s" , uuid .New ().String ()[:6 ])
@@ -610,9 +613,9 @@ var _ = Describe("Environment API", func() {
610613 })
611614
612615 It ("should support multiple environments in the same system" , func () {
613- systemID , _ , err := createTestSystem (ctx , apiClient , "multi-env" )
616+ systemID , err := createTestSystem (ctx , apiClient , "multi-env" )
614617 Expect (err ).NotTo (HaveOccurred ())
615- defer deleteTestSystem (ctx , apiClient , systemID )
618+ defer safeDeleteTestSystem (ctx , apiClient , systemID )
616619
617620 environments := []struct {
618621 name string
@@ -690,9 +693,9 @@ var _ = Describe("Environment API", func() {
690693 })
691694
692695 It ("should create an environment with nested comparison conditions" , func () {
693- systemID , _ , err := createTestSystem (ctx , apiClient , "env-nested-comparison" )
696+ systemID , err := createTestSystem (ctx , apiClient , "env-nested-comparison" )
694697 Expect (err ).NotTo (HaveOccurred ())
695- defer deleteTestSystem (ctx , apiClient , systemID )
698+ defer safeDeleteTestSystem (ctx , apiClient , systemID )
696699
697700 releaseChannels := []string {}
698701 envName := fmt .Sprintf ("env-nested-comp-%s" , uuid .New ().String ()[:6 ])
@@ -793,9 +796,9 @@ var _ = Describe("Environment API", func() {
793796 })
794797
795798 It ("should create an environment with mixed condition types" , func () {
796- systemID , _ , err := createTestSystem (ctx , apiClient , "env-mixed-conditions" )
799+ systemID , err := createTestSystem (ctx , apiClient , "env-mixed-conditions" )
797800 Expect (err ).NotTo (HaveOccurred ())
798- defer deleteTestSystem (ctx , apiClient , systemID )
801+ defer safeDeleteTestSystem (ctx , apiClient , systemID )
799802
800803 releaseChannels := []string {}
801804 envName := fmt .Sprintf ("env-mixed-conditions-%s" , uuid .New ().String ()[:6 ])
@@ -899,9 +902,9 @@ var _ = Describe("Environment API", func() {
899902 })
900903
901904 It ("should create an environment with deeply nested conditions" , func () {
902- systemID , _ , err := createTestSystem (ctx , apiClient , "env-deep-nesting" )
905+ systemID , err := createTestSystem (ctx , apiClient , "env-deep-nesting" )
903906 Expect (err ).NotTo (HaveOccurred ())
904- defer deleteTestSystem (ctx , apiClient , systemID )
907+ defer safeDeleteTestSystem (ctx , apiClient , systemID )
905908
906909 releaseChannels := []string {}
907910 envName := fmt .Sprintf ("env-deep-nesting-%s" , uuid .New ().String ()[:6 ])
@@ -1042,3 +1045,11 @@ var _ = Describe("Environment API", func() {
10421045 })
10431046 })
10441047})
1048+
1049+ // Helper function to safely delete a test system with error handling.
1050+ func safeDeleteTestSystem (ctx context.Context , apiClient * client.ClientWithResponses , systemID uuid.UUID ) {
1051+ err := deleteTestSystem (ctx , apiClient , systemID )
1052+ if err != nil {
1053+ Logger .Error ("Failed to delete test system" , zap .Error (err ), zap .String ("system_id" , systemID .String ()))
1054+ }
1055+ }
0 commit comments