From c6c77ad2adbaebee6706ce78d764a7032bfbd257 Mon Sep 17 00:00:00 2001 From: Prashansa Kulshrestha Date: Mon, 9 Dec 2024 12:34:58 +0530 Subject: [PATCH] chore: added test-case for cg scoped plugins with tags --- pkg/file/kong_json_schema.json | 6 ++ tests/integration/sync_test.go | 92 +++++++++++++++++++ .../kong-cg-plugin.yaml | 19 ++++ 3 files changed, 117 insertions(+) create mode 100644 tests/integration/testdata/sync/xxx-plugins-on-entities/kong-cg-plugin.yaml diff --git a/pkg/file/kong_json_schema.json b/pkg/file/kong_json_schema.json index 5063371..28f4ef6 100644 --- a/pkg/file/kong_json_schema.json +++ b/pkg/file/kong_json_schema.json @@ -357,6 +357,12 @@ }, "name": { "type": "string" + }, + "tags": { + "items": { + "type": "string" + }, + "type": "array" } }, "additionalProperties": false, diff --git a/tests/integration/sync_test.go b/tests/integration/sync_test.go index 031faca..3ea8986 100644 --- a/tests/integration/sync_test.go +++ b/tests/integration/sync_test.go @@ -1267,6 +1267,57 @@ var ( Protocols: []*string{kong.String("http"), kong.String("https")}, }, } + + consumerGroupScopedPluginWithTags = []*kong.Plugin{{ + Name: kong.String("rate-limiting-advanced"), + Config: kong.Configuration{ + "consumer_groups": nil, + "dictionary_name": string("kong_rate_limiting_counters"), + "disable_penalty": bool(false), + "enforce_consumer_groups": bool(false), + "error_code": float64(429), + "error_message": string("API rate limit exceeded"), + "header_name": nil, + "hide_client_headers": bool(false), + "identifier": string("consumer"), + "limit": []any{float64(10)}, + "namespace": string("gold"), + "path": nil, + "redis": map[string]any{ + "cluster_addresses": nil, + "connect_timeout": nil, + "database": float64(0), + "host": nil, + "keepalive_backlog": nil, + "keepalive_pool_size": float64(256), + "password": nil, + "port": nil, + "read_timeout": nil, + "send_timeout": nil, + "sentinel_addresses": nil, + "sentinel_master": nil, + "sentinel_password": nil, + "sentinel_role": nil, + "sentinel_username": nil, + "server_name": nil, + "ssl": false, + "ssl_verify": false, + "timeout": float64(2000), + "username": nil, + }, + "retry_after_jitter_max": float64(1), + "strategy": string("local"), + "sync_rate": float64(-1), + "window_size": []any{float64(60)}, + "window_type": string("sliding"), + }, + ConsumerGroup: &kong.ConsumerGroup{ + ID: kong.String("58076db2-28b6-423b-ba39-a79719301700"), + }, + Tags: kong.StringSlice("tag1", "tag2"), + Enabled: kong.Bool(true), + Protocols: []*string{kong.String("grpc"), kong.String("grpcs"), kong.String("http"), kong.String("https")}, + }} ) // test scope: @@ -2800,6 +2851,47 @@ func Test_Sync_PluginsOnEntitiesFrom_3_0_0(t *testing.T) { } } +// test scope: +// - 3.4.0+ +func Test_Sync_PluginsOnConsumerGroupsFrom_3_4_0(t *testing.T) { + // setup stage + client, err := getTestClient() + if err != nil { + t.Fatalf(err.Error()) + } + + tests := []struct { + name string + kongFile string + expectedState utils.KongRawState + }{ + { + name: "create plugins on consumer-groups", + kongFile: "testdata/sync/xxx-plugins-on-entities/kong-cg-plugin.yaml", + expectedState: utils.KongRawState{ + ConsumerGroups: []*kong.ConsumerGroupObject{ + { + ConsumerGroup: &kong.ConsumerGroup{ + Name: kong.String("foo"), + }, + }, + }, + Plugins: consumerGroupScopedPluginWithTags, + }, + }, + } + + for _, tc := range tests { + t.Run(tc.name, func(t *testing.T) { + runWhenKongOrKonnect(t, ">=3.4.0") + setup(t) + + sync(tc.kongFile) + testKongState(t, client, false, tc.expectedState, nil) + }) + } +} + // test scope: // - 3.0.0+ func Test_Sync_PluginOrdering(t *testing.T) { diff --git a/tests/integration/testdata/sync/xxx-plugins-on-entities/kong-cg-plugin.yaml b/tests/integration/testdata/sync/xxx-plugins-on-entities/kong-cg-plugin.yaml new file mode 100644 index 0000000..5788718 --- /dev/null +++ b/tests/integration/testdata/sync/xxx-plugins-on-entities/kong-cg-plugin.yaml @@ -0,0 +1,19 @@ +_format_version: "3.0" + +consumer_groups: +- id: 58076db2-28b6-423b-ba39-a79719301700 + name: foo + plugins: + - name: rate-limiting-advanced + tags: + - tag1 + - tag2 + config: + namespace: silver + limit: + - 7 + retry_after_jitter_max: 1 + window_size: + - 60 + window_type: sliding + sync_rate: -1 \ No newline at end of file