From 3e8bf3d8587bccf79f1eead8d241ea02cde114f6 Mon Sep 17 00:00:00 2001 From: Costas Papastathis Date: Fri, 27 Oct 2023 15:07:11 +0300 Subject: [PATCH] fixing the integration tests --- integration/default_test.go | 50 ++++++++++++++++++++++----------- integration/layer_reuse_test.go | 23 +++++++++++---- integration/offline_test.go | 18 ++++++++---- 3 files changed, 63 insertions(+), 28 deletions(-) diff --git a/integration/default_test.go b/integration/default_test.go index 21c5d1d..e79277a 100644 --- a/integration/default_test.go +++ b/integration/default_test.go @@ -21,11 +21,17 @@ func testDefault(t *testing.T, context spec.G, it spec.S) { pack occam.Pack docker occam.Docker + + pullPolicy = "never" ) it.Before(func() { pack = occam.NewPack().WithVerbose() docker = occam.NewDocker() + + if settings.Extensions.UbiNodejsExtension.Online != "" { + pullPolicy = "always" + } }) context("when the buildpack is run with pack build", func() { @@ -68,16 +74,21 @@ func testDefault(t *testing.T, context spec.G, it spec.S) { ) image, logs, err = pack.WithNoColor().Build. - WithPullPolicy("never"). - WithBuildpacks(buildpack, buildPlanBuildpack). + WithExtensions( + settings.Extensions.UbiNodejsExtension.Online, + ). + WithBuildpacks( + settings.Buildpacks.Yarn.Online, + settings.Buildpacks.BuildPlan.Online, + ). WithSBOMOutputDir(sbomDir). WithEnv(map[string]string{"BP_LOG_LEVEL": "DEBUG"}). + WithPullPolicy(pullPolicy). Execute(name, source) Expect(err).ToNot(HaveOccurred(), logs.String) // Ensure yarn is installed correctly - - container, err = docker.Container.Run.WithCommand("which yarn").Execute(image.ID) + container, err = docker.Container.Run.WithCommand("command -v yarn").Execute(image.ID) Expect(err).NotTo(HaveOccurred()) Eventually(func() string { @@ -87,12 +98,12 @@ func testDefault(t *testing.T, context spec.G, it spec.S) { }).Should(ContainSubstring("yarn")) Expect(logs).To(ContainLines( - MatchRegexp(fmt.Sprintf(`%s \d+\.\d+\.\d+`, buildpackInfo.Buildpack.Name)), + MatchRegexp(fmt.Sprintf(`%s \d+\.\d+\.\d+`, settings.Buildpack.Name)), " Executing build process", MatchRegexp(` Installing Yarn`), MatchRegexp(` Completed in ([0-9]*(\.[0-9]*)?[a-z]+)+`), "", - fmt.Sprintf(" Generating SBOM for /layers/%s/yarn", strings.ReplaceAll(buildpackInfo.Buildpack.ID, "/", "_")), + fmt.Sprintf(" Generating SBOM for /layers/%s/yarn", strings.ReplaceAll(settings.Buildpack.ID, "/", "_")), MatchRegexp(` Completed in \d+(\.?\d+)*`), "", " Writing SBOM in the following format(s):", @@ -103,12 +114,12 @@ func testDefault(t *testing.T, context spec.G, it spec.S) { )) // check that all required SBOM files are present - Expect(filepath.Join(sbomDir, "sbom", "launch", strings.ReplaceAll(buildpackInfo.Buildpack.ID, "/", "_"), "yarn", "sbom.cdx.json")).To(BeARegularFile()) - Expect(filepath.Join(sbomDir, "sbom", "launch", strings.ReplaceAll(buildpackInfo.Buildpack.ID, "/", "_"), "yarn", "sbom.spdx.json")).To(BeARegularFile()) - Expect(filepath.Join(sbomDir, "sbom", "launch", strings.ReplaceAll(buildpackInfo.Buildpack.ID, "/", "_"), "yarn", "sbom.syft.json")).To(BeARegularFile()) + Expect(filepath.Join(sbomDir, "sbom", "launch", strings.ReplaceAll(settings.Buildpack.ID, "/", "_"), "yarn", "sbom.cdx.json")).To(BeARegularFile()) + Expect(filepath.Join(sbomDir, "sbom", "launch", strings.ReplaceAll(settings.Buildpack.ID, "/", "_"), "yarn", "sbom.spdx.json")).To(BeARegularFile()) + Expect(filepath.Join(sbomDir, "sbom", "launch", strings.ReplaceAll(settings.Buildpack.ID, "/", "_"), "yarn", "sbom.syft.json")).To(BeARegularFile()) // check an SBOM file to make sure it has an entry for yarn - contents, err := os.ReadFile(filepath.Join(sbomDir, "sbom", "launch", strings.ReplaceAll(buildpackInfo.Buildpack.ID, "/", "_"), "yarn", "sbom.cdx.json")) + contents, err := os.ReadFile(filepath.Join(sbomDir, "sbom", "launch", strings.ReplaceAll(settings.Buildpack.ID, "/", "_"), "yarn", "sbom.cdx.json")) Expect(err).NotTo(HaveOccurred()) Expect(string(contents)).To(ContainSubstring(`"name": "Yarn"`)) @@ -155,8 +166,13 @@ func testDefault(t *testing.T, context spec.G, it spec.S) { ) image, logs, err = pack.WithNoColor().Build. - WithPullPolicy("never"). - WithBuildpacks(buildpack, buildPlanBuildpack). + WithExtensions( + settings.Extensions.UbiNodejsExtension.Online, + ). + WithPullPolicy(pullPolicy). + WithBuildpacks( + settings.Buildpacks.Yarn.Online, + settings.Buildpacks.BuildPlan.Online). WithSBOMOutputDir(sbomDir). WithEnv(map[string]string{ "BP_LOG_LEVEL": "DEBUG", @@ -166,7 +182,7 @@ func testDefault(t *testing.T, context spec.G, it spec.S) { Expect(err).ToNot(HaveOccurred(), logs.String) // Ensure yarn is installed correctly - container, err = docker.Container.Run.WithCommand("which yarn").Execute(image.ID) + container, err = docker.Container.Run.WithCommand("command -v yarn").Execute(image.ID) Expect(err).NotTo(HaveOccurred()) Eventually(func() string { @@ -176,7 +192,7 @@ func testDefault(t *testing.T, context spec.G, it spec.S) { }).Should(ContainSubstring("yarn")) Expect(logs).To(ContainLines( - MatchRegexp(fmt.Sprintf(`%s \d+\.\d+\.\d+`, buildpackInfo.Buildpack.Name)), + MatchRegexp(fmt.Sprintf(`%s \d+\.\d+\.\d+`, settings.Buildpack.Name)), " Executing build process", MatchRegexp(` Installing Yarn`), MatchRegexp(` Completed in ([0-9]*(\.[0-9]*)?[a-z]+)+`), @@ -185,9 +201,9 @@ func testDefault(t *testing.T, context spec.G, it spec.S) { )) // check that SBOM files were not generated - Expect(filepath.Join(sbomDir, "sbom", "launch", strings.ReplaceAll(buildpackInfo.Buildpack.ID, "/", "_"), "yarn", "sbom.cdx.json")).ToNot(BeARegularFile()) - Expect(filepath.Join(sbomDir, "sbom", "launch", strings.ReplaceAll(buildpackInfo.Buildpack.ID, "/", "_"), "yarn", "sbom.spdx.json")).ToNot(BeARegularFile()) - Expect(filepath.Join(sbomDir, "sbom", "launch", strings.ReplaceAll(buildpackInfo.Buildpack.ID, "/", "_"), "yarn", "sbom.syft.json")).ToNot(BeARegularFile()) + Expect(filepath.Join(sbomDir, "sbom", "launch", strings.ReplaceAll(settings.Buildpack.ID, "/", "_"), "yarn", "sbom.cdx.json")).ToNot(BeARegularFile()) + Expect(filepath.Join(sbomDir, "sbom", "launch", strings.ReplaceAll(settings.Buildpack.ID, "/", "_"), "yarn", "sbom.spdx.json")).ToNot(BeARegularFile()) + Expect(filepath.Join(sbomDir, "sbom", "launch", strings.ReplaceAll(settings.Buildpack.ID, "/", "_"), "yarn", "sbom.syft.json")).ToNot(BeARegularFile()) }) }) } diff --git a/integration/layer_reuse_test.go b/integration/layer_reuse_test.go index 3925faf..c5cb489 100644 --- a/integration/layer_reuse_test.go +++ b/integration/layer_reuse_test.go @@ -25,6 +25,9 @@ func testRebuildLayerReuse(t *testing.T, context spec.G, it spec.S) { name string source string + + pullPolicy = "never" + // extenderBuildStr = "" ) it.Before(func() { @@ -36,6 +39,11 @@ func testRebuildLayerReuse(t *testing.T, context spec.G, it spec.S) { pack = occam.NewPack() imageIDs = map[string]struct{}{} containerIDs = map[string]struct{}{} + + if settings.Extensions.UbiNodejsExtension.Online != "" { + pullPolicy = "always" + // extenderBuildStr = "[extender (build)] " + } }) it.After(func() { @@ -64,10 +72,13 @@ func testRebuildLayerReuse(t *testing.T, context spec.G, it spec.S) { Expect(err).NotTo(HaveOccurred()) build := pack.WithNoColor().Build. - WithPullPolicy("never"). + WithExtensions( + settings.Extensions.UbiNodejsExtension.Online, + ). + WithPullPolicy(pullPolicy). WithBuildpacks( - buildpack, - buildPlanBuildpack, + settings.Buildpacks.Yarn.Online, + settings.Buildpacks.BuildPlan.Online, ) firstImage, logs, err = build.Execute(name, source) @@ -77,7 +88,7 @@ func testRebuildLayerReuse(t *testing.T, context spec.G, it spec.S) { Expect(firstImage.Buildpacks).To(HaveLen(2)) - Expect(firstImage.Buildpacks[0].Key).To(Equal(buildpackInfo.Buildpack.ID)) + Expect(firstImage.Buildpacks[0].Key).To(Equal(settings.Buildpack.ID)) Expect(firstImage.Buildpacks[0].Layers).To(HaveKey("yarn")) Expect(logs.String()).To(ContainSubstring(" Executing build process")) @@ -90,11 +101,11 @@ func testRebuildLayerReuse(t *testing.T, context spec.G, it spec.S) { Expect(secondImage.Buildpacks).To(HaveLen(2)) - Expect(secondImage.Buildpacks[0].Key).To(Equal(buildpackInfo.Buildpack.ID)) + Expect(secondImage.Buildpacks[0].Key).To(Equal(settings.Buildpack.ID)) Expect(secondImage.Buildpacks[0].Layers).To(HaveKey("yarn")) Expect(logs.String()).NotTo(ContainSubstring(" Executing build process")) - Expect(logs.String()).To(ContainSubstring(fmt.Sprintf(" Reusing cached layer /layers/%s/yarn", strings.ReplaceAll(buildpackInfo.Buildpack.ID, "/", "_")))) + Expect(logs.String()).To(ContainSubstring(fmt.Sprintf(" Reusing cached layer /layers/%s/yarn", strings.ReplaceAll(settings.Buildpack.ID, "/", "_")))) Expect(secondImage.Buildpacks[0].Layers["yarn"].SHA).To(Equal(firstImage.Buildpacks[0].Layers["yarn"].SHA)) }) diff --git a/integration/offline_test.go b/integration/offline_test.go index cc511cc..93b3c6a 100644 --- a/integration/offline_test.go +++ b/integration/offline_test.go @@ -32,12 +32,18 @@ func testOffline(t *testing.T, context spec.G, it spec.S) { name string source string + + pullPolicy = "never" ) it.Before(func() { var err error name, err = occam.RandomName() Expect(err).NotTo(HaveOccurred()) + + if settings.Extensions.UbiNodejsExtension.Online != "" { + pullPolicy = "always" + } }) it.After(func() { @@ -54,16 +60,18 @@ func testOffline(t *testing.T, context spec.G, it spec.S) { var logs fmt.Stringer image, logs, err = pack.WithNoColor().Build. - WithPullPolicy("never"). + WithExtensions( + settings.Extensions.UbiNodejsExtension.Online, + ). WithBuildpacks( - offlineBuildpack, - buildPlanBuildpack). - WithNetwork("none"). + settings.Buildpacks.Yarn.Offline, + settings.Buildpacks.BuildPlan.Online). + WithPullPolicy(pullPolicy). Execute(name, source) Expect(err).NotTo(HaveOccurred(), logs.String()) - container, err = docker.Container.Run.WithCommand("which yarn").Execute(image.ID) + container, err = docker.Container.Run.WithCommand("command -v yarn").Execute(image.ID) Expect(err).NotTo(HaveOccurred()) Eventually(func() string {