Skip to content
This repository has been archived by the owner on Jul 13, 2022. It is now read-only.

Commit

Permalink
Uses occam.Source to allow integration specs to run in parallel (#6)
Browse files Browse the repository at this point in the history
occam.Source duplicates the source code directory and makes it unique by
adding a file with unique random content.
  • Loading branch information
ryanmoran authored Jul 8, 2020
1 parent f18c99f commit 7a9fdbe
Show file tree
Hide file tree
Showing 3 changed files with 27 additions and 13 deletions.
10 changes: 5 additions & 5 deletions integration/init_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,13 +25,13 @@ func TestIntegration(t *testing.T) {
Expect := NewWithT(t).Expect

root, err := dagger.FindBPRoot()
Expect(err).ToNot(HaveOccurred())
Expect(err).NotTo(HaveOccurred())

buildpack, err = dagger.PackageBuildpack(root)
Expect(err).NotTo(HaveOccurred())

nginxBuildpack, err = dagger.GetLatestCommunityBuildpack("paketo-buildpacks", "nginx")
Expect(err).ToNot(HaveOccurred())
Expect(err).NotTo(HaveOccurred())

// HACK: we need to fix dagger and the package.sh scripts so that this isn't required
buildpack = fmt.Sprintf("%s.tgz", buildpack)
Expand All @@ -43,9 +43,9 @@ func TestIntegration(t *testing.T) {

SetDefaultEventuallyTimeout(5 * time.Second)

suite := spec.New("Integration", spec.Report(report.Terminal{}))
suite("Nginx", testNginx, spec.Parallel())
suite("Logging", testLogging, spec.Parallel())
suite := spec.New("Integration", spec.Report(report.Terminal{}), spec.Parallel())
suite("Nginx", testNginx)
suite("Logging", testLogging)
suite.Run(t)
}

Expand Down
15 changes: 11 additions & 4 deletions integration/logging_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package integration

import (
"fmt"
"os"
"path/filepath"
"testing"

Expand All @@ -27,7 +28,9 @@ func testLogging(t *testing.T, when spec.G, it spec.S) {
when("when the buildpack is run with pack build", func() {
var (
image occam.Image
name string

name string
source string
)

it.Before(func() {
Expand All @@ -39,19 +42,23 @@ func testLogging(t *testing.T, when spec.G, it spec.S) {
it.After(func() {
Expect(docker.Image.Remove.Execute(image.ID)).To(Succeed())
Expect(docker.Volume.Remove.Execute(occam.CacheVolumeNames(name))).To(Succeed())
Expect(os.RemoveAll(source)).To(Succeed())
})

it("logs useful information for the user", func() {
var err error
source, err = occam.Source(filepath.Join("testdata", "nginx_helloworld"))
Expect(err).NotTo(HaveOccurred())

var logs fmt.Stringer
image, logs, err = pack.WithNoColor().Build.
WithNoPull().
WithBuildpacks(nginxBuildpack, buildpack).
Execute(name, filepath.Join("testdata", "nginx_helloworld"))
Expect(err).ToNot(HaveOccurred(), logs.String)
Execute(name, source)
Expect(err).NotTo(HaveOccurred(), logs.String)

buildpackVersion, err := GetGitVersion()
Expect(err).ToNot(HaveOccurred())
Expect(err).NotTo(HaveOccurred())

Expect(logs).To(ContainLines(
fmt.Sprintf("Staticfile Buildpack %s", buildpackVersion),
Expand Down
15 changes: 11 additions & 4 deletions integration/nginx_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import (
"fmt"
"io/ioutil"
"net/http"
"os"
"path/filepath"
"testing"

Expand Down Expand Up @@ -32,7 +33,9 @@ func testNginx(t *testing.T, context spec.G, it spec.S) {
var (
image occam.Image
container occam.Container
name string

name string
source string
)

it.Before(func() {
Expand All @@ -45,16 +48,20 @@ func testNginx(t *testing.T, context spec.G, it spec.S) {
Expect(docker.Container.Remove.Execute(container.ID)).To(Succeed())
Expect(docker.Image.Remove.Execute(image.ID)).To(Succeed())
Expect(docker.Volume.Remove.Execute(occam.CacheVolumeNames(name))).To(Succeed())
Expect(os.RemoveAll(source)).To(Succeed())
})

it("creates nginx.conf file", func() {
var err error
source, err = occam.Source(filepath.Join("testdata", "nginx_helloworld"))
Expect(err).NotTo(HaveOccurred())

var logs fmt.Stringer
image, logs, err = pack.WithNoColor().Build.
WithNoPull().
WithBuildpacks(nginxBuildpack, buildpack).
Execute(name, filepath.Join("testdata", "nginx_helloworld"))
Expect(err).ToNot(HaveOccurred(), logs.String)
Execute(name, source)
Expect(err).NotTo(HaveOccurred(), logs.String)

container, err = docker.Container.Run.Execute(image.ID)
Expect(err).NotTo(HaveOccurred())
Expand All @@ -64,13 +71,13 @@ func testNginx(t *testing.T, context spec.G, it spec.S) {
response, err := http.Get(fmt.Sprintf("http://localhost:%s", container.HostPort()))
Expect(err).NotTo(HaveOccurred())
defer response.Body.Close()

Expect(response.StatusCode).To(Equal(http.StatusOK))

content, err := ioutil.ReadAll(response.Body)
Expect(err).NotTo(HaveOccurred())

Expect(string(content)).To(ContainSubstring("helloworld"))

})
})
}

0 comments on commit 7a9fdbe

Please sign in to comment.