Skip to content

Commit

Permalink
chore: fix CI and update Kong images (#79)
Browse files Browse the repository at this point in the history
* chore: fix CI and update Kong images

* chore: fix linter issues

* chore: fix test

* chore: fix Test_Sync_ConsumerGroupsScopedPlugins_After350/creates_consumer_groups_scoped_plugins

* chore(ci): don't 'go build' a library

* chore: fix Test_Sync_ConsumerGroupsScopedPlugins_After350 schema changes
  • Loading branch information
pmalek authored Apr 4, 2024
1 parent be872d2 commit 599ea65
Show file tree
Hide file tree
Showing 14 changed files with 271 additions and 76 deletions.
5 changes: 2 additions & 3 deletions .github/workflows/integration-enterprise.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ jobs:
- 'kong/kong-gateway:3.3'
- 'kong/kong-gateway:3.4'
- 'kong/kong-gateway:3.5'
- 'kong/kong-gateway:3.6'
- 'kong/kong-gateway-dev:latest'
env:
KONG_ANONYMOUS_REPORTS: "off"
Expand All @@ -33,9 +34,7 @@ jobs:
- name: Checkout repository
uses: actions/checkout@v4
- name: Setup go
uses: actions/setup-go@v4
with:
go-version: '^1.20'
uses: actions/setup-go@v5
- name: Login to Docker Hub
uses: docker/login-action@v3
with:
Expand Down
7 changes: 3 additions & 4 deletions .github/workflows/integration.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,8 @@ jobs:
- 'kong:3.3'
- 'kong:3.4'
- 'kong:3.5'
- 'kong/kong:master-alpine'
- 'kong:3.6'
- 'kong/kong:master'
env:
KONG_ANONYMOUS_REPORTS: "off"
KONG_IMAGE: ${{ matrix.kong_image }}
Expand All @@ -34,9 +35,7 @@ jobs:
- name: Checkout repository
uses: actions/checkout@v4
- name: Setup go
uses: actions/setup-go@v4
with:
go-version: '^1.20'
uses: actions/setup-go@v5
- name: Setup Kong
run: make setup-kong
- name: Run integration tests
Expand Down
11 changes: 4 additions & 7 deletions .github/workflows/test.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,8 @@ on:
branches:
- main
pull_request:
- *
branches:
- '**'

jobs:
test:
Expand All @@ -20,11 +21,9 @@ jobs:
- name: Checkout repository
uses: actions/checkout@v4
- name: Setup go
uses: actions/setup-go@v4
with:
go-version: '^1.20'
uses: actions/setup-go@v5
- name: Setup golangci-lint
uses: golangci/golangci-lint-action@v3.7.0
uses: golangci/golangci-lint-action@v4
- name: Run tests with Coverage
run: make coverage
- name: Upload Code Coverage
Expand All @@ -33,5 +32,3 @@ jobs:
name: codecov
token: ${{ secrets.CODECOV_TOKEN }}
fail_ci_if_error: true
- name: Build
run: make build
4 changes: 0 additions & 4 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -9,10 +9,6 @@ test:
lint:
golangci-lint run -v ./...

.PHONY: build
build:
CGO_ENABLED=0 go build -o deck main.go

.PHONY: verify-codegen
verify-codegen:
./scripts/verify-codegen.sh
Expand Down
5 changes: 3 additions & 2 deletions pkg/file/builder.go
Original file line number Diff line number Diff line change
Expand Up @@ -437,8 +437,9 @@ func (b *stateBuilder) consumers() {
return
}
for _, cgc := range consumerGroupConsumers {
if cgc.Consumer != nil && (c.Username != nil && cgc.Consumer.Username != nil && *cgc.Consumer.Username == *c.Username ||
c.CustomID != nil && cgc.Consumer.CustomID != nil && *cgc.Consumer.CustomID == *c.CustomID) {
if cgc.Consumer != nil &&
(c.Username != nil && cgc.Consumer.Username != nil && *cgc.Consumer.Username == *c.Username ||
c.CustomID != nil && cgc.Consumer.CustomID != nil && *cgc.Consumer.CustomID == *c.CustomID) {
c.ID = cgc.Consumer.ID
consumerAlreadyAdded = true
break
Expand Down
30 changes: 10 additions & 20 deletions pkg/file/builder_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -377,7 +377,6 @@ func TestMain(m *testing.M) {
}

func Test_stateBuilder_services(t *testing.T) {
assert := assert.New(t)
rand.Seed(42)
type fields struct {
targetContent *Content
Expand Down Expand Up @@ -459,13 +458,12 @@ func Test_stateBuilder_services(t *testing.T) {
selectTags: []string{"tag1"},
}
b.build()
assert.Equal(tt.want, b.rawState)
assert.Equal(t, tt.want, b.rawState)
})
}
}

func Test_stateBuilder_ingestRoute(t *testing.T) {
assert := assert.New(t)
rand.Seed(42)
type fields struct {
currentState *state.KongState
Expand Down Expand Up @@ -573,13 +571,12 @@ func Test_stateBuilder_ingestRoute(t *testing.T) {
if err := b.ingestRoute(tt.args.route); (err != nil) != tt.wantErr {
t.Errorf("stateBuilder.ingestPlugins() error = %v, wantErr %v", err, tt.wantErr)
}
assert.Equal(tt.wantState, b.rawState)
assert.Equal(t, tt.wantState, b.rawState)
})
}
}

func Test_stateBuilder_ingestTargets(t *testing.T) {
assert := assert.New(t)
rand.Seed(42)
type fields struct {
currentState *state.KongState
Expand Down Expand Up @@ -679,13 +676,12 @@ func Test_stateBuilder_ingestTargets(t *testing.T) {
if err := b.ingestTargets(tt.args.targets); (err != nil) != tt.wantErr {
t.Errorf("stateBuilder.ingestPlugins() error = %v, wantErr %v", err, tt.wantErr)
}
assert.Equal(tt.wantState, b.rawState)
assert.Equal(t, tt.wantState, b.rawState)
})
}
}

