Skip to content

Commit 8210ef4

Browse files
fix lint
1 parent 020d56d commit 8210ef4

21 files changed

+233
-209
lines changed

.golangci.yml

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,6 @@ linters:
99
enable:
1010
- durationcheck
1111
- errcheck
12-
- exportloopref
1312
- forcetypeassert
1413
- godot
1514
- gofmt
@@ -18,9 +17,9 @@ linters:
1817
- makezero
1918
- misspell
2019
- nilerr
20+
- usetesting
2121
- predeclared
2222
- staticcheck
23-
- tenv
2423
- unconvert
2524
- unparam
2625
- unused

docs/resources/system.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,11 +26,11 @@ resource "ctrlplane_system" "example" {
2626
### Required
2727

2828
- `name` (String) The name of the system
29-
- `slug` (String) The slug of the system (must be unique to the workspace)
3029

3130
### Optional
3231

3332
- `description` (String) The description of the system
33+
- `slug` (String) The slug of the system (must be unique to the workspace). If not provided, it will be generated from the name.
3434

3535
### Read-Only
3636

examples/resources/ctrlplane_environment/main.tf

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -6,11 +6,7 @@ terraform {
66
}
77
}
88

9-
provider "ctrlplane" {
10-
base_url = "http://localhost:3000"
11-
token = "ec2dcd404a4a53c4.41c876a1055cb2e636721fdd394be83dbdc901ab57aeccb14b0ca57eb687e26a"
12-
workspace = "zacharyblasczyk"
13-
}
9+
provider "ctrlplane" {}
1410

1511
resource "ctrlplane_system" "example" {
1612
name = "example-system"

examples/resources/ctrlplane_resource_filter/main.tf

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -6,11 +6,7 @@ terraform {
66
}
77
}
88

9-
provider "ctrlplane" {
10-
base_url = "http://localhost:3000"
11-
token = "ec2dcd404a4a53c4.41c876a1055cb2e636721fdd394be83dbdc901ab57aeccb14b0ca57eb687e26a"
12-
workspace = "zacharyblasczyk"
13-
}
9+
provider "ctrlplane" {}
1410

1511
resource "ctrlplane_system" "example" {
1612
name = "resource-filter-example-system"

internal/integration/environment_test.go

Lines changed: 42 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -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+
}

internal/integration/integration_suite_test.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ type TestMode string
1919

2020
const (
2121
TestModePersist TestMode = "persistent"
22-
// TestModeCleanup TestMode = "cleanup"
22+
// TestModeCleanup TestMode = "cleanup".
2323
TestModeAutoCleanup TestMode = "autocleanup"
2424
)
2525

internal/integration/test_helpers_test.go

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -50,12 +50,11 @@ func getWorkspaceID(ctx context.Context, workspaceStr string, apiClient *client.
5050
return workspaceResp.JSON200.Id, nil
5151
}
5252

53-
func createTestSystem(ctx context.Context, apiClient *client.ClientWithResponses, namePrefix string) (uuid.UUID, string, error) {
54-
53+
func createTestSystem(ctx context.Context, apiClient *client.ClientWithResponses, namePrefix string) (uuid.UUID, error) {
5554
workspaceStr := os.Getenv("CTRLPLANE_WORKSPACE")
5655
workspaceID, err := getWorkspaceID(ctx, workspaceStr, apiClient)
5756
if err != nil {
58-
return uuid.Nil, "", fmt.Errorf("failed to get workspace ID: %w", err)
57+
return uuid.Nil, fmt.Errorf("failed to get workspace ID: %w", err)
5958
}
6059

6160
shortUUID := uuid.New().String()[:6]
@@ -78,18 +77,18 @@ func createTestSystem(ctx context.Context, apiClient *client.ClientWithResponses
7877
})
7978

8079
if err != nil {
81-
return uuid.Nil, "", fmt.Errorf("failed to create system: %w", err)
80+
return uuid.Nil, fmt.Errorf("failed to create system: %w", err)
8281
}
8382

8483
if systemResp.JSON201 == nil {
8584

8685
Logger.Error("system creation failed",
8786
zap.Int("status_code", systemResp.StatusCode()),
8887
zap.String("response_body", string(systemResp.Body)))
89-
return uuid.Nil, "", fmt.Errorf("system creation failed with status: %d", systemResp.StatusCode())
88+
return uuid.Nil, fmt.Errorf("system creation failed with status: %d", systemResp.StatusCode())
9089
}
9190

92-
return systemResp.JSON201.Id, systemName, nil
91+
return systemResp.JSON201.Id, nil
9392
}
9493

9594
func deleteTestSystem(ctx context.Context, apiClient *client.ClientWithResponses, systemID uuid.UUID) error {

0 commit comments

Comments
 (0)