Skip to content

Commit

Permalink
Merge remote-tracking branch 'origin/main' into chore/extract-library
Browse files Browse the repository at this point in the history
  • Loading branch information
rainest committed Nov 21, 2023
2 parents 676afd9 + f7e0a17 commit 7893868
Show file tree
Hide file tree
Showing 8 changed files with 218 additions and 71 deletions.
27 changes: 10 additions & 17 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ replace github.com/yudai/gojsondiff v1.0.0 => github.com/Kong/gojsondiff v1.3.0
require (
github.com/acarl005/stripansi v0.0.0-20180116102854-5a71ef0e047d
github.com/blang/semver/v4 v4.0.0
github.com/daveshanley/vacuum v0.4.5
github.com/daveshanley/vacuum v0.5.0
github.com/fatih/color v1.15.0
github.com/google/go-cmp v0.6.0
github.com/kong/go-apiops v0.1.24
Expand All @@ -31,20 +31,17 @@ require (
github.com/Kong/go-diff v1.2.2 // indirect
github.com/Kong/gojsondiff v1.3.2 // indirect
github.com/adrg/strutil v0.2.3 // indirect
github.com/alecthomas/chroma v0.10.0 // indirect
github.com/cenkalti/backoff/v4 v4.2.1 // indirect
github.com/containerd/console v1.0.3 // indirect
github.com/davecgh/go-spew v1.1.2-0.20180830191138-d8f796af33cc // indirect
github.com/dlclark/regexp2 v1.10.0 // indirect
github.com/dop251/goja v0.0.0-20231027120936-b396bb4c349d // indirect
github.com/dop251/goja_nodejs v0.0.0-20231022114343-5c1f9037c9ab // indirect
github.com/dprotaso/go-yit v0.0.0-20220510233725-9ba8df137936 // indirect
github.com/dustin/go-humanize v1.0.1 // indirect
github.com/emicklei/go-restful/v3 v3.9.0 // indirect
github.com/fsnotify/fsnotify v1.6.0 // indirect
github.com/getkin/kin-openapi v0.108.0 // indirect
github.com/ghodss/yaml v1.0.0 // indirect
github.com/gizak/termui/v3 v3.1.0 // indirect
github.com/go-logr/logr v1.2.4 // indirect
github.com/go-logr/stdr v1.2.2 // indirect
github.com/go-ole/go-ole v1.2.6 // indirect
Expand Down Expand Up @@ -80,19 +77,17 @@ require (
github.com/mattn/go-colorable v0.1.13 // indirect
github.com/mattn/go-isatty v0.0.20 // indirect
github.com/mattn/go-runewidth v0.0.15 // indirect
github.com/mitchellh/go-wordwrap v0.0.0-20150314170334-ad45545899c7 // indirect
github.com/mitchellh/mapstructure v1.5.0 // indirect
github.com/modern-go/concurrent v0.0.0-20180306012644-bacd9c7ef1dd // indirect
github.com/modern-go/reflect2 v1.0.2 // indirect
github.com/mohae/deepcopy v0.0.0-20170929034955-c48cc78d4826 // indirect
github.com/mozillazg/go-unidecode v0.2.0 // indirect
github.com/nsf/termbox-go v0.0.0-20190121233118-02980233997d // indirect
github.com/pb33f/libopenapi v0.13.9 // indirect
github.com/pb33f/libopenapi-validator v0.0.27 // indirect
github.com/pb33f/libopenapi v0.13.11 // indirect
github.com/pb33f/libopenapi-validator v0.0.28 // indirect
github.com/pelletier/go-toml/v2 v2.1.0 // indirect
github.com/pmezard/go-difflib v1.0.1-0.20181226105442-5d4384ee4fb2 // indirect
github.com/power-devops/perfstat v0.0.0-20210106213030-5aafc221ea8c // indirect
github.com/pterm/pterm v0.12.69 // indirect
github.com/pterm/pterm v0.12.70 // indirect
github.com/rivo/uniseg v0.4.4 // indirect
github.com/sagikazarmark/locafero v0.3.0 // indirect
github.com/sagikazarmark/slog-shim v0.1.0 // indirect
Expand All @@ -102,7 +97,6 @@ require (
github.com/sourcegraph/conc v0.3.0 // indirect
github.com/spf13/afero v1.10.0 // indirect
github.com/spf13/cast v1.5.1 // indirect
github.com/spf13/jwalterweatherman v1.1.0 // indirect
github.com/ssgelm/cookiejarparser v1.0.1 // indirect
github.com/subosito/gotenv v1.6.0 // indirect
github.com/tidwall/gjson v1.17.0 // indirect
Expand All @@ -118,14 +112,13 @@ require (
github.com/yudai/golcs v0.0.0-20170316035057-ecda9a501e82 // indirect
github.com/yusufpapurcu/wmi v1.2.3 // indirect
go.uber.org/multierr v1.11.0 // indirect
go.uber.org/zap v1.26.0 // indirect
golang.org/x/exp v0.0.0-20231006140011-7918f672742d // indirect
golang.org/x/mod v0.13.0 // indirect
golang.org/x/net v0.17.0 // indirect
golang.org/x/exp v0.0.0-20231110203233-9a3e6036ecaa // indirect
golang.org/x/mod v0.14.0 // indirect
golang.org/x/net v0.18.0 // indirect
golang.org/x/sys v0.14.0 // indirect
golang.org/x/term v0.13.0 // indirect
golang.org/x/text v0.13.0 // indirect
golang.org/x/tools v0.14.0 // indirect
golang.org/x/term v0.14.0 // indirect
golang.org/x/text v0.14.0 // indirect
golang.org/x/tools v0.15.0 // indirect
google.golang.org/protobuf v1.31.0 // indirect
gopkg.in/ini.v1 v1.67.0 // indirect
gopkg.in/yaml.v2 v2.4.0 // indirect
Expand Down
78 changes: 24 additions & 54 deletions go.sum

Large diffs are not rendered by default.

33 changes: 33 additions & 0 deletions tests/integration/dump_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import (
"testing"

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

func Test_Dump_SelectTags_30(t *testing.T) {
Expand Down Expand Up @@ -251,3 +252,35 @@ func Test_Dump_KonnectRename(t *testing.T) {
})
}
}

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"))

var output string
flags := []string{"-o", "-", "--with-id"}
output, err := dump(flags...)
assert.NoError(t, err)

expected, err := readFile("testdata/sync/028-consumer-group-consumers-custom_id/kong.yaml")
assert.NoError(t, err)
assert.Equal(t, expected, output)
}

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"))

var output string
flags := []string{"-o", "-", "--with-id"}
output, err := dump(flags...)
assert.NoError(t, err)

expected, err := readFile("testdata/dump/003-consumer-group-consumers-custom_id/konnect.yaml")
assert.NoError(t, err)
assert.Equal(t, expected, output)
}
15 changes: 15 additions & 0 deletions tests/integration/reset_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import (

"github.com/kong/go-database-reconciler/pkg/utils"
"github.com/kong/go-kong/kong"
"github.com/stretchr/testify/require"
)

var caCert = &kong.CACertificate{
Expand Down Expand Up @@ -106,3 +107,17 @@ func Test_Reset_SkipCACert_3x(t *testing.T) {
})
}
}