func Test_stateBuilder_ingestPlugins(t *testing.T) {
assert := assert.New(t)
rand.Seed(42)
type fields struct {
currentState *state.KongState
Expand Down Expand Up @@ -804,7 +800,7 @@ func Test_stateBuilder_ingestPlugins(t *testing.T) {
if err := b.ingestPlugins(tt.args.plugins); (err != nil) != tt.wantErr {
t.Errorf("stateBuilder.ingestPlugins() error = %v, wantErr %v", err, tt.wantErr)
}
assert.Equal(tt.wantState, b.rawState)
assert.Equal(t, tt.wantState, b.rawState)
})
}
}
Expand Down Expand Up @@ -876,7 +872,6 @@ func Test_pluginRelations(t *testing.T) {
}

func Test_stateBuilder_consumers(t *testing.T) {
assert := assert.New(t)
rand.Seed(42)
type fields struct {
currentState *state.KongState
Expand Down Expand Up @@ -1350,13 +1345,12 @@ func Test_stateBuilder_consumers(t *testing.T) {
d, _ := utils.GetDefaulter(ctx, defaulterTestOpts)
b.defaulter = d
b.build()
assert.Equal(tt.want, b.rawState)
assert.Equal(t, tt.want, b.rawState)
})
}
}

func Test_stateBuilder_certificates(t *testing.T) {
assert := assert.New(t)
rand.Seed(42)
type fields struct {
currentState *state.KongState
Expand Down Expand Up @@ -1518,13 +1512,12 @@ func Test_stateBuilder_certificates(t *testing.T) {
d, _ := utils.GetDefaulter(ctx, defaulterTestOpts)
b.defaulter = d
b.build()
assert.Equal(tt.want, b.rawState)
assert.Equal(t, tt.want, b.rawState)
})
}
}

func Test_stateBuilder_caCertificates(t *testing.T) {
assert := assert.New(t)
rand.Seed(42)
type fields struct {
currentState *state.KongState
Expand Down Expand Up @@ -1592,13 +1585,12 @@ func Test_stateBuilder_caCertificates(t *testing.T) {
d, _ := utils.GetDefaulter(ctx, defaulterTestOpts)
b.defaulter = d
b.build()
assert.Equal(tt.want, b.rawState)
assert.Equal(t, tt.want, b.rawState)
})
}
}

func Test_stateBuilder_upstream(t *testing.T) {
assert := assert.New(t)
rand.Seed(42)
type fields struct {
targetContent *Content
Expand Down Expand Up @@ -1945,13 +1937,12 @@ func Test_stateBuilder_upstream(t *testing.T) {
d, _ := utils.GetDefaulter(ctx, defaulterTestOpts)
b.defaulter = d
b.build()
assert.Equal(tt.want, b.rawState)
assert.Equal(t, tt.want, b.rawState)
})
}
}

