Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: test fix for Konnect errors #1396

Merged
merged 1 commit into from
Sep 10, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
115 changes: 113 additions & 2 deletions tests/integration/sync_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -327,6 +327,72 @@ var (
},
}

plugin_on_entitiesKonnect = []*kong.Plugin{ //nolint:revive,stylecheck
{
Name: kong.String("prometheus"),
Protocols: []*string{
kong.String("grpc"),
kong.String("grpcs"),
kong.String("http"),
kong.String("https"),
},
Enabled: kong.Bool(true),
Config: kong.Configuration{
"ai_metrics": false,
"bandwidth_metrics": false,
"latency_metrics": false,
"per_consumer": false,
"status_code_metrics": false,
"upstream_health_metrics": false,
},
Service: &kong.Service{
ID: kong.String("58076db2-28b6-423b-ba39-a797193017f7"),
},
},
{
Name: kong.String("prometheus"),
Protocols: []*string{
kong.String("grpc"),
kong.String("grpcs"),
kong.String("http"),
kong.String("https"),
},
Enabled: kong.Bool(true),
Config: kong.Configuration{
"ai_metrics": false,
"bandwidth_metrics": false,
"latency_metrics": false,
"per_consumer": false,
"status_code_metrics": false,
"upstream_health_metrics": false,
},
Route: &kong.Route{
ID: kong.String("87b6a97e-f3f7-4c47-857a-7464cb9e202b"),
},
},
{
Name: kong.String("prometheus"),
Protocols: []*string{
kong.String("grpc"),
kong.String("grpcs"),
kong.String("http"),
kong.String("https"),
},
Enabled: kong.Bool(true),
Config: kong.Configuration{
"ai_metrics": false,
"bandwidth_metrics": false,
"latency_metrics": false,
"per_consumer": false,
"status_code_metrics": false,
"upstream_health_metrics": false,
},
Consumer: &kong.Consumer{
ID: kong.String("d2965b9b-0608-4458-a9f8-0b93d88d03b8"),
},
},
}

upstream_pre31 = []*kong.Upstream{ //nolint:revive,stylecheck
{
Name: kong.String("upstream1"),
Expand Down Expand Up @@ -2677,7 +2743,42 @@ func Test_Sync_PluginsOnEntitiesFrom_3_0_0(t *testing.T) {

for _, tc := range tests {
t.Run(tc.name, func(t *testing.T) {
runWhenKongOrKonnect(t, ">=3.0.0")
runWhen(t, "kong", ">=3.0.0")
setup(t)

sync(tc.kongFile)
testKongState(t, client, false, tc.expectedState, nil)
})
}
}

// test scope:
// - konnect
func Test_Sync_PluginsOnEntities_Konnect(t *testing.T) {
// setup stage
client, err := getTestClient()
require.NoError(t, err)

tests := []struct {
name string
kongFile string
expectedState utils.KongRawState
}{
{
name: "create plugins on services, routes and consumers",
kongFile: "testdata/sync/xxx-plugins-on-entities/kong.yaml",
expectedState: utils.KongRawState{
Services: svc1_207,
Routes: route1_20x,
Plugins: plugin_on_entitiesKonnect,
Consumers: consumer,
},
},
}

for _, tc := range tests {
t.Run(tc.name, func(t *testing.T) {
runWhenKonnect(t)
setup(t)

sync(tc.kongFile)
Expand Down Expand Up @@ -4576,6 +4677,16 @@ func Test_Sync_ConsumerGroupsScopedPluginsKonnect(t *testing.T) {
client, err := getTestClient()
require.NoError(t, err)

ignoreFields := []cmp.Option{
cmp.FilterValues(func(x, y interface{}) bool {
_, okX := x.(map[string]interface{})
_, okY := y.(map[string]interface{})
return okX && okY
}, cmpopts.IgnoreMapEntries(func(key string, _ interface{}) bool {
return key == "redis"
})),
}

tests := []struct {
name string
kongFile string
Expand Down Expand Up @@ -4640,7 +4751,7 @@ func Test_Sync_ConsumerGroupsScopedPluginsKonnect(t *testing.T) {
setup(t)

require.NoError(t, sync(tc.kongFile))
testKongState(t, client, true, tc.expectedState, nil)
testKongState(t, client, true, tc.expectedState, ignoreFields)
})
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,17 +20,21 @@ consumer_groups:
path: null
redis:
cluster_addresses: null
connect_timeout: null
cluster_max_redirections: 5
cluster_nodes: null
connect_timeout: 2000
connection_is_proxied: false
database: 0
host: null
host: 127.0.0.1
keepalive_backlog: null
keepalive_pool_size: 256
password: null
port: null
read_timeout: null
send_timeout: null
port: 6379
read_timeout: 2000
send_timeout: 2000
sentinel_addresses: null
sentinel_master: null
sentinel_nodes: null
sentinel_password: null
sentinel_role: null
sentinel_username: null
Expand Down
Loading