Skip to content

Commit

Permalink
chore: added test-case for cg scoped plugins with tags
Browse files Browse the repository at this point in the history
  • Loading branch information
Prashansa-K committed Dec 9, 2024
1 parent 9cb130c commit c6c77ad
Show file tree
Hide file tree
Showing 3 changed files with 117 additions and 0 deletions.
6 changes: 6 additions & 0 deletions pkg/file/kong_json_schema.json
Original file line number Diff line number Diff line change
Expand Up @@ -357,6 +357,12 @@
},
"name": {
"type": "string"
},
"tags": {
"items": {
"type": "string"
},
"type": "array"
}
},
"additionalProperties": false,
Expand Down
92 changes: 92 additions & 0 deletions tests/integration/sync_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down Expand Up @@ -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) {
Expand Down
Original file line number Diff line number Diff line change
@@ -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

0 comments on commit c6c77ad

Please sign in to comment.