github.com/buildpacks/pack@v0.33.3-0.20240516162812-884dd1837311/pkg/dist/image_test.go (about) 1 package dist_test 2 3 import ( 4 "testing" 5 6 "github.com/heroku/color" 7 "github.com/pkg/errors" 8 "github.com/sclevine/spec" 9 "github.com/sclevine/spec/report" 10 11 "github.com/buildpacks/pack/internal/builder/fakes" 12 "github.com/buildpacks/pack/pkg/dist" 13 h "github.com/buildpacks/pack/testhelpers" 14 ) 15 16 func TestImage(t *testing.T) { 17 color.Disable(true) 18 defer color.Disable(false) 19 spec.Run(t, "testImage", testImage, spec.Parallel(), spec.Report(report.Terminal{})) 20 } 21 22 func testImage(t *testing.T, when spec.G, it spec.S) { 23 when("A label needs to be get", func() { 24 it("sets a label successfully", func() { 25 var outputLabel bool 26 mockInspectable := fakes.FakeInspectable{ReturnForLabel: "true", ErrorForLabel: nil} 27 28 isPresent, err := dist.GetLabel(&mockInspectable, "random-label", &outputLabel) 29 30 h.AssertNil(t, err) 31 h.AssertEq(t, isPresent, true) 32 h.AssertEq(t, outputLabel, true) 33 }) 34 35 it("returns an error", func() { 36 var outputLabel bool 37 mockInspectable := fakes.FakeInspectable{ReturnForLabel: "", ErrorForLabel: errors.New("random-error")} 38 39 isPresent, err := dist.GetLabel(&mockInspectable, "random-label", &outputLabel) 40 41 h.AssertNotNil(t, err) 42 h.AssertEq(t, isPresent, false) 43 h.AssertEq(t, outputLabel, false) 44 }) 45 }) 46 47 when("Try to get an empty label", func() { 48 it("returns isPresent but it doesn't set the label", func() { 49 var outputLabel bool 50 mockInspectable := fakes.FakeInspectable{ReturnForLabel: "", ErrorForLabel: nil} 51 52 isPresent, err := dist.GetLabel(&mockInspectable, "random-label", &outputLabel) 53 54 h.AssertNil(t, err) 55 h.AssertEq(t, isPresent, false) 56 h.AssertEq(t, outputLabel, false) 57 }) 58 }) 59 }