Skip to content

Commit

Permalink
Update oci integration tests to test login for when only the registry…
Browse files Browse the repository at this point in the history
… host

is set. It also updates the Makefile to build the testapp for linux/amd64
by default. This can be changed by setting GOARCH and GOOS variables.

Signed-off-by: Somtochi Onyekwere <[email protected]>
  • Loading branch information
somtochiama committed May 19, 2023
1 parent 1d451cf commit 8d21146
Show file tree
Hide file tree
Showing 3 changed files with 28 additions and 25 deletions.
4 changes: 3 additions & 1 deletion oci/tests/integration/Makefile
Original file line number Diff line number Diff line change
@@ -1,12 +1,14 @@
GO_TEST_ARGS ?=
PROVIDER_ARG ?=
TEST_TIMEOUT ?= 30m
GOARCH ?= amd64
GOOS ?= linux

TEST_IMG ?= fluxcd/testapp:test

.PHONY: app
app:
CGO_ENABLED=0 go build -v -o app ./testapp
CGO_ENABLED=0 GOARCH=$(GOARCH) GOOS=$(GOOS) go build -v -o app ./testapp

docker-build: app
docker buildx build -t $(TEST_IMG) --load .
Expand Down
9 changes: 6 additions & 3 deletions oci/tests/integration/repo_list_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -34,19 +34,22 @@ import (
func TestImageRepositoryListTags(t *testing.T) {
for name, repo := range testRepos {
t.Run(name, func(t *testing.T) {
args := []string{fmt.Sprintf("-repo=%s", repo)}
parts := strings.SplitN(repo, "/", 2)
args := []string{
fmt.Sprintf("-registry=%s", parts[0]),
fmt.Sprintf("-repo=%s", parts[1]),
}
testImageRepositoryListTags(t, args)
})
}
}

func TestRepositoryRootLoginListTags(t *testing.T) {
func TestRepositoryRootLogin(t *testing.T) {
for name, repo := range testRepos {
t.Run(name, func(t *testing.T) {
parts := strings.SplitN(repo, "/", 2)
args := []string{
fmt.Sprintf("-registry=%s", parts[0]),
fmt.Sprintf("-repo=%s", parts[1]),
}
testImageRepositoryListTags(t, args)
})
Expand Down
40 changes: 19 additions & 21 deletions oci/tests/integration/testapp/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -34,9 +34,8 @@ import (

// registry and repo flags are to facilitate testing of two login scenarios:
// - when the repository contains the full address, including registry host,
// e.g. foo.azurecr.io/bar.
// - when the repository contains only the repository name and registry name
// is provided separately, e.g. registry: foo.azurecr.io, repo: bar.
// e.g. foo.azurecr.io/bar (registry: foo.azurecr.io, repo: bar).
// - when only the registry host is provided e.g. registry: foo.azurecr.io
var (
registry = flag.String("registry", "", "registry of the repository")
repo = flag.String("repo", "", "repository to list")
Expand All @@ -53,25 +52,21 @@ func main() {
ctx, cancel := context.WithTimeout(context.Background(), 10*time.Second)
defer cancel()

if *repo == "" {
panic("must provide -repo value")
if *registry == "" {
panic("must provide -registry value")
}

var loginURL string
var auth authn.Authenticator
var ref name.Reference
var err error

if *registry != "" {
// Registry and repository are separate.
loginURL = *registry
if *repo != "" {
// Repository was provided so we append it to the registry
log.Printf("registry: %s, repo: %s\n", *registry, *repo)
loginURL = *registry
ref, err = name.ParseReference(strings.Join([]string{*registry, *repo}, "/"))
} else {
// Repository contains the registry host address.
log.Println("repo:", *repo)
loginURL = *repo
ref, err = name.ParseReference(*repo)
loginURL = strings.Join([]string{*registry, *repo}, "/")
ref, err = name.ParseReference(loginURL)
}
if err != nil {
panic(err)
Expand All @@ -83,13 +78,16 @@ func main() {
}
log.Println("logged in")

var options []remote.Option
options = append(options, remote.WithAuth(auth))
options = append(options, remote.WithContext(ctx))
// only list if a repository is passed in
if *repo != "" {
var options []remote.Option
options = append(options, remote.WithAuth(auth))
options = append(options, remote.WithContext(ctx))

tags, err := remote.List(ref.Context(), options...)
if err != nil {
panic(err)
tags, err := remote.List(ref.Context(), options...)
if err != nil {
panic(err)
}
log.Println("tags:", tags)
}
log.Println("tags:", tags)
}

0 comments on commit 8d21146

Please sign in to comment.