Skip to content

Commit b6f3a09

Browse files
chore: bump goapiops version to 0.2.2 (#1846)
* chore: bump goapiops version to 0.2.2 * fix: fix for linting and test issues
1 parent 19a389c commit b6f3a09

File tree

8 files changed

+162
-23
lines changed

8 files changed

+162
-23
lines changed

go.mod

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ require (
1313
github.com/ettle/strcase v0.2.0
1414
github.com/fatih/color v1.18.0
1515
github.com/google/go-cmp v0.7.0
16-
github.com/kong/go-apiops v0.2.1
16+
github.com/kong/go-apiops v0.2.2
1717
github.com/kong/go-database-reconciler v1.31.0
1818
github.com/kong/go-kong v0.71.0
1919
github.com/mitchellh/go-homedir v1.1.0

go.sum

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -242,8 +242,8 @@ github.com/klauspost/cpuid/v2 v2.0.10/go.mod h1:g2LTdtYhdyuGPqyWyv7qRAmj1WBqxuOb
242242
github.com/klauspost/cpuid/v2 v2.0.12/go.mod h1:g2LTdtYhdyuGPqyWyv7qRAmj1WBqxuObKfj5c0PQa7c=
243243
github.com/klauspost/cpuid/v2 v2.2.5 h1:0E5MSMDEoAulmXNFquVs//DdoomxaoTY1kUhbc/qbZg=
244244
github.com/klauspost/cpuid/v2 v2.2.5/go.mod h1:Lcz8mBdAVJIBVzewtcLocK12l3Y+JytZYpaMropDUws=
245-
github.com/kong/go-apiops v0.2.1 h1:6HtyQyOj+CLA86iRtXA6rpTqemp7VqJJ6gpHyNHdB7o=
246-
github.com/kong/go-apiops v0.2.1/go.mod h1:yPwbl3P2eQinVGAEA0d3legaYmzPJ+WtJf9fSeGF4b8=
245+
github.com/kong/go-apiops v0.2.2 h1:Owdcl/PxTdtciqyZKgPScVhTKHgY2b8dGIC1Bms8NpI=
246+
github.com/kong/go-apiops v0.2.2/go.mod h1:yPwbl3P2eQinVGAEA0d3legaYmzPJ+WtJf9fSeGF4b8=
247247
github.com/kong/go-database-reconciler v1.31.0 h1:LITt0L/EhajVaSNDMj/TOxh4Cst7CRhiTykYMMlOoLk=
248248
github.com/kong/go-database-reconciler v1.31.0/go.mod h1:kw4+JGF6iv70LcLBmuY2UuMr8KSdqop77IR86B1mYvU=
249249
github.com/kong/go-kong v0.71.0 h1:unPik6osV1DD3DF+jLs9oMedxWQsnepPYTm1dRQSIa4=

kong2tf/generate_resource.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -141,7 +141,7 @@ func generateRelationship(
141141
s := fmt.Sprintf(`resource "konnect_%s" "%s" {`, entityType, name)
142142

143143
// Extract keys to iterate in a deterministic order
144-
keys := make([]string, 0)
144+
keys := make([]string, 0, len(relations))
145145
for k := range relations {
146146
keys = append(keys, k)
147147
}

tests/integration/dump_test.go

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -301,7 +301,8 @@ func Test_Dump_KonnectRename(t *testing.T) {
301301
output string
302302
err error
303303
)
304-
flags := []string{"-o", "-", "--with-id"}
304+
flags := make([]string, 0, 3+len(tc.flags))
305+
flags = append(flags, "-o", "-", "--with-id")
305306
flags = append(flags, tc.flags...)
306307
output, err = dump(flags...)
307308

tests/integration/render_test.go

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -51,9 +51,8 @@ func Test_RenderPlain(t *testing.T) {
5151
}
5252
for _, tc := range tests {
5353
t.Run(tc.name, func(t *testing.T) {
54-
renderOpts := []string{
55-
tc.stateFile,
56-
}
54+
renderOpts := make([]string, 0, 1+len(tc.additionalArgs))
55+
renderOpts = append(renderOpts, tc.stateFile)
5756
renderOpts = append(renderOpts, tc.additionalArgs...)
5857

5958
for k, v := range tc.envVars {

tests/integration/sync_test.go

Lines changed: 143 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8540,7 +8540,146 @@ func Test_Sync_SkipConsumersWithConsumerGroups_Konnect(t *testing.T) {
85408540
}
85418541

85428542
func Test_Sync_Partials_Plugins(t *testing.T) {
8543-
runWhenEnterpriseOrKonnect(t, ">=3.10.0")
8543+
runWhen(t, "enterprise", ">=3.10.0")
8544+
8545+
client, err := getTestClient()
8546+
require.NoError(t, err)
8547+
8548+
ctx := context.Background()
8549+
8550+
dumpConfig := deckDump.Config{}
8551+
8552+
partialConfig := kong.Configuration{
8553+
"cluster_max_redirections": float64(5),
8554+
"cluster_nodes": nil,
8555+
"connect_timeout": float64(2000),
8556+
"connection_is_proxied": bool(false),
8557+
"database": float64(0),
8558+
"host": string("127.0.0.1"),
8559+
"keepalive_backlog": nil,
8560+
"keepalive_pool_size": float64(256),
8561+
"password": nil,
8562+
"port": float64(6379),
8563+
"read_timeout": float64(3001),
8564+
"send_timeout": float64(2004),
8565+
"sentinel_master": nil,
8566+
"sentinel_nodes": nil,
8567+
"sentinel_password": nil,
8568+
"sentinel_role": nil,
8569+
"sentinel_username": nil,
8570+
"server_name": nil,
8571+
"ssl": bool(false),
8572+
"ssl_verify": bool(false),
8573+
"username": nil,
8574+
}
8575+
8576+
t.Run("create a partial and link to a plugin via name", func(t *testing.T) {
8577+
require.NoError(t, sync(ctx, "testdata/sync/039-partials/kong.yaml"))
8578+
t.Cleanup(func() {
8579+
reset(t)
8580+
})
8581+
8582+
newState, err := fetchCurrentState(ctx, client, dumpConfig, t)
8583+
require.NoError(t, err)
8584+
8585+
// check for partial
8586+
partials, err := newState.Partials.GetAll()
8587+
require.NoError(t, err)
8588+
require.NotNil(t, partials)
8589+
8590+
require.Len(t, partials, 1)
8591+
assert.Equal(t, "my-ee-partial", *partials[0].Name)
8592+
assert.Equal(t, "redis-ee", *partials[0].Type)
8593+
assert.IsType(t, kong.Configuration{}, partials[0].Config)
8594+
assert.Equal(t, partialConfig, partials[0].Config)
8595+
8596+
// check for plugin
8597+
plugins, err := newState.Plugins.GetAll()
8598+
require.NoError(t, err)
8599+
require.NotNil(t, plugins)
8600+
require.Len(t, plugins, 1)
8601+
assert.Equal(t, "rate-limiting-advanced", *plugins[0].Name)
8602+
assert.IsType(t, []*kong.PartialLink{}, plugins[0].Partials)
8603+
require.Len(t, plugins[0].Partials, 1)
8604+
assert.Equal(t, *partials[0].ID, *plugins[0].Partials[0].ID)
8605+
assert.Equal(t, "config.redis", *plugins[0].Partials[0].Path)
8606+
})
8607+
8608+
t.Run("partial id is preserved if passed and linking can be done via id", func(t *testing.T) {
8609+
require.NoError(t, sync(ctx, "testdata/sync/039-partials/kong-ids.yaml"))
8610+
t.Cleanup(func() {
8611+
reset(t)
8612+
})
8613+
8614+
newState, err := fetchCurrentState(ctx, client, dumpConfig, t)
8615+
require.NoError(t, err)
8616+
8617+
// check for partial
8618+
partials, err := newState.Partials.GetAll()
8619+
require.NoError(t, err)
8620+
require.NotNil(t, partials)
8621+
8622+
require.Len(t, partials, 1)
8623+
assert.Equal(t, "13dc230d-d65e-439a-9f05-9fd71abfee4d", *partials[0].ID)
8624+
assert.Equal(t, "my-ee-partial", *partials[0].Name)
8625+
assert.Equal(t, "redis-ee", *partials[0].Type)
8626+
assert.IsType(t, kong.Configuration{}, partials[0].Config)
8627+
assert.Equal(t, partialConfig, partials[0].Config)
8628+
8629+
// check for plugin
8630+
plugins, err := newState.Plugins.GetAll()
8631+
require.NoError(t, err)
8632+
require.NotNil(t, plugins)
8633+
require.Len(t, plugins, 1)
8634+
assert.Equal(t, "rate-limiting-advanced", *plugins[0].Name)
8635+
assert.IsType(t, []*kong.PartialLink{}, plugins[0].Partials)
8636+
require.Len(t, plugins[0].Partials, 1)
8637+
assert.Equal(t, "13dc230d-d65e-439a-9f05-9fd71abfee4d", *plugins[0].Partials[0].ID)
8638+
assert.Equal(t, "config.redis", *plugins[0].Partials[0].Path)
8639+
})
8640+
8641+
t.Run("linking to a plugin fails in case of non-existent partial", func(t *testing.T) {
8642+
err := sync(ctx, "testdata/sync/039-partials/kong-wrong.yaml")
8643+
require.Error(t, err)
8644+
assert.ErrorContains(t, err, "partial non-existent-partial for plugin rate-limiting-advanced: entity not found")
8645+
})
8646+
8647+
t.Run("partial linking with a consumer-group scoped plugin works fine", func(t *testing.T) {
8648+
require.NoError(t, sync(ctx, "testdata/sync/039-partials/cg-plugin-partial.yaml"))
8649+
t.Cleanup(func() {
8650+
reset(t)
8651+
})
8652+
8653+
newState, err := fetchCurrentState(ctx, client, dumpConfig, t)
8654+
require.NoError(t, err)
8655+
8656+
// check for partial
8657+
partials, err := newState.Partials.GetAll()
8658+
require.NoError(t, err)
8659+
require.NotNil(t, partials)
8660+
8661+
require.Len(t, partials, 1)
8662+
assert.Equal(t, "my-redis-ee", *partials[0].Name)
8663+
assert.Equal(t, "redis-ee", *partials[0].Type)
8664+
8665+
// check for plugin
8666+
plugins, err := newState.Plugins.GetAll()
8667+
require.NoError(t, err)
8668+
require.NotNil(t, plugins)
8669+
require.Len(t, plugins, 1)
8670+
assert.Equal(t, "rate-limiting-advanced", *plugins[0].Name)
8671+
assert.IsType(t, []*kong.PartialLink{}, plugins[0].Partials)
8672+
require.Len(t, plugins[0].Partials, 1)
8673+
assert.Equal(t, *partials[0].ID, *plugins[0].Partials[0].ID)
8674+
assert.Equal(t, "config.redis", *plugins[0].Partials[0].Path)
8675+
assert.Equal(t, "foo", *plugins[0].ConsumerGroup.Name)
8676+
})
8677+
}
8678+
8679+
func Test_Sync_Partials_Plugins_Konnect(t *testing.T) {
8680+
runWhenKonnect(t)
8681+
setDefaultKonnectControlPlane(t)
8682+
setup(t)
85448683

85458684
client, err := getTestClient()
85468685
require.NoError(t, err)
@@ -8550,6 +8689,7 @@ func Test_Sync_Partials_Plugins(t *testing.T) {
85508689
dumpConfig := deckDump.Config{}
85518690

85528691
partialConfig := kong.Configuration{
8692+
"cloud_authentication": nil,
85538693
"cluster_max_redirections": float64(5),
85548694
"cluster_nodes": nil,
85558695
"connect_timeout": float64(2000),
@@ -10063,6 +10203,7 @@ func Test_Sync_Partials_Tagging_Konnect(t *testing.T) {
1006310203
Name: kong.String("redis-ee-common"),
1006410204
Type: kong.String("redis-ee"),
1006510205
Config: kong.Configuration{
10206+
"cloud_authentication": nil,
1006610207
"cluster_max_redirections": float64(5),
1006710208
"cluster_nodes": nil,
1006810209
"connect_timeout": float64(2000),
@@ -10092,6 +10233,7 @@ func Test_Sync_Partials_Tagging_Konnect(t *testing.T) {
1009210233
Name: kong.String("redis-ee-sentinel"),
1009310234
Type: kong.String("redis-ee"),
1009410235
Config: kong.Configuration{
10236+
"cloud_authentication": nil,
1009510237
"cluster_max_redirections": float64(5),
1009610238
"cluster_nodes": nil,
1009710239
"connect_timeout": float64(2000),

tests/integration/test_utils.go

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -242,7 +242,8 @@ func testKongState(t *testing.T, client *kong.Client, isKonnect bool,
242242
kongState, err := deckDump.Get(ctx, client, dumpConfig)
243243
require.NoError(t, err)
244244

245-
opt := []cmp.Option{
245+
opt := make([]cmp.Option, 0, 22+len(ignoreFields))
246+
opt = append(opt,
246247
cmpopts.IgnoreFields(kong.Service{}, "CreatedAt", "UpdatedAt"),
247248
cmpopts.IgnoreFields(kong.Route{}, "CreatedAt", "UpdatedAt"),
248249
cmpopts.IgnoreFields(kong.Plugin{}, "ID", "CreatedAt"),
@@ -265,7 +266,7 @@ func testKongState(t *testing.T, client *kong.Client, isKonnect bool,
265266
cmpopts.SortSlices(sortSlices),
266267
cmpopts.SortSlices(func(a, b *string) bool { return *a < *b }),
267268
cmpopts.EquateEmpty(),
268-
}
269+
)
269270
opt = append(opt, ignoreFields...)
270271

271272
if diff := cmp.Diff(kongState, &expectedState, opt...); diff != "" {

tests/integration/validate_test.go

Lines changed: 8 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -155,9 +155,8 @@ func Test_Validate_File(t *testing.T) {
155155

156156
for _, tc := range tests {
157157
t.Run(tc.name, func(t *testing.T) {
158-
validateOpts := []string{
159-
tc.stateFile,
160-
}
158+
validateOpts := make([]string, 0, 1+len(tc.additionalArgs))
159+
validateOpts = append(validateOpts, tc.stateFile)
161160
validateOpts = append(validateOpts, tc.additionalArgs...)
162161

163162
err := validate(OFFLINE, validateOpts...)
@@ -205,9 +204,8 @@ func Test_Validate_Gateway(t *testing.T) {
205204

206205
for _, tc := range tests {
207206
t.Run(tc.name, func(t *testing.T) {
208-
validateOpts := []string{
209-
tc.stateFile,
210-
}
207+
validateOpts := make([]string, 0, 1+len(tc.additionalArgs))
208+
validateOpts = append(validateOpts, tc.stateFile)
211209
validateOpts = append(validateOpts, tc.additionalArgs...)
212210

213211
err := validate(ONLINE, validateOpts...)
@@ -284,9 +282,8 @@ func Test_Validate_Gateway_EE(t *testing.T) {
284282
require.NoError(t, sync(ctx, tc.priorStateFile))
285283
}
286284

287-
validateOpts := []string{
288-
tc.stateFile,
289-
}
285+
validateOpts := make([]string, 0, 1+len(tc.additionalArgs))
286+
validateOpts = append(validateOpts, tc.stateFile)
290287
validateOpts = append(validateOpts, tc.additionalArgs...)
291288

292289
err := validate(ONLINE, validateOpts...)
@@ -353,9 +350,8 @@ func Test_Validate_PartialLookupTags(t *testing.T) {
353350
t.Run(tc.name, func(t *testing.T) {
354351
require.NoError(t, sync(ctx, "testdata/validate/001-partials/partials.yaml"))
355352

356-
validateOpts := []string{
357-
tc.stateFile,
358-
}
353+
validateOpts := make([]string, 0, 1+len(tc.additionalArgs))
354+
validateOpts = append(validateOpts, tc.stateFile)
359355
validateOpts = append(validateOpts, tc.additionalArgs...)
360356

361357
err := validate(tc.mode, validateOpts...)

0 commit comments

Comments
 (0)