Skip to content

Commit

Permalink
update test
Browse files Browse the repository at this point in the history
Signed-off-by: cpanato <ctadeu@gmail.com>
  • Loading branch information
cpanato authored and imjasonh committed Nov 14, 2023
1 parent a271b54 commit 4aceae1
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 2 deletions.
10 changes: 9 additions & 1 deletion pkg/commands/resolver_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,10 @@ var (

type erroringClient struct {
daemon.Client

inspectErr error
inspectResp types.ImageInspect
inspectBody []byte
}

func (m *erroringClient) NegotiateAPIVersion(context.Context) {}
Expand All @@ -75,6 +79,10 @@ func (m *erroringClient) ImageTag(_ context.Context, _ string, _ string) error {
return errImageTag
}

func (m *erroringClient) ImageInspectWithRaw(_ context.Context, _ string) (types.ImageInspect, []byte, error) {
return m.inspectResp, m.inspectBody, m.inspectErr
}

func TestResolveMultiDocumentYAMLs(t *testing.T) {
refs := []string{fooRef, barRef}
hashes := []v1.Hash{fooHash, barHash}
Expand Down Expand Up @@ -275,7 +283,7 @@ func TestNewPublisherCanPublish(t *testing.T) {
Local: true,
},
shouldError: true,
wantError: errImageLoad,
wantError: errImageTag,
},
{
description: "bare with local domain and repo",
Expand Down
8 changes: 8 additions & 0 deletions pkg/internal/testing/daemon.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,10 @@ import (
type MockDaemon struct {
daemon.Client
Tags []string

inspectErr error
inspectResp types.ImageInspect
inspectBody []byte
}

func (m *MockDaemon) NegotiateAPIVersion(context.Context) {}
Expand All @@ -42,3 +46,7 @@ func (m *MockDaemon) ImageTag(_ context.Context, _ string, tag string) error {
m.Tags = append(m.Tags, tag)
return nil
}

func (m *MockDaemon) ImageInspectWithRaw(_ context.Context, _ string) (types.ImageInspect, []byte, error) {
return m.inspectResp, m.inspectBody, m.inspectErr
}
8 changes: 7 additions & 1 deletion pkg/publish/daemon_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ package publish_test

import (
"context"
"fmt"
"strings"
"testing"

Expand Down Expand Up @@ -63,7 +64,12 @@ func TestDaemonTags(t *testing.T) {
t.Errorf("Publish() = %v, wanted prefix %v", got, want)
}

expected := []string{"ko.local/98b8c7facdad74510a7cae0cd368eb4e:v2.0.0", "ko.local/98b8c7facdad74510a7cae0cd368eb4e:v1.2.3", "ko.local/98b8c7facdad74510a7cae0cd368eb4e:production"}
imgDigest, err := img.Digest()
if err != nil {
t.Fatalf("img.Digest() = %v", err)
}

expected := []string{fmt.Sprintf("ko.local/98b8c7facdad74510a7cae0cd368eb4e:%s", strings.Replace(imgDigest.String(), "sha256:", "", 1)), "ko.local/98b8c7facdad74510a7cae0cd368eb4e:v2.0.0", "ko.local/98b8c7facdad74510a7cae0cd368eb4e:v1.2.3", "ko.local/98b8c7facdad74510a7cae0cd368eb4e:production"}

for i, v := range expected {
if client.Tags[i] != v {
Expand Down

0 comments on commit 4aceae1

Please sign in to comment.