Skip to content

Commit

Permalink
fix(tests) isolate consumer list test
Browse files Browse the repository at this point in the history
Use a dedicated workspace for testing consumer listing, to avoid
interactions with other tests.
  • Loading branch information
rainest committed Mar 22, 2022
1 parent 6dc55a3 commit 9691ad7
Showing 1 changed file with 21 additions and 6 deletions.
27 changes: 21 additions & 6 deletions kong/consumer_service_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -93,6 +93,18 @@ func TestConsumerListEndpoint(T *testing.T) {
assert.Nil(err)
assert.NotNil(client)

workspace := &Workspace{
Name: String("consumer-list-test-workspace"),
}

createdWorkspace, err := client.Workspaces.Create(defaultCtx, workspace)

assert.Nil(err)
assert.NotNil(createdWorkspace)

workspaced, err := NewTestClient(String(defaultBaseURL+"/consumer-list-test-workspace"), nil)
assert.Nil(err)

// fixtures
consumers := []*Consumer{
{
Expand All @@ -108,13 +120,13 @@ func TestConsumerListEndpoint(T *testing.T) {

// create fixturs
for i := 0; i < len(consumers); i++ {
consumer, err := client.Consumers.Create(defaultCtx, consumers[i])
consumer, err := workspaced.Consumers.Create(defaultCtx, consumers[i])
assert.Nil(err)
assert.NotNil(consumer)
consumers[i] = consumer
}

consumersFromKong, next, err := client.Consumers.List(defaultCtx, nil)
consumersFromKong, next, err := workspaced.Consumers.List(defaultCtx, nil)
assert.Nil(err)
assert.Nil(next)
assert.NotNil(consumersFromKong)
Expand All @@ -127,7 +139,7 @@ func TestConsumerListEndpoint(T *testing.T) {
consumersFromKong = []*Consumer{}

// first page
page1, next, err := client.Consumers.List(defaultCtx, &ListOpt{Size: 1})
page1, next, err := workspaced.Consumers.List(defaultCtx, &ListOpt{Size: 1})
assert.Nil(err)
assert.NotNil(next)
assert.NotNil(page1)
Expand All @@ -136,7 +148,7 @@ func TestConsumerListEndpoint(T *testing.T) {

// last page
next.Size = 2
page2, next, err := client.Consumers.List(defaultCtx, next)
page2, next, err := workspaced.Consumers.List(defaultCtx, next)
assert.Nil(err)
assert.Nil(next)
assert.NotNil(page2)
Expand All @@ -145,14 +157,17 @@ func TestConsumerListEndpoint(T *testing.T) {

assert.True(compareConsumers(consumers, consumersFromKong))

consumers, err = client.Consumers.ListAll(defaultCtx)
consumers, err = workspaced.Consumers.ListAll(defaultCtx)
assert.Nil(err)
assert.NotNil(consumers)
assert.Equal(3, len(consumers))

for i := 0; i < len(consumers); i++ {
assert.Nil(client.Consumers.Delete(defaultCtx, consumers[i].ID))
assert.Nil(workspaced.Consumers.Delete(defaultCtx, consumers[i].ID))
}

err = client.Workspaces.Delete(defaultCtx, createdWorkspace.ID)
assert.Nil(err)
}

func TestConsumerListWithTags(T *testing.T) {
Expand Down

0 comments on commit 9691ad7

Please sign in to comment.