Skip to content

Commit

Permalink
dist: add tests for listing repos, tags
Browse files Browse the repository at this point in the history
Added tests for listing existing repos and tags of a given manifest.

Signed-off-by: Dongsu Park <dongsu@kinvolk.io>
  • Loading branch information
Dongsu Park committed Dec 21, 2018
1 parent 1a54c8c commit b1de6b8
Showing 1 changed file with 48 additions and 0 deletions.
48 changes: 48 additions & 0 deletions test/dist/dist_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -268,3 +268,51 @@ func TestPushPullLayer(t *testing.T) {
testDeleteLayer(t)
testDeleteManifest(t)
}

func TestListRepos(t *testing.T) {
reqPath := "_catalog"

regAuthCtx := auth.NewRegAuthContext()
regURL := regAuthCtx.RegURL

regAuthCtx.Scope.RemoteName = reqPath
regAuthCtx.Scope.Actions = "pull"

indexServer := auth.GetIndexServer(regURL)

// NOTE: it will fail when testing against docker.io, as '/v2/_catalog' endpoint
// will not be supported.
if err := regAuthCtx.PrepareAuth(indexServer); err != nil {
t.Fatalf("failed to prepare auth to %s for %s: %v", indexServer, reqPath, err)
}

inputURL := "https://" + indexServer + "/v2/" + reqPath

_, err := regAuthCtx.GetResponse(inputURL, "GET", nil, []int{http.StatusOK})
if err != nil {
t.Fatalf("got an unexpected reply: %v", err)
}
}

func TestListTags(t *testing.T) {
regAuthCtx := auth.NewRegAuthContext()
regURL := regAuthCtx.RegURL

indexServer := auth.GetIndexServer(regURL)

remoteName := filepath.Join(auth.DefaultRepoPrefix, testImageName)
reqPath := filepath.Join(remoteName, "tags/list")

regAuthCtx.Scope.RemoteName = remoteName
regAuthCtx.Scope.Actions = "pull"

if err := regAuthCtx.PrepareAuth(indexServer); err != nil {
t.Fatalf("failed to prepare auth to %s for %s: %v", indexServer, reqPath, err)
}

inputURL := "https://" + indexServer + "/v2/" + reqPath

if _, err := regAuthCtx.GetResponse(inputURL, "GET", nil, []int{http.StatusOK}); err != nil {
t.Fatalf("got an unexpected reply: %v", err)
}
}

0 comments on commit b1de6b8

Please sign in to comment.