Skip to content

Commit

Permalink
Speed up base image unit test with local registry
Browse files Browse the repository at this point in the history
Also follow my own advice to `defer Close()` 😇
  • Loading branch information
halvards committed Aug 27, 2021
1 parent ae594dc commit a83e016
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 2 deletions.
16 changes: 14 additions & 2 deletions pkg/commands/config_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,15 +18,27 @@ package commands

import (
"context"
"fmt"
"testing"

"github.com/google/go-containerregistry/pkg/crane"
"github.com/google/ko/pkg/build"
"github.com/google/ko/pkg/commands/options"
)

func TestOverrideDefaultBaseImageUsingBuildOption(t *testing.T) {
wantDigest := "sha256:76c39a6f76890f8f8b026f89e081084bc8c64167d74e6c93da7a053cb4ccb5dd"
wantImage := "gcr.io/distroless/static-debian9@" + wantDigest
namespace := "base"
s, err := registryServerWithImage(namespace)
if err != nil {
t.Fatalf("could not create test registry server: %v", err)
}
defer s.Close()
baseImage := fmt.Sprintf("%s/%s", s.Listener.Addr().String(), namespace)
wantDigest, err := crane.Digest(baseImage)
if err != nil {
t.Fatalf("crane.Digest(%s): %v", baseImage, err)
}
wantImage := fmt.Sprintf("%s@%s", baseImage, wantDigest)
bo := &options.BuildOptions{
BaseImage: wantImage,
}
Expand Down
1 change: 1 addition & 0 deletions pkg/commands/resolver_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -166,6 +166,7 @@ func TestNewBuilder(t *testing.T) {
if err != nil {
t.Fatalf("could not create test registry server: %v", err)
}
defer s.Close()
baseImage := fmt.Sprintf("%s/%s", s.Listener.Addr().String(), namespace)

tests := []struct {
Expand Down

0 comments on commit a83e016

Please sign in to comment.