diff --git a/detect.go b/detect.go index f64a0162..fdd01380 100644 --- a/detect.go +++ b/detect.go @@ -33,11 +33,14 @@ func Detect(versionParser VersionParser) packit.DetectFunc { if os.IsNotExist(err) { return plan, nil } + + fmt.Printf("failed to stat nginx.conf: %s", err) return packit.DetectResult{}, fmt.Errorf("failed to stat nginx.conf: %w", err) } version, versionSource, err := versionParser.ParseVersion(context.WorkingDir, context.CNBPath) if err != nil { + fmt.Printf("parsing version failed: %s", err) return packit.DetectResult{}, fmt.Errorf("parsing version failed: %w", err) } diff --git a/go.mod b/go.mod index d3ea79ec..cc7b50c0 100644 --- a/go.mod +++ b/go.mod @@ -1,12 +1,12 @@ module github.com/paketo-buildpacks/nginx -go 1.12 +go 1.15 require ( github.com/BurntSushi/toml v0.3.1 github.com/onsi/gomega v1.10.3 github.com/paketo-buildpacks/occam v0.0.20 - github.com/paketo-buildpacks/packit v0.3.0 + github.com/paketo-buildpacks/packit v0.3.1 github.com/sclevine/spec v1.4.0 gopkg.in/yaml.v2 v2.3.0 ) diff --git a/go.sum b/go.sum index b04c0230..78e53d94 100644 --- a/go.sum +++ b/go.sum @@ -95,6 +95,8 @@ github.com/paketo-buildpacks/occam v0.0.20 h1:HLrX2gisgTQGUPnu6yY7sVhvzNdxtX/C3R github.com/paketo-buildpacks/occam v0.0.20/go.mod h1:hX9a63hlZWjhugZOBsD41fW4tToGpWhbJr6r3gjEhDA= github.com/paketo-buildpacks/packit v0.3.0 h1:JnlqRkhrtpyut5BcKND/OoVB7FclicIBoWljWLQmVxQ= github.com/paketo-buildpacks/packit v0.3.0/go.mod h1:BQ38pCFZjrtPnJBVbH7X0DEoLyob9YKjrx0+3hlFaRY= +github.com/paketo-buildpacks/packit v0.3.1 h1:LpyxVH4OewGduN1lZWx8X/u1TdWltEC+oslHMffpeII= +github.com/paketo-buildpacks/packit v0.3.1/go.mod h1:BQ38pCFZjrtPnJBVbH7X0DEoLyob9YKjrx0+3hlFaRY= github.com/prometheus/client_model v0.0.0-20190812154241-14fe0d1b01d4/go.mod h1:xMI15A0UPsDsEKsMN9yxemIoYk6Tm2C1GtYGdfGttqA= github.com/sclevine/agouti v3.0.0+incompatible/go.mod h1:b4WX9W9L1sfQKXeJf1mUTLZKJ48R1S7H23Ji7oFO5Bw= github.com/sclevine/spec v1.4.0 h1:z/Q9idDcay5m5irkZ28M7PtQM4aOISzOpj4bUPkDee8= diff --git a/integration/caching_test.go b/integration/caching_test.go index c86f98ab..7db060a0 100644 --- a/integration/caching_test.go +++ b/integration/caching_test.go @@ -8,11 +8,11 @@ import ( "github.com/paketo-buildpacks/occam" "github.com/sclevine/spec" - . "github.com/paketo-buildpacks/occam/matchers" . "github.com/onsi/gomega" + . "github.com/paketo-buildpacks/occam/matchers" ) -func testCaching(t *testing.T, when spec.G, it spec.S) { +func testCaching(t *testing.T, context spec.G, it spec.S) { var ( Expect = NewWithT(t).Expect Eventually = NewWithT(t).Eventually @@ -36,6 +36,9 @@ func testCaching(t *testing.T, when spec.G, it spec.S) { imageIDs = map[string]struct{}{} containerIDs = map[string]struct{}{} + + source, err = occam.Source(filepath.Join("testdata", "simple_app")) + Expect(err).ToNot(HaveOccurred()) }) it.After(func() { @@ -52,9 +55,6 @@ func testCaching(t *testing.T, when spec.G, it spec.S) { }) it("uses a cached layer and doesn't run twice", func() { - source, err := occam.Source(filepath.Join("testdata", "simple_app")) - Expect(err).ToNot(HaveOccurred()) - build := pack.Build.WithBuildpacks(nginxBuildpack) firstImage, _, err := build.Execute(name, source) diff --git a/integration/init_test.go b/integration/init_test.go index e904fc7e..e94fe62c 100644 --- a/integration/init_test.go +++ b/integration/init_test.go @@ -1,16 +1,13 @@ package integration import ( - "bytes" "os" "path/filepath" - "strings" "testing" "time" "github.com/BurntSushi/toml" "github.com/paketo-buildpacks/occam" - "github.com/paketo-buildpacks/packit/pexec" "github.com/sclevine/spec" "github.com/sclevine/spec/report" @@ -20,10 +17,9 @@ import ( var ( nginxBuildpack string offlineNginxBuildpack string - version string - buildpackInfo struct { + buildpackInfo struct { Buildpack struct { - ID string + ID string Name string } } @@ -44,17 +40,14 @@ func TestIntegration(t *testing.T) { buildpackStore := occam.NewBuildpackStore() - version, err = GetGitVersion() - Expect(err).NotTo(HaveOccurred()) - nginxBuildpack, err = buildpackStore.Get. - WithVersion(version). + WithVersion("1.2.3"). Execute(root) Expect(err).NotTo(HaveOccurred()) offlineNginxBuildpack, err = buildpackStore.Get. WithOfflineDependencies(). - WithVersion(version). + WithVersion("1.2.3"). Execute(root) Expect(err).NotTo(HaveOccurred()) @@ -68,32 +61,3 @@ func TestIntegration(t *testing.T) { suite("SimpleApp", testSimpleApp) suite.Run(t) } - -func GetGitVersion() (string, error) { - gitExec := pexec.NewExecutable("git") - revListOut := bytes.NewBuffer(nil) - - err := gitExec.Execute(pexec.Execution{ - Args: []string{"rev-list", "--tags", "--max-count=1"}, - Stdout: revListOut, - }) - - if revListOut.String() == "" { - return "0.0.0", nil - } - - if err != nil { - return "", err - } - - stdout := bytes.NewBuffer(nil) - err = gitExec.Execute(pexec.Execution{ - Args: []string{"describe", "--tags", strings.TrimSpace(revListOut.String())}, - Stdout: stdout, - }) - if err != nil { - return "", err - } - - return strings.TrimSpace(strings.TrimPrefix(stdout.String(), "v")), nil -} diff --git a/integration/logging_test.go b/integration/logging_test.go index 281db82d..02e91939 100644 --- a/integration/logging_test.go +++ b/integration/logging_test.go @@ -14,7 +14,7 @@ import ( . "github.com/onsi/gomega" ) -func testLogging(t *testing.T, when spec.G, it spec.S) { +func testLogging(t *testing.T, context spec.G, it spec.S) { var ( Expect = NewWithT(t).Expect @@ -33,6 +33,9 @@ func testLogging(t *testing.T, when spec.G, it spec.S) { var err error name, err = occam.RandomName() Expect(err).NotTo(HaveOccurred()) + + source, err = occam.Source(filepath.Join("testdata", "simple_app")) + Expect(err).NotTo(HaveOccurred()) }) it.After(func() { @@ -41,16 +44,10 @@ func testLogging(t *testing.T, when spec.G, it spec.S) { Expect(os.RemoveAll(source)).To(Succeed()) }) - when("building an app image", func() { + context("when building an app image", func() { it("correctly outputs logs", func() { var err error var logs fmt.Stringer - buildpackVersion, err := GetGitVersion() - Expect(err).NotTo(HaveOccurred()) - - source, err = occam.Source(filepath.Join("testdata", "simple_app")) - Expect(err).NotTo(HaveOccurred()) - image, logs, err = pack.Build. WithBuildpacks(nginxBuildpack). WithPullPolicy("never"). @@ -58,7 +55,7 @@ func testLogging(t *testing.T, when spec.G, it spec.S) { Expect(err).NotTo(HaveOccurred()) Expect(logs).To(matchers.ContainLines( - fmt.Sprintf("%s %s", buildpackInfo.Buildpack.Name, buildpackVersion), + fmt.Sprintf("%s 1.2.3", buildpackInfo.Buildpack.Name), " Resolving Nginx Server version", " Candidate version sources (in priority order):", ` buildpack.yml -> "1.19.*"`, diff --git a/integration/no_conf_app_test.go b/integration/no_conf_app_test.go index 312e7190..0d70b3c0 100644 --- a/integration/no_conf_app_test.go +++ b/integration/no_conf_app_test.go @@ -13,7 +13,7 @@ import ( . "github.com/onsi/gomega" ) -func testNoConfApp(t *testing.T, when spec.G, it spec.S) { +func testNoConfApp(t *testing.T, context spec.G, it spec.S) { var ( Expect = NewWithT(t).Expect pack occam.Pack @@ -27,21 +27,18 @@ func testNoConfApp(t *testing.T, when spec.G, it spec.S) { var err error name, err = occam.RandomName() Expect(err).NotTo(HaveOccurred()) + + source, err = occam.Source(filepath.Join("testdata", "no_conf_app")) + Expect(err).NotTo(HaveOccurred()) }) it.After(func() { Expect(os.RemoveAll(source)).To(Succeed()) }) - when("pushing app with no conf", func() { - // This is for when downstream buildpacks require nginx - it("build fails but provides unused nginx", func() { - var err error - - source, err = occam.Source(filepath.Join("testdata", "no_conf_app")) - Expect(err).NotTo(HaveOccurred()) - - _, _, err = pack.Build. + context("when pushing app with no conf", func() { + it("fails to build but provides unused nginx", func() { + _, _, err := pack.Build. WithBuildpacks(nginxBuildpack). WithPullPolicy("never"). Execute(name, source) diff --git a/integration/offline_test.go b/integration/offline_test.go index a63de654..bb3eaf25 100644 --- a/integration/offline_test.go +++ b/integration/offline_test.go @@ -15,7 +15,7 @@ import ( . "github.com/paketo-buildpacks/occam/matchers" ) -func testOffline(t *testing.T, when spec.G, it spec.S) { +func testOffline(t *testing.T, context spec.G, it spec.S) { var ( Expect = NewWithT(t).Expect Eventually = NewWithT(t).Eventually @@ -36,6 +36,9 @@ func testOffline(t *testing.T, when spec.G, it spec.S) { var err error name, err = occam.RandomName() Expect(err).NotTo(HaveOccurred()) + + source, err = occam.Source(filepath.Join("testdata", "simple_app")) + Expect(err).NotTo(HaveOccurred()) }) it.After(func() { @@ -45,13 +48,9 @@ func testOffline(t *testing.T, when spec.G, it spec.S) { Expect(os.RemoveAll(source)).To(Succeed()) }) - when("offline", func() { + context("offline", func() { it("serves up staticfile", func() { var err error - - source, err = occam.Source(filepath.Join("testdata", "simple_app")) - Expect(err).NotTo(HaveOccurred()) - image, _, err = pack.WithNoColor().Build. WithPullPolicy("never"). WithBuildpacks(offlineNginxBuildpack). diff --git a/integration/simple_app_test.go b/integration/simple_app_test.go index 592bf7e5..40f923d3 100644 --- a/integration/simple_app_test.go +++ b/integration/simple_app_test.go @@ -15,7 +15,7 @@ import ( . "github.com/paketo-buildpacks/occam/matchers" ) -func testSimpleApp(t *testing.T, when spec.G, it spec.S) { +func testSimpleApp(t *testing.T, context spec.G, it spec.S) { var ( Expect = NewWithT(t).Expect Eventually = NewWithT(t).Eventually @@ -45,13 +45,15 @@ func testSimpleApp(t *testing.T, when spec.G, it spec.S) { Expect(os.RemoveAll(source)).To(Succeed()) }) - when("pushing simple app", func() { - it("serves up staticfile", func() { + context("when pushing a simple app", func() { + it.Before(func() { var err error - source, err = occam.Source(filepath.Join("testdata", "simple_app")) Expect(err).NotTo(HaveOccurred()) + }) + it("serves up staticfile", func() { + var err error image, _, err = pack.Build. WithBuildpacks(nginxBuildpack). WithPullPolicy("never"). @@ -68,13 +70,16 @@ func testSimpleApp(t *testing.T, when spec.G, it spec.S) { Expect(response.StatusCode).To(Equal(http.StatusOK)) }) }) - when("an Nginx app uses the stream module", func() { - it("starts successfully", func() { - var err error + context("when an nginx app uses the stream module", func() { + it.Before(func() { + var err error source, err = occam.Source(filepath.Join("testdata", "with_stream_module")) Expect(err).NotTo(HaveOccurred()) + }) + it("starts successfully", func() { + var err error image, _, err = pack.Build. WithBuildpacks(nginxBuildpack). WithPullPolicy("never").