Skip to content

Commit

Permalink
fix layer cache test
Browse files Browse the repository at this point in the history
  • Loading branch information
thirdeyenick committed Nov 28, 2023
1 parent ab8d38f commit 3575466
Showing 1 changed file with 40 additions and 31 deletions.
71 changes: 40 additions & 31 deletions build_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -384,40 +384,48 @@ composer-lock-sha = "sha-from-composer-lock"
Expect(os.RemoveAll(filepath.Join(layersDir, composer.ComposerPackagesLayerName))).To(Succeed())
})

it("reuses the cached version of the composer packages", func() {
result, err := build(packit.BuildContext{
BuildpackInfo: buildpackInfo,
WorkingDir: workingDir,
Layers: packit.Layers{Path: layersDir},
Plan: buildpackPlan,
context("with BP_RUN_COMPOSER_INSTALL set to false", func() {
it.Before(func() {
Expect(os.Setenv("BP_RUN_COMPOSER_INSTALL", "false")).To(Succeed())
})
it.After(func() {
Expect(os.Unsetenv("BP_RUN_COMPOSER_INSTALL")).To(Succeed())
})
Expect(err).NotTo(HaveOccurred())

Expect(buffer).NotTo(ContainSubstring("Running 'composer install options from fake'"))
it("reuses the cached version of the composer packages", func() {
result, err := build(packit.BuildContext{
BuildpackInfo: buildpackInfo,
WorkingDir: workingDir,
Layers: packit.Layers{Path: layersDir},
Plan: buildpackPlan,
})
Expect(err).NotTo(HaveOccurred())

Expect(calculator.SumCall.Receives.Paths).To(Equal([]string{filepath.Join(workingDir, "composer.lock")}))
layers := result.Layers
Expect(layers).To(HaveLen(1))
Expect(buffer).NotTo(ContainSubstring("Running 'composer install options from fake'"))

packagesLayer := layers[0]
Expect(packagesLayer.Name).To(Equal(composer.ComposerPackagesLayerName))
Expect(packagesLayer.Path).To(Equal(filepath.Join(layersDir, composer.ComposerPackagesLayerName)))
Expect(calculator.SumCall.Receives.Paths).To(Equal([]string{filepath.Join(workingDir, "composer.lock")}))
layers := result.Layers
Expect(layers).To(HaveLen(1))

Expect(packagesLayer.Build).To(BeTrue())
Expect(packagesLayer.Launch).To(BeTrue())
Expect(packagesLayer.Cache).To(BeTrue())
packagesLayer := layers[0]
Expect(packagesLayer.Name).To(Equal(composer.ComposerPackagesLayerName))
Expect(packagesLayer.Path).To(Equal(filepath.Join(layersDir, composer.ComposerPackagesLayerName)))

Expect(packagesLayer.Metadata["composer-lock-sha"]).To(Equal("sha-from-composer-lock"))
Expect(packagesLayer.Metadata["stack"]).To(Equal(""))
Expect(packagesLayer.Build).To(BeTrue())
Expect(packagesLayer.Launch).To(BeTrue())
Expect(packagesLayer.Cache).To(BeTrue())

Expect(packagesLayer.SBOM.Formats()).To(HaveLen(2))
cdx := packagesLayer.SBOM.Formats()[0]
spdx := packagesLayer.SBOM.Formats()[1]
Expect(packagesLayer.Metadata["composer-lock-sha"]).To(Equal("sha-from-composer-lock"))
Expect(packagesLayer.Metadata["stack"]).To(Equal(""))

Expect(cdx.Extension).To(Equal("cdx.json"))
content, err := io.ReadAll(cdx.Content)
Expect(err).NotTo(HaveOccurred())
Expect(string(content)).To(MatchJSON(`{
Expect(packagesLayer.SBOM.Formats()).To(HaveLen(2))
cdx := packagesLayer.SBOM.Formats()[0]
spdx := packagesLayer.SBOM.Formats()[1]

Expect(cdx.Extension).To(Equal("cdx.json"))
content, err := io.ReadAll(cdx.Content)
Expect(err).NotTo(HaveOccurred())
Expect(string(content)).To(MatchJSON(`{
"bomFormat": "CycloneDX",
"components": [],
"metadata": {
Expand All @@ -433,10 +441,10 @@ composer-lock-sha = "sha-from-composer-lock"
"version": 1
}`))

Expect(spdx.Extension).To(Equal("spdx.json"))
content, err = io.ReadAll(spdx.Content)
Expect(err).NotTo(HaveOccurred())
Expect(string(content)).To(MatchJSON(`{
Expect(spdx.Extension).To(Equal("spdx.json"))
content, err = io.ReadAll(spdx.Content)
Expect(err).NotTo(HaveOccurred())
Expect(string(content)).To(MatchJSON(`{
"SPDXID": "SPDXRef-DOCUMENT",
"creationInfo": {
"created": "0001-01-01T00:00:00Z",
Expand All @@ -459,7 +467,8 @@ composer-lock-sha = "sha-from-composer-lock"
"spdxVersion": "SPDX-2.2"
}`))

Expect(filepath.Join(workingDir, "vendor", "file.txt")).To(BeAnExistingFile())
Expect(filepath.Join(workingDir, "vendor", "file.txt")).To(BeAnExistingFile())
})
})

context("when trying to reuse a layer but the stack changes", func() {
Expand Down

0 comments on commit 3575466

Please sign in to comment.