func Test_Reset_ConsumerGroupConsumersWithCustomID(t *testing.T) {
runWhenEnterpriseOrKonnect(t, ">=3.0.0")
setup(t)

client, err := getTestClient()
if err != nil {
t.Fatalf(err.Error())
}

require.NoError(t, sync("testdata/sync/028-consumer-group-consumers-custom_id/kong.yaml"))
reset(t)
testKongState(t, client, false, utils.KongRawState{}, nil)
}
73 changes: 73 additions & 0 deletions tests/integration/sync_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -4714,3 +4714,76 @@ func Test_Sync_DoNotUpdateCreatedAt(t *testing.T) {
// plugins do not have an updated_at field
// consumers do not have an updated_at field
}

// test scope:
// - 3.0.0+
// - konnect
func Test_Sync_ConsumerGroupConsumersWithCustomID(t *testing.T) {
t.Setenv("DECK_KONNECT_CONTROL_PLANE_NAME", "default")
runWhenEnterpriseOrKonnect(t, ">=3.0.0")
setup(t)

client, err := getTestClient()
if err != nil {
t.Fatalf(err.Error())
}

expectedState := utils.KongRawState{
ConsumerGroups: []*kong.ConsumerGroupObject{
{
ConsumerGroup: &kong.ConsumerGroup{
ID: kong.String("48df7cd3-1cd0-4e53-af73-8f57f257be18"),
Name: kong.String("cg1"),
},
Consumers: []*kong.Consumer{
{
ID: kong.String("bcb296c3-22bb-46f6-99c8-4828af750b77"),
CustomID: kong.String("foo"),
},
},
},
{
ConsumerGroup: &kong.ConsumerGroup{
ID: kong.String("1a81dc83-5329-4666-8ae7-8a966e62d076"),
Name: kong.String("cg2"),
},
Consumers: []*kong.Consumer{
{
ID: kong.String("562bf5c7-a7d9-4338-84dd-2c1064fb7f67"),
Username: kong.String("foo"),
},
},
},
{
ConsumerGroup: &kong.ConsumerGroup{
ID: kong.String("d140f9cc-227e-4872-8b0b-639f6922dfb0"),
Name: kong.String("cg3"),
},
Consumers: []*kong.Consumer{
{
ID: kong.String("7906968b-cd89-4a87-8dda-94678e7106b2"),
Username: kong.String("bar"),
CustomID: kong.String("custom_bar"),
},
},
},
},
Consumers: []*kong.Consumer{
{
ID: kong.String("bcb296c3-22bb-46f6-99c8-4828af750b77"),
CustomID: kong.String("foo"),
},
{
ID: kong.String("562bf5c7-a7d9-4338-84dd-2c1064fb7f67"),
Username: kong.String("foo"),
},
{
ID: kong.String("7906968b-cd89-4a87-8dda-94678e7106b2"),
Username: kong.String("bar"),
CustomID: kong.String("custom_bar"),
},
},
}
require.NoError(t, sync("testdata/sync/028-consumer-group-consumers-custom_id/kong.yaml"))
testKongState(t, client, false, expectedState, nil)
}
11 changes: 11 additions & 0 deletions tests/integration/test_utils.go
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,17 @@ func runWhenKongOrKonnect(t *testing.T, kongSemverRange string) {
kong.RunWhenKong(t, kongSemverRange)
}

