Skip to content

Commit

Permalink
fix: plugin shown as global despite a consumer-group present
Browse files Browse the repository at this point in the history
Prior to this fix, deck was reporting the plugins as global
even if a consumer-group was attached to them. This was only
a output problem, not a association problem. The fix
checks if a consumer-group exists or not before reporting
any plugin as global.

Fixes: Kong/deck#1005
  • Loading branch information
Prashansa-K committed Aug 26, 2024
1 parent 6d1bb06 commit d039ac9
Show file tree
Hide file tree
Showing 2 changed files with 47 additions and 1 deletion.
2 changes: 1 addition & 1 deletion pkg/state/types.go
Original file line number Diff line number Diff line change
Expand Up @@ -526,7 +526,7 @@ func (p1 *Plugin) Identifier() string {
func (p1 *Plugin) Console() string {
res := *p1.Name + " "

if p1.Service == nil && p1.Route == nil && p1.Consumer == nil {
if p1.Service == nil && p1.Route == nil && p1.Consumer == nil && p1.ConsumerGroup == nil {
return res + "(global)"
}
associations := []string{}
Expand Down
46 changes: 46 additions & 0 deletions pkg/state/types_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -663,3 +663,49 @@ func TestDeepEqualWithSorting(t *testing.T) {
t.Errorf("expected maps to be equal, but they are not")
}
}

func TestConsole(t *testing.T) {
assert := assert.New(t)

var p1 Plugin
p1.ID = kong.String("foo")
p1.Name = kong.String("foo-plugin")

// Testing for global
expected := "foo-plugin (global)"
actual := p1.Console()
assert.Equal(expected, actual)

// Adding a service
p1.Service = &kong.Service{ID: kong.String("bar")}
expected = "foo-plugin for service bar"
actual = p1.Console()
assert.Equal(expected, actual)

// Adding a route with service
p1.Route = &kong.Route{ID: kong.String("baz")}
expected = "foo-plugin for service bar and route baz"
actual = p1.Console()
assert.Equal(expected, actual)

// Adding a consumer with service and route
p1.Consumer = &kong.Consumer{ID: kong.String("demo")}
expected = "foo-plugin for service bar and route baz and consumer demo"
actual = p1.Console()
assert.Equal(expected, actual)

// Adding a consumer-group with service, route and consumer
p1.ConsumerGroup = &kong.ConsumerGroup{ID: kong.String("demo-group")}
expected = "foo-plugin for service bar and route baz and consumer demo and consumer-group demo-group"
actual = p1.Console()
assert.Equal(expected, actual)

// Making everything nil
p1.Service = nil
p1.Route = nil
p1.Consumer = nil
p1.ConsumerGroup = nil
expected = "foo-plugin (global)"
actual = p1.Console()
assert.Equal(expected, actual)
}

0 comments on commit d039ac9

Please sign in to comment.