Skip to content

Commit

Permalink
Fix test failure with changes in listnamespace API
Browse files Browse the repository at this point in the history
  • Loading branch information
haoming29 committed Jan 8, 2024
1 parent 00e6db3 commit e360785
Show file tree
Hide file tree
Showing 2 changed files with 36 additions and 7 deletions.
22 changes: 18 additions & 4 deletions registry/registry_db_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -144,18 +144,32 @@ func mockNamespace(prefix, pubkey, identity string, adminMetadata AdminMetadata)
// functinos in this package. Please treat them as "constants"
var (
mockNssWithOrigins []Namespace = []Namespace{
mockNamespace("/test1", "pubkey1", "", AdminMetadata{}),
mockNamespace("/test2", "pubkey2", "", AdminMetadata{}),
mockNamespace("/test1", "pubkey1", "", AdminMetadata{Status: Approved}),
mockNamespace("/test2", "pubkey2", "", AdminMetadata{Status: Approved}),
}
mockNssWithCaches []Namespace = []Namespace{
mockNamespace("/caches/random1", "pubkey1", "", AdminMetadata{}),
mockNamespace("/caches/random2", "pubkey2", "", AdminMetadata{}),
mockNamespace("/caches/random1", "pubkey1", "", AdminMetadata{Status: Approved}),
mockNamespace("/caches/random2", "pubkey2", "", AdminMetadata{Status: Approved}),
}
mockNssWithOriginsNotApproved []Namespace = []Namespace{
mockNamespace("/pending1", "pubkey1", "", AdminMetadata{Status: Pending}),
mockNamespace("/pending2", "pubkey2", "", AdminMetadata{Status: Pending}),
}
mockNssWithCachesNotApproved []Namespace = []Namespace{
mockNamespace("/caches/pending1", "pubkey1", "", AdminMetadata{Status: Pending}),
mockNamespace("/caches/pending2", "pubkey2", "", AdminMetadata{Status: Pending}),
}
mockNssWithMixed []Namespace = func() (mixed []Namespace) {
mixed = append(mixed, mockNssWithOrigins...)
mixed = append(mixed, mockNssWithCaches...)
return
}()

mockNssWithMixedNotApproved []Namespace = func() (mixed []Namespace) {
mixed = append(mixed, mockNssWithOriginsNotApproved...)
mixed = append(mixed, mockNssWithCachesNotApproved...)
return
}()
)

func TestGetNamespacesById(t *testing.T) {
Expand Down
21 changes: 18 additions & 3 deletions registry/registry_ui_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -85,6 +85,7 @@ func TestListNamespaces(t *testing.T) {
serverType string
expectedCode int
emptyDB bool
notApproved bool
expectedData []Namespace
}{
{
Expand Down Expand Up @@ -112,6 +113,13 @@ func TestListNamespaces(t *testing.T) {
expectedCode: http.StatusOK,
expectedData: mockNssWithMixed,
},
{
description: "unauthed-not-approved-without-type-returns-empty",
serverType: "",
expectedCode: http.StatusOK,
expectedData: []Namespace{},
notApproved: true,
},
{
description: "invalid-request-parameters",
serverType: "random_type", // some invalid query string
Expand All @@ -123,9 +131,16 @@ func TestListNamespaces(t *testing.T) {
for _, tc := range tests {
t.Run(tc.description, func(t *testing.T) {
if !tc.emptyDB {
err := insertMockDBData(mockNssWithMixed)
if err != nil {
t.Fatalf("Failed to set up mock data: %v", err)
if tc.notApproved {
err := insertMockDBData(mockNssWithMixedNotApproved)
if err != nil {
t.Fatalf("Failed to set up mock data: %v", err)
}
} else {
err := insertMockDBData(mockNssWithMixed)
if err != nil {
t.Fatalf("Failed to set up mock data: %v", err)
}
}
}
defer func() {
Expand Down

0 comments on commit e360785

Please sign in to comment.