func runWhenEnterpriseOrKonnect(t *testing.T, kongSemverRange string) {
t.Helper()

if os.Getenv("DECK_KONNECT_EMAIL") != "" &&
os.Getenv("DECK_KONNECT_PASSWORD") != "" &&
os.Getenv("DECK_KONNECT_TOKEN") != "" {
return
}
kong.RunWhenEnterprise(t, kongSemverRange, kong.RequiredFeatures{})
}

func runWhen(t *testing.T, mode string, semverRange string) {
t.Helper()

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
_format_version: "3.0"
_konnect:
control_plane_name: default
consumer_groups:
- id: 48df7cd3-1cd0-4e53-af73-8f57f257be18
name: cg1
- id: 1a81dc83-5329-4666-8ae7-8a966e62d076
name: cg2
- id: d140f9cc-227e-4872-8b0b-639f6922dfb0
name: cg3
consumers:
- custom_id: custom_bar
groups:
- id: d140f9cc-227e-4872-8b0b-639f6922dfb0
name: cg3
id: 7906968b-cd89-4a87-8dda-94678e7106b2
username: bar
- custom_id: foo
groups:
- id: 48df7cd3-1cd0-4e53-af73-8f57f257be18
name: cg1
id: bcb296c3-22bb-46f6-99c8-4828af750b77
- groups:
- id: 1a81dc83-5329-4666-8ae7-8a966e62d076
name: cg2
id: 562bf5c7-a7d9-4338-84dd-2c1064fb7f67
username: foo
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
_format_version: "3.0"
consumer_groups:
- id: 48df7cd3-1cd0-4e53-af73-8f57f257be18
name: cg1
- id: 1a81dc83-5329-4666-8ae7-8a966e62d076
name: cg2
- id: d140f9cc-227e-4872-8b0b-639f6922dfb0
name: cg3
consumers:
- custom_id: custom_bar
groups:
- id: d140f9cc-227e-4872-8b0b-639f6922dfb0
name: cg3
id: 7906968b-cd89-4a87-8dda-94678e7106b2
username: bar
- custom_id: foo
groups:
- id: 48df7cd3-1cd0-4e53-af73-8f57f257be18
name: cg1
id: bcb296c3-22bb-46f6-99c8-4828af750b77
- groups:
- id: 1a81dc83-5329-4666-8ae7-8a966e62d076
name: cg2
id: 562bf5c7-a7d9-4338-84dd-2c1064fb7f67
username: foo

0 comments on commit 7893868

Please sign in to comment.