From dc9c2c13e233b3fc9133b3fd4f183854429f720f Mon Sep 17 00:00:00 2001 From: Michael Martin Date: Mon, 25 Mar 2024 10:44:37 -0700 Subject: [PATCH] tests: fix TestFillPluginDefaults test case A new `realm` field was recently added to the basic-auth plugin: https://github.com/Kong/kong/pull/11795 To address this I added version awareness to the test cases. --- kong/plugin_service_test.go | 64 +++++++++++++++++++++++++++++++++++-- kong/test_utils.go | 2 +- 2 files changed, 62 insertions(+), 4 deletions(-) diff --git a/kong/plugin_service_test.go b/kong/plugin_service_test.go index 69f42594a..ae1ff3bbf 100644 --- a/kong/plugin_service_test.go +++ b/kong/plugin_service_test.go @@ -1,6 +1,7 @@ package kong import ( + "fmt" "testing" "github.com/google/go-cmp/cmp" @@ -559,9 +560,11 @@ func TestFillPluginDefaults(T *testing.T) { name string plugin *Plugin expected *Plugin + version string }{ { - name: "no config no protocols", + name: "no config no protocols", + version: ">=3.7.0", plugin: &Plugin{ Name: String("basic-auth"), RunOn: String("test"), @@ -572,13 +575,59 @@ func TestFillPluginDefaults(T *testing.T) { Config: Configuration{ "anonymous": nil, "hide_credentials": false, + "realm": "service", }, Protocols: []*string{String("grpc"), String("grpcs"), String("http"), String("https")}, Enabled: Bool(true), }, }, { - name: "partial config no protocols", + name: "no config no protocols", + version: "<3.7.0", + plugin: &Plugin{ + Name: String("basic-auth"), + RunOn: String("test"), + }, + expected: &Plugin{ + Name: String("basic-auth"), + RunOn: String("test"), + Config: Configuration{ + "anonymous": nil, + "hide_credentials": false, + }, + Protocols: []*string{String("grpc"), String("grpcs"), String("http"), String("https")}, + Enabled: Bool(true), + }, + }, + { + name: "partial config no protocols", + version: ">=3.7.0", + plugin: &Plugin{ + Name: String("basic-auth"), + Consumer: &Consumer{ + ID: String("3bb9a73c-a467-11ec-b909-0242ac120002"), + }, + Config: Configuration{ + "hide_credentials": true, + }, + }, + expected: &Plugin{ + Name: String("basic-auth"), + Consumer: &Consumer{ + ID: String("3bb9a73c-a467-11ec-b909-0242ac120002"), + }, + Config: Configuration{ + "anonymous": nil, + "hide_credentials": true, + "realm": "service", + }, + Protocols: []*string{String("grpc"), String("grpcs"), String("http"), String("https")}, + Enabled: Bool(true), + }, + }, + { + name: "partial config no protocols", + version: "<3.7.0", plugin: &Plugin{ Name: String("basic-auth"), Consumer: &Consumer{ @@ -660,7 +709,16 @@ func TestFillPluginDefaults(T *testing.T) { } for _, tc := range tests { - T.Run(tc.name, func(t *testing.T) { + name := tc.name + if tc.version != "" { + name = fmt.Sprintf("%s (kong %s)", name, tc.version) + } + + T.Run(name, func(t *testing.T) { + if tc.version != "" { + RunWhenKong(t, tc.version) + } + p := tc.plugin fullSchema, err := client.Plugins.GetFullSchema(defaultCtx, p.Name) require.NoError(t, err) diff --git a/kong/test_utils.go b/kong/test_utils.go index c3c10a197..e3362a60c 100644 --- a/kong/test_utils.go +++ b/kong/test_utils.go @@ -105,7 +105,7 @@ func SkipWhenEnterprise(t *testing.T) { } if currentVersion.IsKongGatewayEnterprise() { - t.Skip("non-Enterprise test Kong instance, skipping") + t.Skip("Enterprise test Kong instance, skipping") } }