Skip to content

Commit

Permalink
chore: add context plumbing and enforce errcheck via golangci-lint co…
Browse files Browse the repository at this point in the history
…nfig (#1509)
  • Loading branch information
pmalek authored Jan 28, 2025
1 parent b786101 commit 44b5f64
Show file tree
Hide file tree
Showing 8 changed files with 157 additions and 156 deletions.
17 changes: 7 additions & 10 deletions .golangci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -5,35 +5,36 @@ run:
linters:
enable:
- asciicheck
- copyloopvar
- dogsled
- durationcheck
- errcheck
- errorlint
- exhaustive
- copyloopvar
- gci
- goconst
- gofmt
- gofumpt
- goimports
- gomodguard
- gosec
- gosimple
- govet
- importas
- lll
- gosimple
- staticcheck
- unused
- misspell
- nakedret
- nilerr
- nolintlint
- predeclared
- prealloc
- predeclared
- revive
- staticcheck
- stylecheck
- unconvert
- unparam
- unused
- wastedassign
- errorlint
issues:
max-same-issues: 0
exclude-rules:
Expand All @@ -49,10 +50,6 @@ issues:
- gosec
text: "weak random number generator"
path: _test\.go
- linters:
- errcheck
text: "Error return value" # ignore err not checked in test files
path: _test\.go
- linters:
- gosec
text: "Expect WriteFile permissions to be 0600 or less"
Expand Down
2 changes: 1 addition & 1 deletion kong2tf/kong2tf_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ func compareFileContent(t *testing.T, expectedFilename string, actualContent []b
}

actualFilename := baseLocation + strings.Replace(expectedFilename, "-expected.", "-actual.", 1)
os.WriteFile(actualFilename, actualContent, 0o600)
require.NoError(t, os.WriteFile(actualFilename, actualContent, 0o600))

// compare the actual content with the expected content
// both should be the same terraform file
Expand Down
7 changes: 5 additions & 2 deletions tests/integration/apply_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,11 @@
package integration

import (
"context"
"testing"

"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/require"
)

func Test_Apply_3x(t *testing.T) {
Expand Down Expand Up @@ -51,8 +53,9 @@ func Test_Apply_3x(t *testing.T) {
t.Run(tc.name, func(t *testing.T) {
runWhen(t, tc.runWhen, ">=3.0.0")
setup(t)
apply(tc.firstFile)
apply(tc.secondFile)
ctx := context.Background()
require.NoError(t, apply(ctx, tc.firstFile))
require.NoError(t, apply(ctx, tc.secondFile))

out, _ := dump()

Expand Down
25 changes: 13 additions & 12 deletions tests/integration/diff_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
package integration

import (
"context"
"testing"

"github.com/kong/go-database-reconciler/pkg/utils"
Expand Down Expand Up @@ -538,7 +539,7 @@ func Test_Diff_Masked_OlderThan3x(t *testing.T) {
setup(t)

// initialize state
assert.NoError(t, sync(tc.initialStateFile))
assert.NoError(t, sync(context.Background(), tc.initialStateFile))

out, err := diff(tc.stateFile)
assert.NoError(t, err)
Expand All @@ -555,7 +556,7 @@ func Test_Diff_Masked_OlderThan3x(t *testing.T) {
setup(t)

// initialize state
assert.NoError(t, sync(tc.initialStateFile))
assert.NoError(t, sync(context.Background(), tc.initialStateFile))

out, err := diff(tc.stateFile, "--json-output")
assert.NoError(t, err)
Expand Down Expand Up @@ -590,7 +591,7 @@ func Test_Diff_Masked_NewerThan3x(t *testing.T) {
setup(t)

// initialize state
assert.NoError(t, sync(tc.initialStateFile))
assert.NoError(t, sync(context.Background(), tc.initialStateFile))

out, err := diff(tc.stateFile)
assert.NoError(t, err)
Expand All @@ -606,7 +607,7 @@ func Test_Diff_Masked_NewerThan3x(t *testing.T) {
setup(t)

// initialize state
assert.NoError(t, sync(tc.initialStateFile))
assert.NoError(t, sync(context.Background(), tc.initialStateFile))

out, err := diff(tc.stateFile, "--json-output")
assert.NoError(t, err)
Expand All @@ -622,7 +623,7 @@ func Test_Diff_Masked_NewerThan3x(t *testing.T) {
setup(t)

// initialize state
assert.NoError(t, sync(tc.initialStateFile))
assert.NoError(t, sync(context.Background(), tc.initialStateFile))

out, err := diff(tc.stateFile, "--json-output")
assert.NoError(t, err)
Expand Down Expand Up @@ -657,7 +658,7 @@ func Test_Diff_Unmasked_OlderThan3x(t *testing.T) {
setup(t)

// initialize state
assert.NoError(t, sync(tc.initialStateFile))
assert.NoError(t, sync(context.Background(), tc.initialStateFile))

out, err := diff(tc.stateFile, "--no-mask-deck-env-vars-value")
assert.NoError(t, err)
Expand All @@ -673,7 +674,7 @@ func Test_Diff_Unmasked_OlderThan3x(t *testing.T) {
setup(t)

// initialize state
assert.NoError(t, sync(tc.initialStateFile))
assert.NoError(t, sync(context.Background(), tc.initialStateFile))

out, err := diff(tc.stateFile, "--no-mask-deck-env-vars-value", "--json-output")
assert.NoError(t, err)
Expand Down Expand Up @@ -708,7 +709,7 @@ func Test_Diff_Unmasked_NewerThan3x(t *testing.T) {
setup(t)

// initialize state
assert.NoError(t, sync(tc.initialStateFile))
assert.NoError(t, sync(context.Background(), tc.initialStateFile))

out, err := diff(tc.stateFile, "--no-mask-deck-env-vars-value")
assert.NoError(t, err)
Expand All @@ -724,7 +725,7 @@ func Test_Diff_Unmasked_NewerThan3x(t *testing.T) {
setup(t)

// initialize state
assert.NoError(t, sync(tc.initialStateFile))
assert.NoError(t, sync(context.Background(), tc.initialStateFile))

out, err := diff(tc.stateFile, "--no-mask-deck-env-vars-value", "--json-output")
assert.NoError(t, err)
Expand All @@ -740,7 +741,7 @@ func Test_Diff_Unmasked_NewerThan3x(t *testing.T) {
setup(t)

// initialize state
assert.NoError(t, sync(tc.initialStateFile))
assert.NoError(t, sync(context.Background(), tc.initialStateFile))

out, err := diff(tc.stateFile, "--no-mask-deck-env-vars-value", "--json-output")
assert.NoError(t, err)
Expand Down Expand Up @@ -775,7 +776,7 @@ func Test_Diff_NoDiffUnorderedArray(t *testing.T) {

// test that the diff command does not return any changes when
// array fields are not sorted.
assert.NoError(t, sync(tc.stateFile, "--timeout", "60"))
assert.NoError(t, sync(context.Background(), tc.stateFile, "--timeout", "60"))

out, err := diff(tc.stateFile)
assert.NoError(t, err)
Expand All @@ -794,7 +795,7 @@ func Test_Diff_NoDiffCompressedTarget(t *testing.T) {
// test that the diff command does not return any changes when
// target is a compressed IPv6.
stateFile := "testdata/diff/005-no-diff-target/kong.yaml"
assert.NoError(t, sync(stateFile))
assert.NoError(t, sync(context.Background(), stateFile))

out, err := diff(stateFile)
assert.NoError(t, err)
Expand Down
19 changes: 10 additions & 9 deletions tests/integration/dump_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
package integration

import (
"context"
"testing"

"github.com/stretchr/testify/assert"
Expand All @@ -26,7 +27,7 @@ func Test_Dump_SelectTags_30(t *testing.T) {
runWhen(t, "kong", ">=3.0.0 <3.1.0")
setup(t)

assert.NoError(t, sync(tc.stateFile))
assert.NoError(t, sync(context.Background(), tc.stateFile))

output, err := dump(
"--select-tag", "managed-by-deck",
Expand Down Expand Up @@ -67,7 +68,7 @@ func Test_Dump_SelectTags_3x(t *testing.T) {
runWhen(t, "kong", tc.runWhen)
setup(t)

assert.NoError(t, sync(tc.stateFile))
assert.NoError(t, sync(context.Background(), tc.stateFile))

output, err := dump(
"--select-tag", "managed-by-deck",
Expand Down Expand Up @@ -153,7 +154,7 @@ func Test_Dump_SkipConsumers(t *testing.T) {
tc.runWhen(t)
setup(t)

assert.NoError(t, sync(tc.stateFile))
assert.NoError(t, sync(context.Background(), tc.stateFile))

var (
output string
Expand Down Expand Up @@ -203,7 +204,7 @@ func Test_Dump_SkipConsumers_Konnect(t *testing.T) {
runWhenKonnect(t)
setup(t)

assert.NoError(t, sync(tc.stateFile))
assert.NoError(t, sync(context.Background(), tc.stateFile))

var (
output string
Expand Down Expand Up @@ -256,7 +257,7 @@ func Test_Dump_KonnectRename(t *testing.T) {
runWhenKonnect(t)
setup(t)

assert.NoError(t, sync(tc.stateFile))
assert.NoError(t, sync(context.Background(), tc.stateFile))

var (
output string
Expand All @@ -279,7 +280,7 @@ func Test_Dump_ConsumerGroupConsumersWithCustomID(t *testing.T) {
runWhen(t, "enterprise", ">=3.0.0")
setup(t)

require.NoError(t, sync("testdata/sync/028-consumer-group-consumers-custom_id/kong.yaml"))
require.NoError(t, sync(context.Background(), "testdata/sync/028-consumer-group-consumers-custom_id/kong.yaml"))

var output string
flags := []string{"-o", "-", "--with-id"}
Expand All @@ -295,7 +296,7 @@ func Test_Dump_ConsumerGroupConsumersWithCustomID_Konnect(t *testing.T) {
runWhen(t, "konnect", "")
setup(t)

require.NoError(t, sync("testdata/sync/028-consumer-group-consumers-custom_id/kong.yaml"))
require.NoError(t, sync(context.Background(), "testdata/sync/028-consumer-group-consumers-custom_id/kong.yaml"))

var output string
flags := []string{"-o", "-", "--with-id"}
Expand Down Expand Up @@ -331,7 +332,7 @@ func Test_Dump_FilterChains(t *testing.T) {
for _, tc := range tests {
t.Run(tc.version, func(t *testing.T) {
runWhen(t, "kong", tc.version)
require.NoError(t, sync(tc.input))
require.NoError(t, sync(context.Background(), tc.input))

var output string
flags := []string{"-o", "-"}
Expand Down Expand Up @@ -419,7 +420,7 @@ func Test_SkipConsumersWithConsumerGroups(t *testing.T) {
tc.runWhen(t)
setup(t)

assert.NoError(t, sync(tc.stateFile))
assert.NoError(t, sync(context.Background(), tc.stateFile))

var (
output string
Expand Down
7 changes: 4 additions & 3 deletions tests/integration/reset_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
package integration

import (
"context"
"testing"

"github.com/kong/go-database-reconciler/pkg/utils"
Expand Down Expand Up @@ -63,7 +64,7 @@ func Test_Reset_SkipCACert_2x(t *testing.T) {
runWhen(t, "kong", ">=2.7.0 <3.0.0")
setup(t)

sync(tc.kongFile)
require.NoError(t, sync(context.Background(), tc.kongFile))
reset(t, "--skip-ca-certificates")
testKongState(t, client, false, tc.expectedState, nil)
})
Expand Down Expand Up @@ -97,7 +98,7 @@ func Test_Reset_SkipCACert_3x(t *testing.T) {
runWhen(t, "kong", ">=3.0.0")
setup(t)

sync(tc.kongFile)
require.NoError(t, sync(context.Background(), tc.kongFile))
reset(t, "--skip-ca-certificates")
testKongState(t, client, false, tc.expectedState, nil)
})
Expand All @@ -111,7 +112,7 @@ func Test_Reset_ConsumerGroupConsumersWithCustomID(t *testing.T) {
client, err := getTestClient()
require.NoError(t, err)

require.NoError(t, sync("testdata/sync/028-consumer-group-consumers-custom_id/kong.yaml"))
require.NoError(t, sync(context.Background(), "testdata/sync/028-consumer-group-consumers-custom_id/kong.yaml"))
reset(t)
testKongState(t, client, false, utils.KongRawState{}, nil)
}
Loading

0 comments on commit 44b5f64

Please sign in to comment.