Skip to content
This repository has been archived by the owner on May 3, 2022. It is now read-only.

Commit

Permalink
fix(builder): set ImageType for invocation images (#555)
Browse files Browse the repository at this point in the history
Signed-off-by: Matthew Fisher <[email protected]>
  • Loading branch information
Matthew Fisher authored Dec 4, 2018
1 parent 2d7f93b commit def9d9e
Show file tree
Hide file tree
Showing 2 changed files with 98 additions and 0 deletions.
1 change: 1 addition & 0 deletions pkg/builder/builder.go
Original file line number Diff line number Diff line change
Expand Up @@ -108,6 +108,7 @@ func (b *Builder) PrepareBuild(bldr *Builder, mfst *manifest.Manifest, appDir st
} else {
bundleImage := bundle.Image{Description: c.Name()}
bundleImage.Image = c.URI()
bundleImage.ImageType = c.Type()
bf.Images = append(bf.Images, bundleImage)
}
}
Expand Down
97 changes: 97 additions & 0 deletions pkg/builder/builder_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,97 @@
package builder

import (
"context"
"reflect"
"testing"

"github.com/deislabs/duffle/pkg/bundle"

"github.com/deislabs/duffle/pkg/duffle/manifest"
)

// testImage represents a mock invocation image
type testImage struct {
Nam string
Typ string
UR string
Diges string
}

// Name represents the name of a mock invocation image
func (tc testImage) Name() string {
return tc.Nam
}

// Type represents the type of a mock invocation image
func (tc testImage) Type() string {
return tc.Typ
}

// URI represents the URI of the artefact of a mock invocation image
func (tc testImage) URI() string {
return tc.UR
}

// Digest represents the digest of a mock invocation image
func (tc testImage) Digest() string {
return tc.Diges
}

// PrepareBuild is no-op for a mock invocation image
func (tc *testImage) PrepareBuild(ctx *Context) error {
return nil
}

// Build is no-op for a mock invocation image
func (tc testImage) Build(ctx context.Context, app *AppContext) error {
return nil
}

func TestPrepareBuild(t *testing.T) {
mfst := &manifest.Manifest{
Name: "foo",
Version: "0.1.0",
Description: "description",
Keywords: []string{"test"},
Maintainers: []bundle.Maintainer{
{
Name: "test",
Email: "[email protected]",
URL: "https://test.com",
},
},
}

components := []Component{
&testImage{
Nam: "cnab",
Typ: "docker",
UR: "cnab:0.1.0",
Diges: "",
},
&testImage{
Nam: "component1",
Typ: "docker",
UR: "component1:0.1.0",
Diges: "",
},
}

bldr := New()
_, b, err := bldr.PrepareBuild(bldr, mfst, "", components)
if err != nil {
t.Error(err)
}

if len(b.Images) != 1 {
t.Fatalf("expected there to be 1 image, got %d. Full output: %v", len(b.Images), b)
}

expected := bundle.Image{Description: "component1"}
expected.Image = "component1:0.1.0"
expected.ImageType = "docker"
if !reflect.DeepEqual(b.Images[0], expected) {
t.Errorf("expected %v, got %v", expected, b.Images[0])
}
}

0 comments on commit def9d9e

Please sign in to comment.