Skip to content

Commit

Permalink
feat(service_test.go): add TestListContentsService to validate conten…
Browse files Browse the repository at this point in the history
…t listing functionality

The addition of `TestListContentsService` in `service_test.go` ensures
that the service can handle listing contents correctly. This test checks
if the service can return a limited number of content items and
validates the content names against a specific pattern.
  • Loading branch information
cybersiddhu committed Aug 15, 2024
1 parent 53a0e9f commit c61f9a5
Showing 1 changed file with 23 additions and 0 deletions.
23 changes: 23 additions & 0 deletions internal/app/service/service_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,10 @@ package service
import (
"context"
"encoding/json"
"fmt"
"net"
"os"
"regexp"
"testing"
"time"

Expand Down Expand Up @@ -283,6 +285,27 @@ func TestDeleteContent(t *testing.T) {
assert.NoError(err, "expect no error from deleting content")
}

func TestListContentsService(t *testing.T) {
t.Parallel()
client, assert := setup(t)

name, namespace := "catalog", "dsc"
storeMultipleContents(client, assert, 10, name, namespace)
resp, err := client.ListContents(
context.Background(),
&content.ListParameters{Limit: 5},
)
assert.NoError(err, "expect no error from listing contents")
assert.Len(resp.Data, 5, "should return 5 contents")
nameRegex := regexp.MustCompile(fmt.Sprintf(`%s-\d+`, name))
validateListContents(validateListContentsParams{
Assert: assert,
Data: resp.Data,
NameRegex: nameRegex,
Namespace: namespace,
})
}

type validateListContentsParams struct {
Assert *require.Assertions
Data []*content.ContentCollection_Data
Expand Down

0 comments on commit c61f9a5

Please sign in to comment.