-
Notifications
You must be signed in to change notification settings - Fork 293
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
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.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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) | ||
}) | ||
}) | ||
} |