diff --git a/oci/tests/integration/Makefile b/oci/tests/integration/Makefile index 7f90367db..33acd06ff 100644 --- a/oci/tests/integration/Makefile +++ b/oci/tests/integration/Makefile @@ -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 . diff --git a/oci/tests/integration/repo_list_test.go b/oci/tests/integration/repo_list_test.go index 12aaac274..06f2d1fc7 100644 --- a/oci/tests/integration/repo_list_test.go +++ b/oci/tests/integration/repo_list_test.go @@ -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) }) diff --git a/oci/tests/integration/testapp/main.go b/oci/tests/integration/testapp/main.go index c7df88bbc..8f3133f24 100644 --- a/oci/tests/integration/testapp/main.go +++ b/oci/tests/integration/testapp/main.go @@ -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") @@ -53,8 +52,8 @@ 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 @@ -62,16 +61,12 @@ func main() { 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) @@ -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) }