Skip to content

Commit

Permalink
tests: fix Test_Sync_ConsumerGroupsScopedPlugins_After360 integration…
Browse files Browse the repository at this point in the history
… test (#1305)

* tests: fix Test_Sync_ConsumerGroupsScopedPlugins_After360 integration test

* tests: use 3.7 schema in Test_Sync_ConsumerGroupsScopedPluginsKonnect
  • Loading branch information
pmalek authored May 27, 2024
1 parent d8c8465 commit 0247b44
Show file tree
Hide file tree
Showing 4 changed files with 233 additions and 14 deletions.
2 changes: 1 addition & 1 deletion .ci/setup_kong.sh
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

set -e

KONG_IMAGE=${KONG_IMAGE}
KONG_IMAGE=${KONG_IMAGE:-kong}
NETWORK_NAME=deck-test

PG_CONTAINER_NAME=pg
Expand Down
2 changes: 1 addition & 1 deletion .ci/setup_kong_ee.sh
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ KlBs7O9y+fc4AIIn6JD+9tymB1TWEn1B+3Vv6jmtzbztuCQTbJ6rTT3CFcE6TdyJ
8rYuG3/p2VkcG29TWbQARtj5ewv9p5QNfaecUzN+tps89YzawWQBanwI
-----END RSA PRIVATE KEY-----'''

KONG_IMAGE=${KONG_IMAGE}
KONG_IMAGE=${KONG_IMAGE:-kong/kong-gateway}
NETWORK_NAME=deck-test

PG_CONTAINER_NAME=pg
Expand Down
239 changes: 227 additions & 12 deletions tests/integration/sync_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -1089,7 +1089,168 @@ var (
"key_in_header": true,
"key_in_query": true,
"key_names": []interface{}{"apikey"},
"realm": nil,
"run_on_preflight": true,
},
Enabled: kong.Bool(true),
Protocols: []*string{kong.String("http"), kong.String("https")},
},
}

consumerGroupScopedPlugins37x = []*kong.Plugin{
{
Name: kong.String("rate-limiting-advanced"),
ConsumerGroup: &kong.ConsumerGroup{
ID: kong.String("77e6691d-67c0-446a-9401-27be2b141aae"),
},
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"),
},
Enabled: kong.Bool(true),
Protocols: []*string{kong.String("grpc"), kong.String("grpcs"), kong.String("http"), kong.String("https")},
},
{
Name: kong.String("rate-limiting-advanced"),
ConsumerGroup: &kong.ConsumerGroup{
ID: kong.String("5bcbd3a7-030b-4310-bd1d-2721ff85d236"),
},
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(7)},
"namespace": string("silver"),
"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"),
},
Enabled: kong.Bool(true),
Protocols: []*string{kong.String("grpc"), kong.String("grpcs"), kong.String("http"), kong.String("https")},
},
{
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(5)},
"namespace": string("silver"),
"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"),
},
Enabled: kong.Bool(true),
Protocols: []*string{kong.String("grpc"), kong.String("grpcs"), kong.String("http"), kong.String("https")},
},
{
Name: kong.String("key-auth"),
Config: kong.Configuration{
"anonymous": nil,
"hide_credentials": false,
"key_in_body": false,
"key_in_header": true,
"key_in_query": true,
"key_names": []interface{}{"apikey"},
"realm": nil, // This is present on 3.7.x+
"run_on_preflight": true,
},
Enabled: kong.Bool(true),
Expand Down Expand Up @@ -4306,16 +4467,17 @@ func Test_Sync_ConsumerGroupsScopedPlugins_After360(t *testing.T) {
maxRegularRequestsNumber = 5
)
client, err := getTestClient()
if err != nil {
t.Fatalf(err.Error())
}
require.NoError(t, err)

tests := []struct {
name string
runWhen string
kongFile string
expectedState utils.KongRawState
}{
{
name: "creates consumer groups scoped plugins",
runWhen: ">=3.6.0 <3.7.0",
kongFile: "testdata/sync/025-consumer-groups-scoped-plugins/kong3x.yaml",
expectedState: utils.KongRawState{
Consumers: consumerGroupsConsumers,
Expand Down Expand Up @@ -4366,10 +4528,64 @@ func Test_Sync_ConsumerGroupsScopedPlugins_After360(t *testing.T) {
},
},
},
{
name: "creates consumer groups scoped plugins",
runWhen: ">=3.7.0",
kongFile: "testdata/sync/025-consumer-groups-scoped-plugins/kong3x.yaml",
expectedState: utils.KongRawState{
Consumers: consumerGroupsConsumers,
ConsumerGroups: []*kong.ConsumerGroupObject{
{
ConsumerGroup: &kong.ConsumerGroup{
Name: kong.String("silver"),
},
Consumers: []*kong.Consumer{
{
Username: kong.String("bar"),
},
},
},
{
ConsumerGroup: &kong.ConsumerGroup{
Name: kong.String("gold"),
},
Consumers: []*kong.Consumer{
{
Username: kong.String("foo"),
},
},
},
},
Plugins: consumerGroupScopedPlugins37x,
Services: svc1_207,
Routes: route1_20x,
KeyAuths: []*kong.KeyAuth{
{
Consumer: &kong.Consumer{
ID: kong.String("87095815-5395-454e-8c18-a11c9bc0ef04"),
},
Key: kong.String("i-am-special"),
},
{
Consumer: &kong.Consumer{
ID: kong.String("5a5b9369-baeb-4faa-a902-c40ccdc2928e"),
},
Key: kong.String("i-am-not-so-special"),
},
{
Consumer: &kong.Consumer{
ID: kong.String("e894ea9e-ad08-4acf-a960-5a23aa7701c7"),
},
Key: kong.String("i-am-just-average"),
},
},
},
},
}
for _, tc := range tests {
t.Run(tc.name, func(t *testing.T) {
runWhen(t, "enterprise", ">=3.6.0")
t.Run(tc.name+"/"+tc.runWhen, func(t *testing.T) {
runWhen(t, "enterprise", tc.runWhen)

setup(t)

sync(tc.kongFile)
Expand Down Expand Up @@ -4467,9 +4683,8 @@ func Test_Sync_ConsumerGroupsScopedPlugins_Post340(t *testing.T) {

func Test_Sync_ConsumerGroupsScopedPluginsKonnect(t *testing.T) {
client, err := getTestClient()
if err != nil {
t.Fatalf(err.Error())
}
require.NoError(t, err)

tests := []struct {
name string
kongFile string
Expand Down Expand Up @@ -4502,7 +4717,7 @@ func Test_Sync_ConsumerGroupsScopedPluginsKonnect(t *testing.T) {
},
},
},
Plugins: consumerGroupScopedPlugins36x,
Plugins: consumerGroupScopedPlugins37x,
Services: svc1_207,
Routes: route1_20x,
KeyAuths: []*kong.KeyAuth{
Expand Down Expand Up @@ -4533,8 +4748,8 @@ func Test_Sync_ConsumerGroupsScopedPluginsKonnect(t *testing.T) {
runWhenKonnect(t)
setup(t)

sync(tc.kongFile)
testKongState(t, client, false, tc.expectedState, nil)
require.NoError(t, sync(tc.kongFile))
testKongState(t, client, true, tc.expectedState, nil)
})
}
}
Expand Down
4 changes: 4 additions & 0 deletions tests/integration/test_utils.go
Original file line number Diff line number Diff line change
Expand Up @@ -186,6 +186,8 @@ func sortSlices(x, y interface{}) bool {
func testKongState(t *testing.T, client *kong.Client, isKonnect bool,
expectedState utils.KongRawState, ignoreFields []cmp.Option,
) {
t.Helper()

// Get entities from Kong
ctx := context.Background()
dumpConfig := deckDump.Config{}
Expand Down Expand Up @@ -236,6 +238,8 @@ func testKongState(t *testing.T, client *kong.Client, isKonnect bool,
}

func reset(t *testing.T, opts ...string) {
t.Helper()

deckCmd := cmd.NewRootCmd()
args := []string{"reset", "--force"}
if len(opts) > 0 {
Expand Down

0 comments on commit 0247b44

Please sign in to comment.