Skip to content

Commit

Permalink
Update oci integration tests to test OIDCLogin
Browse files Browse the repository at this point in the history
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 25, 2023
1 parent 48ad0eb commit 1c2956b
Show file tree
Hide file tree
Showing 3 changed files with 35 additions and 4 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
22 changes: 22 additions & 0 deletions oci/tests/integration/repo_list_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,28 @@ func TestRepositoryRootLoginListTags(t *testing.T) {
}
}

func TestOIDCLoginListTags(t *testing.T) {
for name, repo := range testRepos {
t.Run(name, func(t *testing.T) {
// Registry only.
parts := strings.SplitN(repo, "/", 2)
args := []string{
"-oidc-login=true",
fmt.Sprintf("-registry=%s", parts[0]),
fmt.Sprintf("-repo=%s", parts[1]),
}
testImageRepositoryListTags(t, args)

// Registry + repo.
args = []string{
"-oidc-login=true",
fmt.Sprintf("-repo=%s", repo),
}
testImageRepositoryListTags(t, args)
})
}
}

func testImageRepositoryListTags(t *testing.T, args []string) {
g := NewWithT(t)
ctx := context.TODO()
Expand Down
13 changes: 10 additions & 3 deletions oci/tests/integration/testapp/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ package main
import (
"context"
"flag"
"fmt"
"log"
"strings"
"time"
Expand All @@ -38,8 +39,9 @@ import (
// - 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")
registry = flag.String("registry", "", "registry of the repository")
repo = flag.String("repo", "", "repository to list")
oidcLogin = flag.Bool("oidc-login", false, "login with OIDCLogin function")
)

func main() {
Expand Down Expand Up @@ -77,7 +79,12 @@ func main() {
panic(err)
}

auth, err = login.NewManager().Login(ctx, loginURL, ref, opts)
if *oidcLogin {
auth, err = login.NewManager().OIDCLogin(ctx, fmt.Sprintf("https://%s", loginURL), opts)
} else {
auth, err = login.NewManager().Login(ctx, loginURL, ref, opts)
}

if err != nil {
panic(err)
}
Expand Down

0 comments on commit 1c2956b

Please sign in to comment.