Skip to content

Commit

Permalink
Add test for the GetLabel function
Browse files Browse the repository at this point in the history
Signed-off-by: Domenico Luciani <[email protected]>
  • Loading branch information
Domenico Luciani committed Aug 10, 2023
1 parent fef3731 commit 144db83
Showing 1 changed file with 57 additions and 1 deletion.
58 changes: 57 additions & 1 deletion pkg/dist/image_test.go
Original file line number Diff line number Diff line change
@@ -1 +1,57 @@
package dist
package dist_test

import (
"github.com/buildpacks/pack/internal/builder/fakes"
"github.com/buildpacks/pack/pkg/dist"
h "github.com/buildpacks/pack/testhelpers"
"github.com/heroku/color"
"github.com/pkg/errors"
"github.com/sclevine/spec"
"github.com/sclevine/spec/report"
"testing"
)

func TestImage(t *testing.T) {
color.Disable(true)
defer color.Disable(false)
spec.Run(t, "testImage", testImage, spec.Parallel(), spec.Report(report.Terminal{}))
}

func testImage(t *testing.T, when spec.G, it spec.S) {
when("A label needs to be get", func() {
it("sets a label successfully", func() {
var outputLabel bool
mockInspectable := fakes.FakeInspectable{ReturnForLabel: "true", ErrorForLabel: nil}

isPresent, err := dist.GetLabel(&mockInspectable, "random-label", &outputLabel)

h.AssertNil(t, err)
h.AssertEq(t, isPresent, true)
h.AssertEq(t, outputLabel, true)
})

it("returns an error", func() {
var outputLabel bool
mockInspectable := fakes.FakeInspectable{ReturnForLabel: "", ErrorForLabel: errors.New("random-error")}

isPresent, err := dist.GetLabel(&mockInspectable, "random-label", &outputLabel)

h.AssertNotNil(t, err)
h.AssertEq(t, isPresent, false)
h.AssertEq(t, outputLabel, false)
})
})

when("Try to get an empty label", func() {
it("returns isPresent but it doesn't set the label", func() {
var outputLabel bool
mockInspectable := fakes.FakeInspectable{ReturnForLabel: "", ErrorForLabel: nil}

isPresent, err := dist.GetLabel(&mockInspectable, "random-label", &outputLabel)

h.AssertNil(t, err)
h.AssertEq(t, isPresent, false)
h.AssertEq(t, outputLabel, false)
})
})
}

0 comments on commit 144db83

Please sign in to comment.