func Test_stateBuilder_documents(t *testing.T) {
assert := assert.New(t)
rand.Seed(42)
type fields struct {
targetContent *Content
Expand Down Expand Up @@ -2049,13 +2040,12 @@ func Test_stateBuilder_documents(t *testing.T) {
d, _ := utils.GetDefaulter(ctx, defaulterTestOpts)
b.defaulter = d
b.build()
assert.Equal(tt.want, b.konnectRawState)
assert.Equal(t, tt.want, b.konnectRawState)
})
}
}

func Test_stateBuilder(t *testing.T) {
assert := assert.New(t)
type fields struct {
targetContent *Content
currentState *state.KongState
Expand Down Expand Up @@ -2602,7 +2592,7 @@ func Test_stateBuilder(t *testing.T) {
d, _ := utils.GetDefaulter(ctx, defaulterTestOpts)
b.defaulter = d
b.build()
assert.Equal(tt.want, b.rawState)
assert.Equal(t, tt.want, b.rawState)
})
}
}
Expand Down
10 changes: 5 additions & 5 deletions pkg/file/reader_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ import (
"github.com/kong/go-database-reconciler/pkg/dump"
"github.com/kong/go-kong/kong"
"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/require"
)

func Test_ensureJSON(t *testing.T) {
Expand Down Expand Up @@ -152,15 +153,14 @@ func TestReadKongStateFromStdin(t *testing.T) {

func TestReadKongStateFromFile(t *testing.T) {
filenames := []string{"testdata/config.yaml"}
assert := assert.New(t)
assert.Equal("testdata/config.yaml", filenames[0])
require.Equal(t, "testdata/config.yaml", filenames[0])

c, err := GetContentFromFiles(filenames, false)
assert.NotNil(c)
assert.Nil(err)
require.NotNil(t, c)
require.Nil(t, err)

t.Run("enabled field for service is read", func(t *testing.T) {
assert.Equal(kong.Service{
assert.Equal(t, kong.Service{
Name: kong.String("svc1"),
Host: kong.String("mockbin.org"),
Enabled: kong.Bool(true),
Expand Down
2 changes: 1 addition & 1 deletion pkg/state/utils.go
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ const (
var allIndex = &memdb.IndexSchema{
Name: all,
Indexer: &memdb.ConditionalIndex{
Conditional: func(v interface{}) (bool, error) {
Conditional: func(_ interface{}) (bool, error) {
return true, nil
},
},
Expand Down
4 changes: 1 addition & 3 deletions pkg/types/core.go
Original file line number Diff line number Diff line change
Expand Up @@ -51,9 +51,7 @@ func (e entityImpl) Differ() Differ {
return e.differ
}

var (
ErrEmptyCRUDArgs = errors.New("empty CRUD arguments")
)
var ErrEmptyCRUDArgs = errors.New("empty CRUD arguments")

type EntityOpts struct {
CurrentState *state.KongState
Expand Down
6 changes: 3 additions & 3 deletions pkg/utils/defaulter.go
Original file line number Diff line number Diff line change
Expand Up @@ -133,7 +133,7 @@ func (t kongTransformer) Transformer(typ reflect.Type) func(dst, src reflect.Val
switch typ {
case reflect.TypeOf(ar):

return func(dst, src reflect.Value) error {
return func(dst, _ reflect.Value) error {
if dst.CanSet() {
if reflect.DeepEqual(reflect.Zero(dst.Type()).Interface(), dst.Interface()) {
return nil
Expand All @@ -143,7 +143,7 @@ func (t kongTransformer) Transformer(typ reflect.Type) func(dst, src reflect.Val
}
case reflect.TypeOf(a):

return func(dst, src reflect.Value) error {
return func(dst, _ reflect.Value) error {
if dst.CanSet() {
if reflect.DeepEqual(reflect.Zero(dst.Type()).Interface(), dst.Interface()) {
return nil
Expand All @@ -153,7 +153,7 @@ func (t kongTransformer) Transformer(typ reflect.Type) func(dst, src reflect.Val
}
case reflect.TypeOf(b):

return func(dst, src reflect.Value) error {
return func(dst, _ reflect.Value) error {
if dst.CanSet() {
if reflect.DeepEqual(reflect.Zero(dst.Type()).Interface(), dst.Interface()) {
return nil
Expand Down
Loading

0 comments on commit 599ea65

Please sign in to comment.