Skip to content

Commit f1e9256

Browse files
authored
fix: preserver api response while ordering node groups and zones
* fix: preserver api response while ordering node groups and zones * test: add test cases for models * fix: lint issues * chore: sync and update latest graphql schema
1 parent 8762642 commit f1e9256

File tree

16 files changed

+6905
-1
lines changed

16 files changed

+6905
-1
lines changed

.github/workflows/test.yml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,8 @@ jobs:
2323
cache: true
2424
- run: go mod download
2525
- run: go build -v .
26+
- name: Run tests
27+
run: make test
2628
- name: Run linters
2729
uses: golangci/golangci-lint-action@4afd733a84b1f43292c63897423277bb7f4313a9 # v8.0.0
2830
with:

Makefile

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -107,6 +107,10 @@ fmt:
107107
lint:
108108
golangci-lint run
109109

110+
.PHONY: test
111+
test:
112+
go test -v -cover ./...
113+
110114
.PHONY: help
111115
help:
112116
@echo "Available commands:"
@@ -118,7 +122,8 @@ help:
118122
@echo "gen - Run SDK generation, version sync, and docs generation. This is a combined command that runs sdk, sync, and docs commands."
119123
@echo "local - Build the provider and set up the local directory for testing. This is useful for local development and testing."
120124
@echo "sdk - Re-sync the SDK client and models. This pulls the latest GraphQL schema and regenerates the client code."
121-
@echo "testacc - Run acceptance tests. These are integration tests that use the Terraform binary to test real infrastructure."
122125
@echo "sync - Fetch and update the current version in the 'example' directory. This syncs the version used in examples with the latest git tag."
126+
@echo "test - Run Go unit tests with coverage. This runs all unit tests in the project and provides coverage information."
127+
@echo "testacc - Run acceptance tests. These are integration tests that use the Terraform binary to test real infrastructure."
123128
@echo "tool - Run Go tools. This is a placeholder for any Go-based tools you might want to run as part of the build."
124129

go.mod

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ require (
1515
github.com/MakeNowJust/heredoc/v2 v2.0.1
1616
github.com/hashicorp/terraform-plugin-framework-validators v0.18.0
1717
github.com/hashicorp/terraform-plugin-testing v1.13.3
18+
github.com/stretchr/testify v1.10.0
1819
)
1920

2021
require (
@@ -33,6 +34,7 @@ require (
3334
github.com/bmatcuk/doublestar/v4 v4.8.1 // indirect
3435
github.com/cloudflare/circl v1.6.1 // indirect
3536
github.com/cpuguy83/go-md2man/v2 v2.0.6 // indirect
37+
github.com/davecgh/go-spew v1.1.1 // indirect
3638
github.com/fatih/color v1.16.0 // indirect
3739
github.com/goccy/go-yaml v1.17.1 // indirect
3840
github.com/golang/protobuf v1.5.4 // indirect
@@ -69,6 +71,7 @@ require (
6971
github.com/mitchellh/mapstructure v1.5.0 // indirect
7072
github.com/mitchellh/reflectwalk v1.0.2 // indirect
7173
github.com/oklog/run v1.0.0 // indirect
74+
github.com/pmezard/go-difflib v1.0.0 // indirect
7275
github.com/posener/complete v1.2.3 // indirect
7376
github.com/russross/blackfriday/v2 v2.1.0 // indirect
7477
github.com/shopspring/decimal v1.3.1 // indirect

internal/provider/env/aws/model.go

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -320,15 +320,25 @@ func maintenanceWindowsToModel(input []*sdk.AWSEnvSpecFragment_MaintenanceWindow
320320

321321
func reorderNodeGroups(model []common.NodeGroupsModel, nodeGroups []*sdk.AWSEnvSpecFragment_NodeGroups) []*sdk.AWSEnvSpecFragment_NodeGroups {
322322
orderedNodeGroups := make([]*sdk.AWSEnvSpecFragment_NodeGroups, 0, len(nodeGroups))
323+
usedNodeGroups := make(map[string]bool)
323324

325+
// First, add node groups that exist in the model in the correct order
324326
for _, ng := range model {
325327
for _, apiGroup := range nodeGroups {
326328
if ng.NodeType.ValueString() == apiGroup.NodeType {
327329
orderedNodeGroups = append(orderedNodeGroups, apiGroup)
330+
usedNodeGroups[apiGroup.NodeType] = true
328331
break
329332
}
330333
}
331334
}
332335

336+
// Then, add any remaining node groups from the API that weren't in the model
337+
for _, apiGroup := range nodeGroups {
338+
if !usedNodeGroups[apiGroup.NodeType] {
339+
orderedNodeGroups = append(orderedNodeGroups, apiGroup)
340+
}
341+
}
342+
333343
return orderedNodeGroups
334344
}

0 commit comments

Comments
 (0)