Skip to content

Commit

Permalink
tests: fix TestFillPluginDefaults test case
Browse files Browse the repository at this point in the history
A new `realm` field was recently added to the basic-auth plugin:

Kong/kong#11795

To address this I added version awareness to the test cases.
  • Loading branch information
flrgh committed Apr 1, 2024
1 parent 4e3dc0f commit dc9c2c1
Show file tree
Hide file tree
Showing 2 changed files with 62 additions and 4 deletions.
64 changes: 61 additions & 3 deletions kong/plugin_service_test.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package kong

import (
"fmt"
"testing"

"github.com/google/go-cmp/cmp"
Expand Down Expand Up @@ -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"),
Expand All @@ -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{
Expand Down Expand Up @@ -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)
Expand Down
2 changes: 1 addition & 1 deletion kong/test_utils.go
Original file line number Diff line number Diff line change
Expand Up @@ -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")
}
}

Expand Down

0 comments on commit dc9c2c1

Please sign in to comment.