diff --git a/.github/workflows/integration-enterprise.yaml b/.github/workflows/integration-enterprise.yaml index 8c6c48907..fbce80e50 100644 --- a/.github/workflows/integration-enterprise.yaml +++ b/.github/workflows/integration-enterprise.yaml @@ -18,22 +18,11 @@ jobs: strategy: matrix: kong_image: - - 'kong/kong-gateway:1.5.0.11' - - 'kong/kong-gateway:2.1.4.6' - - 'kong/kong-gateway:2.2.1.3' - - 'kong/kong-gateway:2.3.3.4' - - 'kong/kong-gateway:2.4.1.3' - - 'kong/kong-gateway:2.5.1.2' - - 'kong/kong-gateway:2.6.0.2' - - 'kong/kong-gateway:2.7' - 'kong/kong-gateway:2.8' - - 'kong/kong-gateway:3.0' - - 'kong/kong-gateway:3.1' - - 'kong/kong-gateway:3.2' - - 'kong/kong-gateway:3.3' - 'kong/kong-gateway:3.4' - 'kong/kong-gateway:3.5' - 'kong/kong-gateway:3.6' + - 'kong/kong-gateway:3.7' - 'kong/kong-gateway-dev:latest' env: KONG_ANONYMOUS_REPORTS: "off" @@ -55,7 +44,6 @@ jobs: - uses: Kong/kong-license@master id: license with: - password: ${{ secrets.PULP_PASSWORD }} op-token: ${{ secrets.OP_SERVICE_ACCOUNT_TOKEN }} - name: Setup Kong env: diff --git a/.github/workflows/integration.yaml b/.github/workflows/integration.yaml index ceabcc380..7786e2b09 100644 --- a/.github/workflows/integration.yaml +++ b/.github/workflows/integration.yaml @@ -18,24 +18,11 @@ jobs: strategy: matrix: kong_image: - - 'kong:1.4.3' - - 'kong:1.5.1' - - 'kong:2.0.5' - - 'kong:2.1.4' - - 'kong:2.2.2' - - 'kong:2.3.3' - - 'kong:2.4.1' - - 'kong:2.5.1' - - 'kong:2.6.0' - - 'kong:2.7' - 'kong:2.8' - - 'kong:3.0' - - 'kong:3.1' - - 'kong:3.2' - - 'kong:3.3' - 'kong:3.4' - 'kong:3.5' - 'kong:3.6' + - 'kong:3.7' - 'kong/kong:master' env: KONG_ANONYMOUS_REPORTS: "off" diff --git a/.github/workflows/release.yaml b/.github/workflows/release.yaml index fea95a8e2..404cac8bf 100644 --- a/.github/workflows/release.yaml +++ b/.github/workflows/release.yaml @@ -19,7 +19,7 @@ jobs: with: go-version-file: go.mod - name: Run GoReleaser - uses: goreleaser/goreleaser-action@v5 + uses: goreleaser/goreleaser-action@v6 with: # either 'goreleaser' (default) or 'goreleaser-pro' distribution: goreleaser diff --git a/.github/workflows/test.yaml b/.github/workflows/test.yaml index 06e402047..c1dd1fd0a 100644 --- a/.github/workflows/test.yaml +++ b/.github/workflows/test.yaml @@ -17,14 +17,10 @@ jobs: timeout-minutes: ${{ fromJSON(vars.GHA_DEFAULT_TIMEOUT) }} runs-on: ubuntu-latest steps: - - name: Checkout repository - uses: actions/checkout@v4 - - name: Setup go - uses: actions/setup-go@v5 + - uses: actions/checkout@v4 + - uses: actions/setup-go@v5 with: go-version-file: go.mod - - name: Setup golangci-lint - uses: golangci/golangci-lint-action@v6.1.0 - name: Run tests with Coverage run: make coverage - name: Upload Code Coverage @@ -33,5 +29,24 @@ jobs: name: codecov-deck token: ${{ secrets.CODECOV_TOKEN }} fail_ci_if_error: true + + lint: + timeout-minutes: ${{ fromJSON(vars.GHA_DEFAULT_TIMEOUT) }} + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v4 + - uses: actions/setup-go@v5 + with: + go-version-file: go.mod + - uses: golangci/golangci-lint-action@v6.1.0 + + build: + timeout-minutes: ${{ fromJSON(vars.GHA_DEFAULT_TIMEOUT) }} + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v4 + - uses: actions/setup-go@v5 + with: + go-version-file: go.mod - name: Build run: make build diff --git a/.github/workflows/validate-kong-release.yaml b/.github/workflows/validate-kong-release.yaml index eb4478127..418ed15b7 100644 --- a/.github/workflows/validate-kong-release.yaml +++ b/.github/workflows/validate-kong-release.yaml @@ -36,7 +36,6 @@ jobs: - uses: Kong/kong-license@master id: license with: - password: ${{ secrets.PULP_PASSWORD }} op-token: ${{ secrets.OP_SERVICE_ACCOUNT_TOKEN }} - name: Setup Kong env: diff --git a/.golangci.yml b/.golangci.yml index 2eafaa9ee..5e40286e3 100644 --- a/.golangci.yml +++ b/.golangci.yml @@ -8,7 +8,7 @@ linters: - dogsled - durationcheck - exhaustive - - exportloopref + - copyloopvar - gci - goconst - gofmt @@ -19,7 +19,9 @@ linters: - govet - importas - lll - - megacheck + - gosimple + - staticcheck + - unused - misspell - nakedret - nilerr diff --git a/CHANGELOG.md b/CHANGELOG.md index cdc625a89..075ea219f 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,5 +1,7 @@ # Table of Contents +- [v1.39.6](#v1396) +- [v1.39.5](#v1395) - [v1.39.4](#v1394) - [v1.39.3](#v1393) - [v1.39.2](#v1392) @@ -90,6 +92,21 @@ - [v0.2.0](#v020) - [v0.1.0](#v010) +## [v1.39.6] +> Release date: 2024/08/22 + +### Fixes + +- Fixed the issue where plugins scoped to consumer-groups were shown as global by deck. [#1380](https://github.com/Kong/deck/pull/1380) +[go-database-reconciler #134](https://github.com/Kong/go-database-reconciler/pull/134) + +## [v1.39.5] +> Release date: 2024/08/22 + +### Fixes + +- Fixed `deck file openapi2kong` command where parameter schema wasn't getting generated properly. [#1355](https://github.com/Kong/deck/pull/1355) [go-apiops #186](https://github.com/Kong/go-apiops/pull/186) + ## [v1.39.4] > Release date: 2024/08/01 @@ -1757,6 +1774,8 @@ No breaking changes have been introduced in this release. Debut release of decK +[v1.39.6]: https://github.com/Kong/deck/compare/v1.39.5...v1.39.6 +[v1.39.5]: https://github.com/Kong/deck/compare/v1.39.4...v1.39.5 [v1.39.4]: https://github.com/Kong/deck/compare/v1.39.3...v1.39.4 [v1.39.3]: https://github.com/Kong/deck/compare/v1.39.2...v1.39.3 [v1.39.2]: https://github.com/kong/deck/compare/v1.39.1...v1.39.2 diff --git a/Dockerfile b/Dockerfile index 81e32d9bb..ee9c51cb8 100644 --- a/Dockerfile +++ b/Dockerfile @@ -1,4 +1,4 @@ -FROM golang:1.22.4 AS build +FROM golang:1.23.0 AS build WORKDIR /deck COPY go.mod ./ COPY go.sum ./ diff --git a/README.md b/README.md index d59d37672..923acfb9b 100644 --- a/README.md +++ b/README.md @@ -73,7 +73,7 @@ the GitHub [release page](https://github.com/kong/deck/releases) or install by downloading the binary: ```shell -$ curl -sL https://github.com/kong/deck/releases/download/v1.39.4/deck_1.39.4_linux_amd64.tar.gz -o deck.tar.gz +$ curl -sL https://github.com/kong/deck/releases/download/v1.39.6/deck_1.39.6_linux_amd64.tar.gz -o deck.tar.gz $ tar -xf deck.tar.gz -C /tmp $ sudo cp /tmp/deck /usr/local/bin/ ``` @@ -84,7 +84,7 @@ If you are on Windows, you can download the binary from the GitHub [release page](https://github.com/kong/deck/releases) or via PowerShell: ```shell -$ curl -sL https://github.com/kong/deck/releases/download/v1.39.4/deck_1.39.4_windows_amd64.tar.gz -o deck.tar.gz +$ curl -sL https://github.com/kong/deck/releases/download/v1.39.6/deck_1.39.6_windows_amd64.tar.gz -o deck.tar.gz $ tar -xzvf deck.tar.gz ``` diff --git a/cmd/common.go b/cmd/common.go index cfc77339f..f58c6f45c 100644 --- a/cmd/common.go +++ b/cmd/common.go @@ -593,11 +593,11 @@ func checkForRBACResources(content reconcilerUtils.KongRawState, common := "At a time, state file(s) must entirely consist of either proxy " + "configuration or RBAC configuration." if rbacResourcesOnly { - return fmt.Errorf("When --rbac-resources-only is used, state file(s) " + - "cannot contain any resources other than RBAC resources. " + common) + return fmt.Errorf("when --rbac-resources-only is used, state file(s) "+ + "cannot contain any resources other than RBAC resources. %s", common) } - return fmt.Errorf("State file(s) contains RBAC resources. " + - "Please use --rbac-resources-only flag to manage these resources. " + common) + return fmt.Errorf("state file(s) contains RBAC resources. "+ + "Please use --rbac-resources-only flag to manage these resources. %s", common) } return nil } diff --git a/cmd/common_konnect.go b/cmd/common_konnect.go index 16dcde56e..83ab7d283 100644 --- a/cmd/common_konnect.go +++ b/cmd/common_konnect.go @@ -5,6 +5,7 @@ import ( "fmt" "os" "strings" + "time" "github.com/kong/go-database-reconciler/pkg/diff" "github.com/kong/go-database-reconciler/pkg/dump" @@ -16,12 +17,36 @@ import ( "golang.org/x/sync/errgroup" ) -const defaultControlPlaneName = "default" +const ( + defaultControlPlaneName = "default" + maxRetriesForAuth = 5 + apiRateLimitExceededErrorString = "API rate limit exceeded" +) func authenticate( ctx context.Context, client *konnect.Client, konnectConfig utils.KonnectConfig, ) (konnect.AuthResponse, error) { - return client.Auth.LoginV2(ctx, konnectConfig.Email, konnectConfig.Password, konnectConfig.Token) + attempts := 0 + backoff := 200 * time.Millisecond + + for { + authResponse, err := client.Auth.LoginV2(ctx, konnectConfig.Email, konnectConfig.Password, konnectConfig.Token) + if err == nil { + return authResponse, nil + } + + if !strings.Contains(err.Error(), apiRateLimitExceededErrorString) { + return authResponse, err + } + + attempts++ + if attempts > maxRetriesForAuth { + return authResponse, fmt.Errorf("maximum retries (%d) exceeded for authentication", maxRetriesForAuth) + } + + time.Sleep(backoff) + backoff *= 2 + } } // GetKongClientForKonnectMode abstracts the different cloud environments users diff --git a/convert/convert_test.go b/convert/convert_test.go index 93a95a693..e6e955cb2 100644 --- a/convert/convert_test.go +++ b/convert/convert_test.go @@ -367,9 +367,8 @@ func Test_Convert(t *testing.T) { func wipeServiceID(content *file.Content) *file.Content { result := content.DeepCopy() - result.ServicePackages = nil + result.ServicePackages = make([]file.FServicePackage, 0, len(content.ServicePackages)) for _, sp := range content.ServicePackages { - sp := sp sp = zeroOutID(sp) result.ServicePackages = append(result.ServicePackages, sp) } diff --git a/kong2kic/route.go b/kong2kic/route.go index be21861ed..f9e797dca 100644 --- a/kong2kic/route.go +++ b/kong2kic/route.go @@ -154,7 +154,7 @@ func populateKICIngressesWithAnnotations(content *file.Content, kicContent *KICC Service: &k8snetv1.IngressServiceBackend{ Name: *service.Name, Port: k8snetv1.ServiceBackendPort{ - Number: int32(*service.Port), + Number: int32(*service.Port), //nolint:gosec }, }, }, @@ -203,7 +203,7 @@ func populateKICIngressesWithAnnotations(content *file.Content, kicContent *KICC Service: &k8snetv1.IngressServiceBackend{ Name: *service.Name, Port: k8snetv1.ServiceBackendPort{ - Number: int32(*service.Port), + Number: int32(*service.Port), //nolint:gosec }, }, }, @@ -394,7 +394,7 @@ func populateKICIngressesWithGatewayAPI(content *file.Content, kicContent *KICCo }, } if service.Port != nil { - portNumber := k8sgwapiv1.PortNumber(*service.Port) + portNumber := k8sgwapiv1.PortNumber(*service.Port) //nolint:gosec backendRef.Port = &portNumber } diff --git a/kong2kic/service.go b/kong2kic/service.go index a5303ae6a..7ce9a06e0 100644 --- a/kong2kic/service.go +++ b/kong2kic/service.go @@ -44,9 +44,11 @@ func populateKICServicesWithAnnotations(content *file.Content, kicContent *KICCo if service.Port != nil { sPort := k8scorev1.ServicePort{ - Protocol: protocol, - Port: int32(*service.Port), - TargetPort: intstr.IntOrString{IntVal: int32(*service.Port)}, + Protocol: protocol, + Port: int32(*service.Port), //nolint:gosec + TargetPort: intstr.IntOrString{ + IntVal: int32(*service.Port), //nolint:gosec + }, } k8sService.Spec.Ports = append(k8sService.Spec.Ports, sPort) } diff --git a/kong2kic/writer.go b/kong2kic/writer.go index da74ada68..69ffb724e 100644 --- a/kong2kic/writer.go +++ b/kong2kic/writer.go @@ -36,7 +36,7 @@ func WriteContentToFile(content *file.Content, filename string, format file.Form return err } default: - return fmt.Errorf("unknown file format: " + string(format)) + return fmt.Errorf("unknown file format: %s", format) } if filename == "-" { diff --git a/tests/integration/lint_test.go b/tests/integration/lint_test.go index 4f2b5c4ca..914813a6b 100644 --- a/tests/integration/lint_test.go +++ b/tests/integration/lint_test.go @@ -157,7 +157,7 @@ func Test_LintStructured(t *testing.T) { cmpopts.EquateEmpty(), } if diff := cmp.Diff(outputErrors, expectedErrors, cmpOpts...); diff != "" { - t.Errorf(diff) + t.Errorf("got unexpected diff\n:%s", diff) } }) } diff --git a/tests/integration/reset_test.go b/tests/integration/reset_test.go index 47aa5b28c..521c16721 100644 --- a/tests/integration/reset_test.go +++ b/tests/integration/reset_test.go @@ -39,9 +39,7 @@ u8S6yNlu2Q== func Test_Reset_SkipCACert_2x(t *testing.T) { // setup stage client, err := getTestClient() - if err != nil { - t.Errorf(err.Error()) - } + require.NoError(t, err) tests := []struct { name string @@ -75,9 +73,7 @@ func Test_Reset_SkipCACert_2x(t *testing.T) { func Test_Reset_SkipCACert_3x(t *testing.T) { // setup stage client, err := getTestClient() - if err != nil { - t.Errorf(err.Error()) - } + require.NoError(t, err) tests := []struct { name string @@ -113,9 +109,7 @@ func Test_Reset_ConsumerGroupConsumersWithCustomID(t *testing.T) { setup(t) client, err := getTestClient() - if err != nil { - t.Fatalf(err.Error()) - } + require.NoError(t, err) require.NoError(t, sync("testdata/sync/028-consumer-group-consumers-custom_id/kong.yaml")) reset(t) diff --git a/tests/integration/sync_test.go b/tests/integration/sync_test.go index 2a010dd42..0d0b74e38 100644 --- a/tests/integration/sync_test.go +++ b/tests/integration/sync_test.go @@ -1264,9 +1264,7 @@ var ( func Test_Sync_ServicesRoutes_Till_1_4_3(t *testing.T) { // setup stage client, err := getTestClient() - if err != nil { - t.Fatalf(err.Error()) - } + require.NoError(t, err) // ignore entities fields based on Kong version ignoreFields := []cmp.Option{ @@ -1311,9 +1309,7 @@ func Test_Sync_ServicesRoutes_Till_1_4_3(t *testing.T) { func Test_Sync_ServicesRoutes_Till_1_5_1(t *testing.T) { // setup stage client, err := getTestClient() - if err != nil { - t.Fatalf(err.Error()) - } + require.NoError(t, err) tests := []struct { name string @@ -1353,9 +1349,7 @@ func Test_Sync_ServicesRoutes_Till_1_5_1(t *testing.T) { func Test_Sync_ServicesRoutes_From_2_0_5_To_2_1_4(t *testing.T) { // setup stage client, err := getTestClient() - if err != nil { - t.Fatalf(err.Error()) - } + require.NoError(t, err) tests := []struct { name string @@ -1402,9 +1396,7 @@ func Test_Sync_ServicesRoutes_From_2_0_5_To_2_1_4(t *testing.T) { func Test_Sync_ServicesRoutes_From_2_2_1_to_2_6_0(t *testing.T) { // setup stage client, err := getTestClient() - if err != nil { - t.Fatalf(err.Error()) - } + require.NoError(t, err) tests := []struct { name string @@ -1446,9 +1438,7 @@ func Test_Sync_ServicesRoutes_From_2_2_1_to_2_6_0(t *testing.T) { func Test_Sync_ServicesRoutes_From_2_6_9_Till_2_8_0(t *testing.T) { // setup stage client, err := getTestClient() - if err != nil { - t.Fatalf(err.Error()) - } + require.NoError(t, err) tests := []struct { name string @@ -1487,9 +1477,7 @@ func Test_Sync_ServicesRoutes_From_2_6_9_Till_2_8_0(t *testing.T) { func Test_Sync_ServicesRoutes_From_3x(t *testing.T) { // setup stage client, err := getTestClient() - if err != nil { - t.Fatalf(err.Error()) - } + require.NoError(t, err) tests := []struct { name string @@ -1528,9 +1516,7 @@ func Test_Sync_ServicesRoutes_From_3x(t *testing.T) { func Test_Sync_ServicesRoutes_Konnect(t *testing.T) { // setup stage client, err := getTestClient() - if err != nil { - t.Fatalf(err.Error()) - } + require.NoError(t, err) tests := []struct { name string @@ -1569,9 +1555,7 @@ func Test_Sync_ServicesRoutes_Konnect(t *testing.T) { func Test_Sync_BasicAuth_Plugin_1_4_3(t *testing.T) { // setup stage client, err := getTestClient() - if err != nil { - t.Fatalf(err.Error()) - } + require.NoError(t, err) tests := []struct { name string @@ -1603,9 +1587,7 @@ func Test_Sync_BasicAuth_Plugin_1_4_3(t *testing.T) { func Test_Sync_BasicAuth_Plugin_Earlier_Than_1_5_1(t *testing.T) { // setup stage client, err := getTestClient() - if err != nil { - t.Fatalf(err.Error()) - } + require.NoError(t, err) tests := []struct { name string @@ -1637,9 +1619,7 @@ func Test_Sync_BasicAuth_Plugin_Earlier_Than_1_5_1(t *testing.T) { func Test_Sync_BasicAuth_Plugin_1_5_1(t *testing.T) { // setup stage client, err := getTestClient() - if err != nil { - t.Fatalf(err.Error()) - } + require.NoError(t, err) tests := []struct { name string @@ -1686,9 +1666,7 @@ func Test_Sync_BasicAuth_Plugin_1_5_1(t *testing.T) { func Test_Sync_BasicAuth_Plugin_From_2_0_5_Till_2_8_0(t *testing.T) { // setup stage client, err := getTestClient() - if err != nil { - t.Fatalf(err.Error()) - } + require.NoError(t, err) tests := []struct { name string @@ -1720,9 +1698,7 @@ func Test_Sync_BasicAuth_Plugin_From_2_0_5_Till_2_8_0(t *testing.T) { func Test_Sync_BasicAuth_Plugin_From_3x(t *testing.T) { // setup stage client, err := getTestClient() - if err != nil { - t.Fatalf(err.Error()) - } + require.NoError(t, err) tests := []struct { name string @@ -1754,9 +1730,7 @@ func Test_Sync_BasicAuth_Plugin_From_3x(t *testing.T) { func Test_Sync_BasicAuth_Plugin_From_36(t *testing.T) { // setup stage client, err := getTestClient() - if err != nil { - t.Fatalf(err.Error()) - } + require.NoError(t, err) tests := []struct { name string @@ -1790,9 +1764,7 @@ func Test_Sync_BasicAuth_Plugin_From_36(t *testing.T) { func Test_Sync_Upstream_Target_Till_1_5_2(t *testing.T) { // setup stage client, err := getTestClient() - if err != nil { - t.Fatalf(err.Error()) - } + require.NoError(t, err) // ignore entities fields based on Kong version ignoreFields := []cmp.Option{ @@ -1845,9 +1817,7 @@ func Test_Sync_Upstream_Target_Till_1_5_2(t *testing.T) { func Test_Sync_Upstream_Target_From_2x(t *testing.T) { // setup stage client, err := getTestClient() - if err != nil { - t.Fatalf(err.Error()) - } + require.NoError(t, err) tests := []struct { name string @@ -1880,9 +1850,7 @@ func Test_Sync_Upstream_Target_From_2x(t *testing.T) { func Test_Sync_Upstream_Target_From_30(t *testing.T) { // setup stage client, err := getTestClient() - if err != nil { - t.Fatalf(err.Error()) - } + require.NoError(t, err) tests := []struct { name string @@ -1915,9 +1883,7 @@ func Test_Sync_Upstream_Target_From_30(t *testing.T) { func Test_Sync_Upstream_Target_From_3x(t *testing.T) { // setup stage client, err := getTestClient() - if err != nil { - t.Fatalf(err.Error()) - } + require.NoError(t, err) tests := []struct { name string @@ -1950,9 +1916,7 @@ func Test_Sync_Upstream_Target_From_3x(t *testing.T) { func Test_Sync_Upstream_Target_Konnect(t *testing.T) { // setup stage client, err := getTestClient() - if err != nil { - t.Fatalf(err.Error()) - } + require.NoError(t, err) tests := []struct { name string @@ -1993,9 +1957,7 @@ func Test_Sync_Upstream_Target_Konnect(t *testing.T) { func Test_Sync_Upstreams_Target_ZeroWeight_2x(t *testing.T) { // setup stage client, err := getTestClient() - if err != nil { - t.Fatalf(err.Error()) - } + require.NoError(t, err) tests := []struct { name string @@ -2028,9 +1990,7 @@ func Test_Sync_Upstreams_Target_ZeroWeight_2x(t *testing.T) { func Test_Sync_Upstreams_Target_ZeroWeight_30(t *testing.T) { // setup stage client, err := getTestClient() - if err != nil { - t.Fatalf(err.Error()) - } + require.NoError(t, err) tests := []struct { name string @@ -2063,9 +2023,7 @@ func Test_Sync_Upstreams_Target_ZeroWeight_30(t *testing.T) { func Test_Sync_Upstreams_Target_ZeroWeight_3x(t *testing.T) { // setup stage client, err := getTestClient() - if err != nil { - t.Fatalf(err.Error()) - } + require.NoError(t, err) tests := []struct { name string @@ -2098,9 +2056,7 @@ func Test_Sync_Upstreams_Target_ZeroWeight_3x(t *testing.T) { func Test_Sync_Upstreams_Target_ZeroWeight_Konnect(t *testing.T) { // setup stage client, err := getTestClient() - if err != nil { - t.Fatalf(err.Error()) - } + require.NoError(t, err) tests := []struct { name string @@ -2131,9 +2087,7 @@ func Test_Sync_Upstreams_Target_ZeroWeight_Konnect(t *testing.T) { func Test_Sync_RateLimitingPlugin(t *testing.T) { // setup stage client, err := getTestClient() - if err != nil { - t.Fatalf(err.Error()) - } + require.NoError(t, err) tests := []struct { name string @@ -2172,9 +2126,7 @@ func Test_Sync_RateLimitingPlugin(t *testing.T) { func Test_Sync_FillDefaults_Earlier_Than_1_5_1(t *testing.T) { // setup stage client, err := getTestClient() - if err != nil { - t.Fatalf(err.Error()) - } + require.NoError(t, err) // ignore entities fields based on Kong version ignoreFields := []cmp.Option{ @@ -2216,9 +2168,7 @@ func Test_Sync_FillDefaults_Earlier_Than_1_5_1(t *testing.T) { func Test_Sync_FillDefaults_From_2_0_5_To_2_1_4(t *testing.T) { // setup stage client, err := getTestClient() - if err != nil { - t.Fatalf(err.Error()) - } + require.NoError(t, err) tests := []struct { name string @@ -2261,9 +2211,7 @@ func Test_Sync_FillDefaults_From_2_0_5_To_2_1_4(t *testing.T) { func Test_Sync_FillDefaults_From_2_2_1_to_2_6_0(t *testing.T) { // setup stage client, err := getTestClient() - if err != nil { - t.Fatalf(err.Error()) - } + require.NoError(t, err) tests := []struct { name string @@ -2301,9 +2249,7 @@ func Test_Sync_FillDefaults_From_2_2_1_to_2_6_0(t *testing.T) { func Test_Sync_FillDefaults_From_2_6_9(t *testing.T) { // setup stage client, err := getTestClient() - if err != nil { - t.Fatalf(err.Error()) - } + require.NoError(t, err) tests := []struct { name string @@ -2336,9 +2282,7 @@ func Test_Sync_FillDefaults_From_2_6_9(t *testing.T) { func Test_Sync_SkipCACert_2x(t *testing.T) { // setup stage client, err := getTestClient() - if err != nil { - t.Fatalf(err.Error()) - } + require.NoError(t, err) tests := []struct { name string @@ -2372,9 +2316,7 @@ func Test_Sync_SkipCACert_2x(t *testing.T) { func Test_Sync_SkipCACert_3x(t *testing.T) { // setup stage client, err := getTestClient() - if err != nil { - t.Fatalf(err.Error()) - } + require.NoError(t, err) tests := []struct { name string @@ -2408,9 +2350,7 @@ func Test_Sync_SkipCACert_3x(t *testing.T) { func Test_Sync_RBAC_2x(t *testing.T) { // setup stage client, err := getTestClient() - if err != nil { - t.Fatalf(err.Error()) - } + require.NoError(t, err) tests := []struct { name string @@ -2513,9 +2453,7 @@ func Test_Sync_RBAC_2x(t *testing.T) { func Test_Sync_RBAC_3x(t *testing.T) { // setup stage client, err := getTestClient() - if err != nil { - t.Fatalf(err.Error()) - } + require.NoError(t, err) tests := []struct { name string @@ -2618,9 +2556,7 @@ func Test_Sync_RBAC_3x(t *testing.T) { func Test_Sync_Create_Route_With_Service_Name_Reference_2x(t *testing.T) { // setup stage client, err := getTestClient() - if err != nil { - t.Fatalf(err.Error()) - } + require.NoError(t, err) tests := []struct { name string @@ -2651,9 +2587,7 @@ func Test_Sync_Create_Route_With_Service_Name_Reference_2x(t *testing.T) { func Test_Sync_Create_Route_With_Service_Name_Reference_3x(t *testing.T) { // setup stage client, err := getTestClient() - if err != nil { - t.Fatalf(err.Error()) - } + require.NoError(t, err) tests := []struct { name string @@ -2687,9 +2621,7 @@ func Test_Sync_Create_Route_With_Service_Name_Reference_3x(t *testing.T) { func Test_Sync_PluginsOnEntitiesTill_3_0_0(t *testing.T) { // setup stage client, err := getTestClient() - if err != nil { - t.Fatalf(err.Error()) - } + require.NoError(t, err) tests := []struct { name string @@ -2724,9 +2656,7 @@ func Test_Sync_PluginsOnEntitiesTill_3_0_0(t *testing.T) { func Test_Sync_PluginsOnEntitiesFrom_3_0_0(t *testing.T) { // setup stage client, err := getTestClient() - if err != nil { - t.Fatalf(err.Error()) - } + require.NoError(t, err) tests := []struct { name string @@ -2761,9 +2691,7 @@ func Test_Sync_PluginsOnEntitiesFrom_3_0_0(t *testing.T) { func Test_Sync_PluginOrdering(t *testing.T) { // setup stage client, err := getTestClient() - if err != nil { - t.Fatalf(err.Error()) - } + require.NoError(t, err) tests := []struct { name string @@ -2920,9 +2848,7 @@ u8S6yNlu2Q== func Test_Sync_Vault(t *testing.T) { // setup stage client, err := getTestClient() - if err != nil { - t.Fatalf(err.Error()) - } + require.NoError(t, err) tests := []struct { name string @@ -3042,9 +2968,7 @@ func Test_Sync_Vault(t *testing.T) { func Test_Sync_UpdateUsernameInConsumerWithCustomID(t *testing.T) { // setup stage client, err := getTestClient() - if err != nil { - t.Fatalf(err.Error()) - } + require.NoError(t, err) tests := []struct { name string @@ -3086,9 +3010,7 @@ func Test_Sync_UpdateUsernameInConsumerWithCustomID(t *testing.T) { func Test_Sync_UpdateConsumerWithCustomID(t *testing.T) { // setup stage client, err := getTestClient() - if err != nil { - t.Fatalf(err.Error()) - } + require.NoError(t, err) tests := []struct { name string @@ -3130,9 +3052,7 @@ func Test_Sync_UpdateConsumerWithCustomID(t *testing.T) { func Test_Sync_UpdateUsernameInConsumerWithCustomID_3x(t *testing.T) { // setup stage client, err := getTestClient() - if err != nil { - t.Fatalf(err.Error()) - } + require.NoError(t, err) tests := []struct { name string @@ -3174,9 +3094,7 @@ func Test_Sync_UpdateUsernameInConsumerWithCustomID_3x(t *testing.T) { func Test_Sync_UpdateConsumerWithCustomID_3x(t *testing.T) { // setup stage client, err := getTestClient() - if err != nil { - t.Fatalf(err.Error()) - } + require.NoError(t, err) tests := []struct { name string @@ -3217,9 +3135,7 @@ func Test_Sync_UpdateConsumerWithCustomID_3x(t *testing.T) { // - 2.7+ func Test_Sync_ConsumerGroupsTill30(t *testing.T) { client, err := getTestClient() - if err != nil { - t.Fatalf(err.Error()) - } + require.NoError(t, err) tests := []struct { name string kongFile string @@ -3257,9 +3173,7 @@ func Test_Sync_ConsumerGroupsTill30(t *testing.T) { // - 3.1 func Test_Sync_ConsumerGroups_31(t *testing.T) { client, err := getTestClient() - if err != nil { - t.Fatalf(err.Error()) - } + require.NoError(t, err) tests := []struct { name string kongFile string @@ -3333,9 +3247,8 @@ func Test_Sync_ConsumerGroupsRLAFrom31(t *testing.T) { maxRegularRequestsNumber = 5 ) client, err := getTestClient() - if err != nil { - t.Fatalf(err.Error()) - } + require.NoError(t, err) + require.NoError(t, err) tests := []struct { name string kongFile string @@ -3442,9 +3355,7 @@ func Test_Sync_ConsumerGroupsRLAFrom31(t *testing.T) { // - konnect func Test_Sync_ConsumerGroupsKonnect(t *testing.T) { client, err := getTestClient() - if err != nil { - t.Fatalf(err.Error()) - } + require.NoError(t, err) tests := []struct { name string kongFile string @@ -3481,9 +3392,7 @@ func Test_Sync_ConsumerGroupsKonnect(t *testing.T) { func Test_Sync_PluginInstanceName(t *testing.T) { // setup stage client, err := getTestClient() - if err != nil { - t.Fatalf(err.Error()) - } + require.NoError(t, err) tests := []struct { name string @@ -3562,9 +3471,7 @@ func Test_Sync_PluginInstanceName(t *testing.T) { func Test_Sync_SkipConsumers(t *testing.T) { // setup stage client, err := getTestClient() - if err != nil { - t.Fatalf(err.Error()) - } + require.NoError(t, err) tests := []struct { name string @@ -3612,9 +3519,7 @@ func Test_Sync_SkipConsumers_34x(t *testing.T) { runWhen(t, "enterprise", ">=3.4.0") // setup stage client, err := getTestClient() - if err != nil { - t.Fatalf(err.Error()) - } + require.NoError(t, err) tests := []struct { name string @@ -3784,9 +3689,7 @@ func Test_Sync_SkipConsumers_Konnect(t *testing.T) { runWhenKonnect(t) // setup stage client, err := getTestClient() - if err != nil { - t.Fatalf(err.Error()) - } + require.NoError(t, err) tests := []struct { name string @@ -3994,9 +3897,7 @@ func Test_Sync_ChangingIDsWhileKeepingNames(t *testing.T) { runWhenKongOrKonnect(t, ">=3.0.0") client, err := getTestClient() - if err != nil { - t.Fatalf(err.Error()) - } + require.NoError(t, err) // These are the IDs that should be present in Kong after the second sync in all cases. var ( @@ -4096,9 +3997,7 @@ func Test_Sync_UpdateWithExplicitIDs(t *testing.T) { setup(t) client, err := getTestClient() - if err != nil { - t.Fatalf(err.Error()) - } + require.NoError(t, err) const ( beforeConfig = "testdata/sync/021-update-with-explicit-ids/before.yaml" @@ -4149,9 +4048,7 @@ func Test_Sync_UpdateWithExplicitIDsWithNoNames(t *testing.T) { setup(t) client, err := getTestClient() - if err != nil { - t.Fatalf(err.Error()) - } + require.NoError(t, err) const ( beforeConfig = "testdata/sync/022-update-with-explicit-ids-with-no-names/before.yaml" @@ -4194,9 +4091,7 @@ func Test_Sync_CreateCertificateWithSNIs(t *testing.T) { setup(t) client, err := getTestClient() - if err != nil { - t.Fatalf(err.Error()) - } + require.NoError(t, err) err = sync("testdata/sync/023-create-and-update-certificate-with-snis/initial.yaml") require.NoError(t, err) @@ -4256,9 +4151,7 @@ func Test_Sync_ConsumersWithCustomIDAndOrUsername(t *testing.T) { setup(t) client, err := getTestClient() - if err != nil { - t.Fatalf(err.Error()) - } + require.NoError(t, err) err = sync("testdata/sync/024-consumers-with-custom_id-and-username/kong3x.yaml") require.NoError(t, err) @@ -4334,9 +4227,7 @@ func Test_Sync_ConsumerGroupsScopedPlugins(t *testing.T) { maxRegularRequestsNumber = 5 ) client, err := getTestClient() - if err != nil { - t.Fatalf(err.Error()) - } + require.NoError(t, err) tests := []struct { name string kongFile string @@ -4847,9 +4738,8 @@ func Test_Sync_KonnectRename(t *testing.T) { }) } client, err := getTestClient() - if err != nil { - t.Fatalf(err.Error()) - } + require.NoError(t, err) + sync(tc.kongFile, tc.flags...) testKongState(t, client, true, tc.expectedState, nil) }) @@ -4907,9 +4797,7 @@ func Test_Sync_DoNotUpdateCreatedAt(t *testing.T) { setup(t) client, err := getTestClient() - if err != nil { - t.Fatalf(err.Error()) - } + require.NoError(t, err) const ( oldConfig = "testdata/sync/027-created-at/old.yaml" @@ -4922,9 +4810,7 @@ func Test_Sync_DoNotUpdateCreatedAt(t *testing.T) { // get the current state ctx := context.Background() oldKongState, err := deckDump.Get(ctx, client, deckDump.Config{}) - if err != nil { - t.Errorf(err.Error()) - } + require.NoError(t, err) // update entities time.Sleep(time.Second) @@ -4932,9 +4818,7 @@ func Test_Sync_DoNotUpdateCreatedAt(t *testing.T) { // get the new state newKongState, err := deckDump.Get(ctx, client, deckDump.Config{}) - if err != nil { - t.Errorf(err.Error()) - } + require.NoError(t, err) // verify that the created_at have not changed across deployments require.Equal(t, oldKongState.Services[0].CreatedAt, newKongState.Services[0].CreatedAt) @@ -4996,9 +4880,7 @@ func Test_Sync_ConsumerGroupConsumersWithCustomID(t *testing.T) { setup(t) client, err := getTestClient() - if err != nil { - t.Fatalf(err.Error()) - } + require.NoError(t, err) expectedState := utils.KongRawState{ ConsumerGroups: []*kong.ConsumerGroupObject{ @@ -5205,9 +5087,7 @@ func Test_Sync_ConsumerGroupConsumerFromUpstream(t *testing.T) { setup(t) client, err := getTestClient() - if err != nil { - t.Fatalf(err.Error()) - } + require.NoError(t, err) expectedState := utils.KongRawState{ ConsumerGroups: []*kong.ConsumerGroupObject{ @@ -5255,9 +5135,7 @@ func Test_Sync_ConsumerGroupConsumerWithTags(t *testing.T) { setup(t) client, err := getTestClient() - if err != nil { - t.Fatalf(err.Error()) - } + require.NoError(t, err) expectedState := utils.KongRawState{ ConsumerGroups: []*kong.ConsumerGroupObject{ @@ -5316,9 +5194,7 @@ func Test_Sync_FilterChains(t *testing.T) { setup(t) client, err := getTestClient() - if err != nil { - t.Fatalf(err.Error()) - } + require.NoError(t, err) service := kong.Service{ ID: kong.String("58076db2-28b6-423b-ba39-a797193017f7"), diff --git a/tests/integration/test_utils.go b/tests/integration/test_utils.go index 83d5a8677..d1d37f676 100644 --- a/tests/integration/test_utils.go +++ b/tests/integration/test_utils.go @@ -15,13 +15,9 @@ import ( deckDump "github.com/kong/go-database-reconciler/pkg/dump" "github.com/kong/go-database-reconciler/pkg/utils" "github.com/kong/go-kong/kong" + "github.com/stretchr/testify/require" ) -func int32p(i int) *int32 { - p := int32(i) - return &p -} - func getKongAddress() string { address := os.Getenv("DECK_KONG_ADDR") if address != "" { @@ -47,7 +43,8 @@ func getTestClient() (*kong.Client, error) { return cmd.GetKongClientForKonnectMode(ctx, &konnectConfig) } return utils.GetKongClient(utils.KongClientConfig{ - Address: getKongAddress(), + Address: getKongAddress(), + Retryable: true, }) } @@ -206,9 +203,7 @@ func testKongState(t *testing.T, client *kong.Client, isKonnect bool, } } kongState, err := deckDump.Get(ctx, client, dumpConfig) - if err != nil { - t.Errorf(err.Error()) - } + require.NoError(t, err) opt := []cmp.Option{ cmpopts.IgnoreFields(kong.Service{}, "CreatedAt", "UpdatedAt"), @@ -234,7 +229,7 @@ func testKongState(t *testing.T, client *kong.Client, isKonnect bool, opt = append(opt, ignoreFields...) if diff := cmp.Diff(kongState, &expectedState, opt...); diff != "" { - t.Errorf(diff) + t.Errorf("unexpected diff:\n%s", diff) } } @@ -242,14 +237,12 @@ func reset(t *testing.T, opts ...string) { t.Helper() deckCmd := cmd.NewRootCmd() - args := []string{"reset", "--force"} + args := []string{"gateway", "reset", "--force"} if len(opts) > 0 { args = append(args, opts...) } deckCmd.SetArgs(args) - if err := deckCmd.Execute(); err != nil { - t.Fatalf(err.Error(), "failed to reset Kong's state") - } + require.NoError(t, deckCmd.Execute(), "failed to reset Kong's state") } func readFile(filepath string) (string, error) {