Skip to content

Commit

Permalink
fix: consumer-group scope doesn't work with multiple nesting
Browse files Browse the repository at this point in the history
  • Loading branch information
GGabriele committed Jan 22, 2024
1 parent 22fde79 commit e73912b
Show file tree
Hide file tree
Showing 3 changed files with 57 additions and 17 deletions.
4 changes: 2 additions & 2 deletions pkg/file/writer.go
Original file line number Diff line number Diff line change
Expand Up @@ -319,7 +319,7 @@ func fetchService(id string, kongState *state.KongState, config WriteConfig) (*F
route := &FRoute{Route: r.Route}
for _, p := range plugins {
p := p
if p.Service != nil || p.Consumer != nil {
if p.Service != nil || p.Consumer != nil || p.ConsumerGroup != nil {
continue
}
p.Route = nil
Expand Down Expand Up @@ -588,7 +588,7 @@ func populateConsumers(kongState *state.KongState, file *Content,
}
for _, p := range plugins {
p := p
if p.Service != nil || p.Route != nil {
if p.Service != nil || p.Route != nil || p.ConsumerGroup != nil {
continue
}
utils.ZeroOutID(p, p.Name, config.WithID)
Expand Down
36 changes: 36 additions & 0 deletions tests/integration/sync_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import (
"errors"
"fmt"
"net/http"
"os"
"testing"
"time"

Expand Down Expand Up @@ -4822,6 +4823,22 @@ func Test_Sync_PluginScopedToConsumerGroupAndRoute(t *testing.T) {
Username: kong.String("foo"),
},
},
Services: []*kong.Service{
{
ID: kong.String("1b9d6d8e-9f0f-4a1a-8d5c-9d2a6b2b7f3c"),
Host: kong.String("example.com"),
Name: kong.String("s1"),
ConnectTimeout: kong.Int(60000),
Port: kong.Int(80),
Path: nil,
Protocol: kong.String("http"),
ReadTimeout: kong.Int(60000),
Retries: kong.Int(5),
WriteTimeout: kong.Int(60000),
Tags: nil,
Enabled: kong.Bool(true),
},
},
Routes: []*kong.Route{
{
Name: kong.String("r1"),
Expand All @@ -4835,6 +4852,9 @@ func Test_Sync_PluginScopedToConsumerGroupAndRoute(t *testing.T) {
HTTPSRedirectStatusCode: kong.Int(426),
RequestBuffering: kong.Bool(true),
ResponseBuffering: kong.Bool(true),
Service: &kong.Service{
ID: kong.String("1b9d6d8e-9f0f-4a1a-8d5c-9d2a6b2b7f3c"),
},
},
},
Plugins: []*kong.Plugin{
Expand Down Expand Up @@ -4895,4 +4915,20 @@ func Test_Sync_PluginScopedToConsumerGroupAndRoute(t *testing.T) {
}
require.NoError(t, sync("testdata/sync/029-plugin-scoped-to-cg-route/kong.yaml"))
testKongState(t, client, false, expectedState, nil)

// create a temporary file to dump the state.
cwd, err := os.Getwd()
require.NoError(t, err)
file, err := os.CreateTemp(cwd, "dump.*.yaml")
assert.NoError(t, err)

// dump the state.
_, err = dump("-o", file.Name(), "--yes")
assert.NoError(t, err)

// verify that the dumped state can be sync'd back and that
// the end result is the same.
require.NoError(t, sync(file.Name()))
testKongState(t, client, false, expectedState, nil)

}
Original file line number Diff line number Diff line change
Expand Up @@ -60,18 +60,22 @@ plugins:
- http
- https
route: r1
routes:
- hosts:
- 10.*
https_redirect_status_code: 426
id: a9730e9e-df7e-4042-8bc7-e8b99af70171
name: r1
path_handling: v0
preserve_host: false
protocols:
- http
- https
regex_priority: 0
request_buffering: true
response_buffering: true
strip_path: true
services:
- host: example.com
id: 1b9d6d8e-9f0f-4a1a-8d5c-9d2a6b2b7f3c
name: s1
routes:
- hosts:
- 10.*
https_redirect_status_code: 426
id: a9730e9e-df7e-4042-8bc7-e8b99af70171
name: r1
path_handling: v0
preserve_host: false
protocols:
- http
- https
regex_priority: 0
request_buffering: true
response_buffering: true
strip_path: true

0 comments on commit e73912b

Please sign in to comment.