-
Notifications
You must be signed in to change notification settings - Fork 106
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add Layer Metadata test as living doc (#1019)
Layer Metadata is straightforward, adding a test to act as a living document. Signed-off-by: Aidan Delaney <adelaney21@bloomberg.net>
- Loading branch information
1 parent
03ee829
commit 4cb2bdc
Showing
1 changed file
with
44 additions
and
0 deletions.
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 |
---|---|---|
@@ -0,0 +1,44 @@ | ||
package buildpack_test | ||
|
||
import ( | ||
"os" | ||
"testing" | ||
|
||
"github.com/sclevine/spec" | ||
"github.com/sclevine/spec/report" | ||
|
||
"github.com/buildpacks/lifecycle/buildpack" | ||
h "github.com/buildpacks/lifecycle/testhelpers" | ||
) | ||
|
||
func TestLayerMetadata(t *testing.T) { | ||
spec.Run(t, "unit-layermetadata", testLayerMetadata, spec.Report(report.Terminal{})) | ||
} | ||
|
||
func testLayerMetadata(t *testing.T, when spec.G, it spec.S) { | ||
when("#LayerMetadata", func() { | ||
var ( | ||
metadataFile *os.File | ||
) | ||
it.Before(func() { | ||
var err error | ||
metadataFile, err = os.CreateTemp("", "test") | ||
h.AssertNil(t, err) | ||
}) | ||
it.After(func() { | ||
os.Remove(metadataFile.Name()) | ||
}) | ||
it("decodes file correctly", func() { | ||
err := os.WriteFile(metadataFile.Name(), []byte("[types]\ncache = true"), 0400) | ||
h.AssertNil(t, err) | ||
|
||
var lmf buildpack.LayerMetadataFile | ||
lmf, s, err := buildpack.DecodeLayerMetadataFile(metadataFile.Name(), "0.9") | ||
h.AssertNil(t, err) | ||
h.AssertEq(t, s, "") | ||
h.AssertEq(t, lmf.Cache, true) | ||
h.AssertEq(t, lmf.Build, false) | ||
h.AssertEq(t, lmf.Launch, false) | ||
}) | ||
}) | ||
} |