Skip to content

Commit

Permalink
hmm.
Browse files Browse the repository at this point in the history
  • Loading branch information
Ryan Moran authored and paketo-bot committed Nov 4, 2020
1 parent ff621a3 commit 238608a
Show file tree
Hide file tree
Showing 9 changed files with 46 additions and 79 deletions.
3 changes: 3 additions & 0 deletions detect.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}

Expand Down
4 changes: 2 additions & 2 deletions go.mod
Original file line number Diff line number Diff line change
@@ -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
)
2 changes: 2 additions & 0 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -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=
Expand Down
10 changes: 5 additions & 5 deletions integration/caching_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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() {
Expand All @@ -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)
Expand Down
44 changes: 4 additions & 40 deletions integration/init_test.go
Original file line number Diff line number Diff line change
@@ -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"

Expand All @@ -20,10 +17,9 @@ import (
var (
nginxBuildpack string
offlineNginxBuildpack string
version string
buildpackInfo struct {
buildpackInfo struct {
Buildpack struct {
ID string
ID string
Name string
}
}
Expand All @@ -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())

Expand All @@ -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
}
15 changes: 6 additions & 9 deletions integration/logging_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand All @@ -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() {
Expand All @@ -41,24 +44,18 @@ 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").
Execute(name, source)
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.*"`,
Expand Down
17 changes: 7 additions & 10 deletions integration/no_conf_app_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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)
Expand Down
11 changes: 5 additions & 6 deletions integration/offline_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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() {
Expand All @@ -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).
Expand Down
19 changes: 12 additions & 7 deletions integration/simple_app_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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").
Expand All @@ -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").
Expand Down

0 comments on commit 238608a

Please sign in to comment.