Skip to content

Commit

Permalink
tests
Browse files Browse the repository at this point in the history
  • Loading branch information
GGabriele committed Nov 9, 2023
1 parent 55c403f commit e66a3fa
Show file tree
Hide file tree
Showing 5 changed files with 89 additions and 1 deletion.
40 changes: 39 additions & 1 deletion tests/integration/sync_test.go
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
//go:build integration
//gos:build integration

package integration

Expand Down Expand Up @@ -4814,3 +4814,41 @@ func Test_Sync_DoNotUpdateCreatedAt(t *testing.T) {
// plugins do not have an updated_at field
// consumers do not have an updated_at field
}

// Test_Sync_LookupConsumerTags tests that existing behavior when referencing
// consumers from plugins is preserved:
// - if a referenced consumer is not present in the state file, the sync fails
// - if a referenced consumer is present in the state file, the sync succeeds
//
// This test also tests that the new behavior is implemented correctly:
// - if a referenced consumer is not present in the state file, but is present
// in Kong when using the new lookup selector tags, the sync succeeds
// - if a referenced consumer is not present in the state file and neither in
// Kong when using the new lookup selector tags, the sync fails
func Test_Sync_LookupConsumerTags(t *testing.T) {
runWhen(t, "enterprise", ">=3.0.0")
setup(t)

// test that reference to non-existing consumer fails.
pluginsNoLookupStateFile := "testdata/sync/028-lookup-tags/plugins_no_lookup.yaml"
err := sync(pluginsNoLookupStateFile)
require.Error(t, err)
require.EqualError(t, err, "building state: consumer foo for plugin rate-limiting-advanced: entity not found")

// test that reference to existing local consumer succeeds.
pluginsAndConsumersStateFile := "testdata/sync/028-lookup-tags/plugins_and_consumers.yaml"
require.NoError(t, sync(pluginsAndConsumersStateFile))
reset(t)

// test that reference to existing global consumer succeeds via lookup tags.
globalConsumersStateFile := "testdata/sync/028-lookup-tags/global_consumers.yaml"
require.NoError(t, sync(globalConsumersStateFile))
// sync plugins with lookup reference to global consumers.
pluginsLookupStateFile := "testdata/sync/028-lookup-tags/plugins_lookup.yaml"
require.NoError(t, sync(pluginsLookupStateFile))
reset(t)

// test that reference to non-existing global consumer fails via lookup tags.
require.Error(t, sync(pluginsLookupStateFile))
require.EqualError(t, err, "building state: consumer foo for plugin rate-limiting-advanced: entity not found")
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
_format_version: "3.0"
_info:
select_tags:
- global-consumers
consumers:
- username: foo
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
_format_version: "3.0"
plugins:
- name: rate-limiting-advanced
config:
limit:
- 10
window_size:
- 60
namespace: foo
sync_rate: -1
consumer: foo
consumers:
- username: foo
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
_format_version: "3.0"
_info:
select_tags:
- managed-by-deck
lookup_tags:
consumers:
- global-consumers
plugins:
- name: rate-limiting-advanced
config:
limit:
- 10
window_size:
- 60
namespace: foo
sync_rate: -1
consumer: foo
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
_format_version: "3.0"
_info:
select_tags:
- managed-by-deck
plugins:
- name: rate-limiting-advanced
config:
limit:
- 10
window_size:
- 60
namespace: foo
sync_rate: -1
consumer: foo

0 comments on commit e66a3fa

Please sign in to comment.