From bee9c4b2553a7f0738413f2fe24363e0df200654 Mon Sep 17 00:00:00 2001 From: Forest Eckhardt Date: Tue, 10 Sep 2024 18:41:20 +0000 Subject: [PATCH] Remove integration test in favor of unit test that excerises the same code path --- build_test.go | 24 +++++++- integration/empty_cache_test.go | 79 ------------------------- integration/init_test.go | 1 - integration/testdata/no_modules/go.mod | 3 - integration/testdata/no_modules/main.go | 11 ---- 5 files changed, 22 insertions(+), 96 deletions(-) delete mode 100644 integration/empty_cache_test.go delete mode 100644 integration/testdata/no_modules/go.mod delete mode 100644 integration/testdata/no_modules/main.go diff --git a/build_test.go b/build_test.go index 9451f2c3..27abe2ab 100644 --- a/build_test.go +++ b/build_test.go @@ -54,8 +54,7 @@ func testBuild(t *testing.T, context spec.G, it spec.S) { err = os.MkdirAll(filepath.Join(layersDir, "mod-cache"), os.ModePerm) Expect(err).NotTo(HaveOccurred()) - _, err = os.CreateTemp(filepath.Join(layersDir, "mod-cache"), "example") - Expect(err).NotTo(HaveOccurred()) + Expect(os.WriteFile(filepath.Join(filepath.Join(layersDir, "mod-cache"), "cache"), nil, os.ModePerm)) now := time.Now() clock = chronos.NewClock(func() time.Time { @@ -177,6 +176,27 @@ func testBuild(t *testing.T, context spec.G, it spec.S) { }) }) + context("when the mod cache layer is empty", func() { + it.Before(func() { + err := os.RemoveAll(filepath.Join(layersDir, "mod-cache", "cache")) + Expect(err).NotTo(HaveOccurred()) + }) + + it("does not include the module cache layer in the build result", func() { + result, err := build(packit.BuildContext{ + Layers: packit.Layers{Path: layersDir}, + WorkingDir: workingDir, + BuildpackInfo: packit.BuildpackInfo{ + Name: "Some Buildpack", + Version: "some-version", + }, + }) + Expect(err).NotTo(HaveOccurred()) + + Expect(result.Layers).To(BeEmpty()) + }) + }) + context("failure cases", func() { context("build process fails to check if it should run", func() { it.Before(func() { diff --git a/integration/empty_cache_test.go b/integration/empty_cache_test.go deleted file mode 100644 index 04d9860f..00000000 --- a/integration/empty_cache_test.go +++ /dev/null @@ -1,79 +0,0 @@ -package integration_test - -import ( - "fmt" - "os" - "path/filepath" - "testing" - - "github.com/paketo-buildpacks/occam" - "github.com/sclevine/spec" - - . "github.com/onsi/gomega" - . "github.com/paketo-buildpacks/occam/matchers" -) - -func testEmptyCache(t *testing.T, context spec.G, it spec.S) { - var ( - Expect = NewWithT(t).Expect - - pack occam.Pack - docker occam.Docker - ) - - it.Before(func() { - pack = occam.NewPack().WithVerbose().WithNoColor() - docker = occam.NewDocker() - }) - - context("when building a simple go mod app", func() { - var ( - image occam.Image - - name string - source string - ) - - it.Before(func() { - var err error - name, err = occam.RandomName() - Expect(err).NotTo(HaveOccurred()) - }) - - it.After(func() { - Expect(docker.Volume.Remove.Execute(occam.CacheVolumeNames(name))).To(Succeed()) - Expect(docker.Image.Remove.Execute(image.ID)).To(Succeed()) - Expect(os.RemoveAll(source)).To(Succeed()) - }) - - it("builds successfully", func() { - var err error - source, err = occam.Source(filepath.Join("testdata", "no_modules")) - Expect(err).NotTo(HaveOccurred()) - - var logs fmt.Stringer - image, logs, err = pack.Build. - WithPullPolicy("never"). - WithBuildpacks( - settings.Buildpacks.GoDist.Online, - settings.Buildpacks.GoModVendor.Online, - ). - WithEnv(map[string]string{ - "GOTELEMETRY": "off", - }). - Execute(name, source) - Expect(err).NotTo(HaveOccurred(), logs.String) - - Expect(logs).To(ContainLines( - MatchRegexp(fmt.Sprintf(`%s \d+\.\d+\.\d+`, settings.Buildpack.Name)), - " Executing build process", - " Running 'go mod vendor'", - " go: no dependencies to vendor", - MatchRegexp(` Completed in ([0-9]*(\.[0-9]*)?[a-z]+)+`), - "", - )) - - Expect(logs).NotTo(ContainSubstring(fmt.Sprintf("%s:mod-cache", settings.Buildpack.ID)), logs.String) - }) - }) -} diff --git a/integration/init_test.go b/integration/init_test.go index 874db9ab..96d16945 100644 --- a/integration/init_test.go +++ b/integration/init_test.go @@ -82,7 +82,6 @@ func TestIntegration(t *testing.T) { suite := spec.New("Integration", spec.Report(report.Terminal{}), spec.Parallel()) suite("Default", testDefault) - suite("EmptyCache", testEmptyCache) suite("Vendored", testVendored) suite.Run(t) } diff --git a/integration/testdata/no_modules/go.mod b/integration/testdata/no_modules/go.mod deleted file mode 100644 index 2c70bc73..00000000 --- a/integration/testdata/no_modules/go.mod +++ /dev/null @@ -1,3 +0,0 @@ -module no_modules - -go 1.23 diff --git a/integration/testdata/no_modules/main.go b/integration/testdata/no_modules/main.go deleted file mode 100644 index 0862d468..00000000 --- a/integration/testdata/no_modules/main.go +++ /dev/null @@ -1,11 +0,0 @@ -package main - -import ( - _ "embed" - "fmt" -) - -//go:embed .occam-key -func main() { - fmt.Println("Hello World!") -}