Skip to content

Commit

Permalink
Add Layer Metadata test as living doc (#1019)
Browse files Browse the repository at this point in the history
Layer Metadata is straightforward, adding a test to act as a living
document.

Signed-off-by: Aidan Delaney <adelaney21@bloomberg.net>
  • Loading branch information
AidanDelaney authored Feb 23, 2023
1 parent 03ee829 commit 4cb2bdc
Showing 1 changed file with 44 additions and 0 deletions.
44 changes: 44 additions & 0 deletions buildpack/layermetadata_test.go
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)
})
})
}

0 comments on commit 4cb2bdc

Please sign in to comment.