1
0
mirror of https://github.com/ko-build/ko.git synced 2025-03-17 20:47:51 +02:00

Speed up base image unit test with local registry (#429)

Also follow my own advice to `defer Close()` 😇
This commit is contained in:
Halvard Skogsrud 2021-08-28 02:52:01 +10:00 committed by GitHub
parent ae594dcc74
commit 29fccb0832
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 15 additions and 2 deletions

View File

@ -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,
}

View File

@ -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 {