Skip to content

Commit

Permalink
test: add missing tests for list endpoint
Browse files Browse the repository at this point in the history
  • Loading branch information
JadhavPoonam committed Oct 25, 2023
1 parent 9417fc2 commit dbda29d
Showing 1 changed file with 41 additions and 0 deletions.
41 changes: 41 additions & 0 deletions agent/grpc-external/services/resource/list_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ package resource
import (
"context"
"fmt"
"strconv"
"strings"
"testing"

Expand Down Expand Up @@ -155,6 +156,46 @@ func TestList_Many(t *testing.T) {
}
}

func TestList_NamePrefix(t *testing.T) {
for desc, tc := range listTestCases() {
t.Run(desc, func(t *testing.T) {
server := testServer(t)
demo.RegisterTypes(server.Registry)
client := testClient(t, server)

expectedResources := []*pbresource.Resource{}

namePrefixIndex := 0
// create a name prefix that is always present
namePrefix := fmt.Sprintf("%s-", strconv.Itoa(namePrefixIndex))
for i := 0; i < 10; i++ {
artist, err := demo.GenerateV2Artist()
require.NoError(t, err)

// Prevent test flakes if the generated names collide.
artist.Id.Name = fmt.Sprintf("%d-%s", i, artist.Id.Name)

rsp, err := client.Write(tc.ctx, &pbresource.WriteRequest{Resource: artist})
require.NoError(t, err)

// only matching name prefix are expected
if i == namePrefixIndex {
expectedResources = append(expectedResources, rsp.Resource)
}
}

rsp, err := client.List(tc.ctx, &pbresource.ListRequest{
Type: demo.TypeV2Artist,
Tenancy: resource.DefaultNamespacedTenancy(),
NamePrefix: namePrefix,
})

require.NoError(t, err)
prototest.AssertElementsMatch(t, expectedResources, rsp.Resources)
})
}
}

func TestList_Tenancy_Defaults_And_Normalization(t *testing.T) {
// Test units of tenancy get defaulted correctly when empty.
ctx := context.Background()
Expand Down

0 comments on commit dbda29d

Please sign in to comment.