Browse Source

test: add missing tests for list endpoint (#19364)

pull/19389/head
Poonam Jadhav 1 year ago committed by GitHub
parent
commit
1806bcb38c
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
  1. 41
      agent/grpc-external/services/resource/list_test.go

41
agent/grpc-external/services/resource/list_test.go vendored

@ -6,6 +6,7 @@ package resource
import (
"context"
"fmt"
"strconv"
"strings"
"testing"
@ -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()

Loading…
Cancel
Save