Skip to content

Commit

Permalink
scheduler test case
Browse files Browse the repository at this point in the history
  • Loading branch information
Bonehead5338 committed Mar 18, 2021
1 parent 8072134 commit b8782ab
Showing 1 changed file with 19 additions and 2 deletions.
21 changes: 19 additions & 2 deletions pkg/skaffold/build/scheduler_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@ import (
func TestGetBuild(t *testing.T) {
tests := []struct {
description string
artifact *latest.Artifact
buildArtifact ArtifactBuilder
tags tag.ImageTags
expectedTag string
Expand All @@ -46,6 +47,7 @@ func TestGetBuild(t *testing.T) {
}{
{
description: "build succeeds",
artifact: &latest.Artifact{ImageName: "skaffold/image1"},
buildArtifact: func(ctx context.Context, out io.Writer, artifact *latest.Artifact, tag string) (string, error) {
out.Write([]byte("build succeeds"))
return fmt.Sprintf("%s@sha256:abac", tag), nil
Expand All @@ -57,8 +59,23 @@ func TestGetBuild(t *testing.T) {
expectedTag: "skaffold/image1:v0.0.1@sha256:abac",
expectedOut: "Building [skaffold/image1]...\nbuild succeeds",
},
{
description: "build succeeds with no digest",
artifact: &latest.Artifact{ImageName: "skaffold/image1", NoDigest: true},
buildArtifact: func(ctx context.Context, out io.Writer, artifact *latest.Artifact, tag string) (string, error) {
out.Write([]byte("build succeeds with no digest"))
return fmt.Sprintf("%s@sha256:abac", tag), nil
},
tags: tag.ImageTags{
"skaffold/image1": "skaffold/image1:v0.0.1",
"skaffold/image2": "skaffold/image2:v0.0.2",
},
expectedTag: "skaffold/image1:v0.0.1",
expectedOut: "Building [skaffold/image1]...\nbuild succeeds with no digest",
},
{
description: "build fails",
artifact: &latest.Artifact{ImageName: "skaffold/image1"},
buildArtifact: func(ctx context.Context, out io.Writer, artifact *latest.Artifact, tag string) (string, error) {
return "", fmt.Errorf("build fails")
},
Expand All @@ -70,6 +87,7 @@ func TestGetBuild(t *testing.T) {
},
{
description: "tag not found",
artifact: &latest.Artifact{ImageName: "skaffold/image1"},
tags: tag.ImageTags{},
expectedOut: "Building [skaffold/image1]...\n",
shouldErr: true,
Expand All @@ -79,8 +97,7 @@ func TestGetBuild(t *testing.T) {
testutil.Run(t, test.description, func(t *testutil.T) {
out := new(bytes.Buffer)

artifact := &latest.Artifact{ImageName: "skaffold/image1"}
got, err := performBuild(context.Background(), out, test.tags, artifact, test.buildArtifact)
got, err := performBuild(context.Background(), out, test.tags, test.artifact, test.buildArtifact)

t.CheckErrorAndDeepEqual(test.shouldErr, err, test.expectedTag, got)
t.CheckDeepEqual(test.expectedOut, out.String())
Expand Down

0 comments on commit b8782ab

Please sign in to comment.