Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 18 additions & 3 deletions oci/tests/integration/repo_list_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ package integration
import (
"context"
"fmt"
"strings"
"testing"

. "github.com/onsi/gomega"
Expand All @@ -33,12 +34,26 @@ import (
func TestImageRepositoryListTags(t *testing.T) {
for name, repo := range testRepos {
t.Run(name, func(t *testing.T) {
testImageRepositoryListTags(t, repo)
args := []string{fmt.Sprintf("-repo=%s", repo)}
testImageRepositoryListTags(t, args)
})
}
}

func testImageRepositoryListTags(t *testing.T, repoURL string) {
func TestRepositoryRootLoginListTags(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)
})
}
}

func testImageRepositoryListTags(t *testing.T, args []string) {
g := NewWithT(t)
ctx := context.TODO()

Expand All @@ -49,7 +64,7 @@ func testImageRepositoryListTags(t *testing.T, repoURL string) {
{
Name: "test-app",
Image: testAppImage,
Args: []string{fmt.Sprintf("-repo=%s", repoURL)},
Args: args,
ImagePullPolicy: corev1.PullAlways,
},
}
Expand Down
35 changes: 31 additions & 4 deletions oci/tests/integration/testapp/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,10 @@ import (
"context"
"flag"
"log"
"strings"
"time"

"github.com/google/go-containerregistry/pkg/authn"
"github.com/google/go-containerregistry/pkg/name"
"github.com/google/go-containerregistry/pkg/v1/remote"
ctrl "sigs.k8s.io/controller-runtime"
Expand All @@ -30,7 +32,15 @@ import (
"github.com/fluxcd/pkg/oci/auth/login"
)

var repo = flag.String("repo", "", "repository to list")
// 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.
var (
registry = flag.String("registry", "", "registry of the repository")
repo = flag.String("repo", "", "repository to list")
)

func main() {
flag.Parse()
Expand All @@ -43,14 +53,31 @@ func main() {
ctx, cancel := context.WithTimeout(context.Background(), 10*time.Second)
defer cancel()

log.Println("repo:", *repo)
if *repo == "" {
panic("must provide -repo value")
}

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

ref, err := name.ParseReference(*repo)
if *registry != "" {
// Registry and repository are separate.
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)
}
if err != nil {
panic(err)
}

auth, err := login.NewManager().Login(ctx, *repo, ref, opts)
auth, err = login.NewManager().Login(ctx, loginURL, ref, opts)
if err != nil {
panic(err)
}
Expand Down