Skip to content

Commit

Permalink
Adds integration testing matrix
Browse files Browse the repository at this point in the history
- factors our integration repo into before suite setup
  • Loading branch information
Ryan Moran committed Jul 6, 2021
1 parent 02dd825 commit 7577e05
Show file tree
Hide file tree
Showing 6 changed files with 92 additions and 164 deletions.
6 changes: 5 additions & 1 deletion config.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,10 @@
"linux"
],
"integration": {
"harness": "gotest"
"harness": "gotest",
"matrix": [
{ "cached": false, "parallel": true },
{ "cached": true, "parallel": true }
]
}
}
87 changes: 38 additions & 49 deletions scripts/integration.sh
Original file line number Diff line number Diff line change
Expand Up @@ -16,55 +16,54 @@ function main() {
stack="$(jq -r -S .stack "${ROOTDIR}/config.json")"
harness="$(jq -r -S .integration.harness "${ROOTDIR}/config.json")"

IFS=$'\n' read -r -d '' -a matrix < <(
jq -r -S -c .integration.matrix[] "${ROOTDIR}/config.json" \
&& printf "\0"
)

util::tools::ginkgo::install --directory "${ROOTDIR}/.bin"
util::tools::buildpack-packager::install --directory "${ROOTDIR}/.bin"
util::tools::cf::install --directory "${ROOTDIR}/.bin"

local cached serial
cached=true
serial=true
for row in "${matrix[@]}"; do
local cached parallel
cached="$(jq -r -S .cached <<<"${row}")"
parallel="$(jq -r -S .parallel <<<"${row}")"

if [[ "${src}" == *python ]]; then
specs::run "${harness}" "uncached" "parallel"
specs::run "${harness}" "uncached" "serial"
echo "Running integration suite (cached: ${cached}, parallel: ${parallel})"

specs::run "${harness}" "cached" "parallel"
specs::run "${harness}" "cached" "serial"
else
specs::run "${harness}" "uncached" "parallel"
specs::run "${harness}" "cached" "parallel"
fi
specs::run "${harness}" "${cached}" "${parallel}"
done
}

function specs::run() {
local harness cached serial
local harness cached parallel
harness="${1}"
cached="${2}"
serial="${3}"
parallel="${3}"

local nodes cached_flag serial_flag
cached_flag="--cached=${cached}"
serial_flag="-serial=true"
nodes=1

if [[ "${parallel}" == "true" ]]; then
nodes=3
serial_flag=""
fi

if [[ "${harness}" == "gotest" ]]; then
specs::gotest::run "${cached}" "${serial}"
specs::gotest::run "${nodes}" "${cached_flag}" "${serial_flag}"
else
specs::ginkgo::run "${cached}" "${serial}"
specs::ginkgo::run "${nodes}" "${cached_flag}" "${serial_flag}"
fi
}

function specs::gotest::run() {
local cached serial nodes
cached="false"
serial=""
nodes=3

echo "Run ${1} Buildpack"

if [[ "${1}" == "cached" ]] ; then
cached="true"
fi

if [[ "${2}" == "serial" ]]; then
nodes=1
serial="-serial=true"
fi
local nodes cached_flag serial_flag
nodes="${1}"
cached_flag="${2}"
serial_flag="${3}"

CF_STACK="${CF_STACK:-"${stack}"}" \
BUILDPACK_FILE="${UNCACHED_BUILDPACK_FILE:-}" \
Expand All @@ -75,36 +74,26 @@ function specs::gotest::run() {
-mod vendor \
-v \
"${src}/integration" \
--cached="${cached}" "${serial}"
"${cached_flag}" \
"${serial_flag}"
}

function specs::ginkgo::run(){
local cached serial nodes
cached="false"
serial=""
nodes="${GINKGO_NODES:-3}"

echo "Run ${1} Buildpack"

if [[ "${1}" == "cached" ]] ; then
cached="true"
fi

if [[ "${2}" == "serial" ]]; then
nodes=1
serial="-serial=true"
fi
local nodes cached_flag serial_flag
nodes="${1}"
cached_flag="${2}"
serial_flag="${3}"

CF_STACK="${CF_STACK:-"${stack}"}" \
BUILDPACK_FILE="${UNCACHED_BUILDPACK_FILE:-}" \
ginkgo \
-r \
-mod vendor \
--flakeAttempts "${GINKGO_ATTEMPTS:-2}" \
-nodes ${nodes} \
-nodes "${nodes}" \
--slowSpecThreshold 60 \
"${src}/integration" \
-- --cached="${cached}" "${serial}"
-- "${cached_flag}" "${serial_flag}"
}

main "${@:-}"
39 changes: 3 additions & 36 deletions src/apt/integration/default_test.go
Original file line number Diff line number Diff line change
@@ -1,11 +1,7 @@
package integration_test

import (
"html/template"
"os"
"path/filepath"
"testing"
"time"

"github.com/cloudfoundry/libbuildpack/cutlass"
"github.com/sclevine/spec"
Expand All @@ -15,46 +11,17 @@ import (

func testDefault(t *testing.T, context spec.G, it spec.S) {
var (
Expect = NewWithT(t).Expect
Eventually = NewWithT(t).Eventually
Expect = NewWithT(t).Expect

app *cutlass.App
repo *cutlass.App
appDir string
app *cutlass.App
)

it.Before(func() {
repo = cutlass.New(filepath.Join(bpDir, "fixtures", "repo"))
repo.Buildpacks = []string{"https://github.com/cloudfoundry/staticfile-buildpack#master"}
Expect(repo.Push()).To(Succeed())
Eventually(func() ([]string, error) { return repo.InstanceStates() }, 20*time.Second).Should(Equal([]string{"RUNNING"}))

var err error
appDir, err = cutlass.CopyFixture(filepath.Join(bpDir, "fixtures", "simple"))
Expect(err).NotTo(HaveOccurred())

repoBaseURL, err := repo.GetUrl("/")
Expect(err).NotTo(HaveOccurred())

template, err := template.ParseFiles(filepath.Join(bpDir, "fixtures", "simple", "apt.yml"))
Expect(err).ToNot(HaveOccurred())

file, err := os.Create(filepath.Join(appDir, "apt.yml"))
Expect(err).NotTo(HaveOccurred())

Expect(template.Execute(file, map[string]string{"repoBaseURL": repoBaseURL})).To(Succeed())
Expect(file.Close()).To(Succeed())
})

it.After(func() {
app = DestroyApp(app)
repo = DestroyApp(repo)

Expect(os.RemoveAll(appDir)).To(Succeed())
})

it("supplies apt packages to later buildpacks", func() {
app = cutlass.New(appDir)
app = cutlass.New(settings.FixturePath)
app.Buildpacks = []string{"apt_buildpack", "https://github.com/cloudfoundry/binary-buildpack#master"}
app.SetEnv("BP_DEBUG", "1")

Expand Down
37 changes: 3 additions & 34 deletions src/apt/integration/failure_test.go
Original file line number Diff line number Diff line change
@@ -1,9 +1,6 @@
package integration_test

import (
"html/template"
"os"
"path/filepath"
"testing"
"time"

Expand All @@ -18,44 +15,16 @@ func testFailure(t *testing.T, context spec.G, it spec.S) {
Expect = NewWithT(t).Expect
Eventually = NewWithT(t).Eventually

app *cutlass.App
repo *cutlass.App
appDir string
app *cutlass.App
)

it.Before(func() {
repo = cutlass.New(filepath.Join(bpDir, "fixtures", "repo"))
repo.Buildpacks = []string{"https://github.com/cloudfoundry/staticfile-buildpack#master"}
Expect(repo.Push()).To(Succeed())
Eventually(func() ([]string, error) { return repo.InstanceStates() }, 20*time.Second).Should(Equal([]string{"RUNNING"}))

var err error
appDir, err = cutlass.CopyFixture(filepath.Join(bpDir, "fixtures", "simple"))
Expect(err).NotTo(HaveOccurred())

repoBaseURL, err := repo.GetUrl("/")
Expect(err).NotTo(HaveOccurred())

template, err := template.ParseFiles(filepath.Join(bpDir, "fixtures", "simple", "apt.yml"))
Expect(err).ToNot(HaveOccurred())

file, err := os.Create(filepath.Join(appDir, "apt.yml"))
Expect(err).NotTo(HaveOccurred())

Expect(template.Execute(file, map[string]string{"repoBaseURL": repoBaseURL})).To(Succeed())
Expect(file.Close()).To(Succeed())
})

it.After(func() {
app = DestroyApp(app)
repo = DestroyApp(repo)

Expect(os.RemoveAll(appDir)).To(Succeed())
})

context("as a final buildpack", func() {
it.Before(func() {
app = cutlass.New(appDir)
app = cutlass.New(settings.FixturePath)
app.Buildpacks = []string{"https://github.com/cloudfoundry/binary-buildpack#master", "apt_buildpack"}
app.SetEnv("BP_DEBUG", "1")
})
Expand All @@ -70,7 +39,7 @@ func testFailure(t *testing.T, context spec.G, it spec.S) {

context("as a single buildpack", func() {
it.Before(func() {
app = cutlass.New(appDir)
app = cutlass.New(settings.FixturePath)
app.Buildpacks = []string{"apt_buildpack"}
app.SetEnv("BP_DEBUG", "1")
})
Expand Down
52 changes: 40 additions & 12 deletions src/apt/integration/init_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,9 @@ package integration_test

import (
"flag"
"html/template"
"os"
"path/filepath"
"testing"
"time"

Expand All @@ -13,38 +15,64 @@ import (
. "github.com/onsi/gomega"
)

var (
bpDir string
buildpackVersion string
packagedBuildpack cutlass.VersionedBuildpackPackage
)
var settings struct {
FixturePath string
BuildpackPath string
BuildpackVersion string
}

func init() {
flag.StringVar(&buildpackVersion, "version", "", "version to use (builds if empty)")
flag.StringVar(&settings.BuildpackVersion, "version", "", "version to use (builds if empty)")
flag.BoolVar(&cutlass.Cached, "cached", true, "cached buildpack")
flag.StringVar(&cutlass.DefaultMemory, "memory", "128M", "default memory for pushed apps")
flag.StringVar(&cutlass.DefaultDisk, "disk", "256M", "default disk for pushed apps")
}

func TestIntegration(t *testing.T) {
var (
Expect = NewWithT(t).Expect
err error
Expect = NewWithT(t).Expect
Eventually = NewWithT(t).Eventually

packagedBuildpack cutlass.VersionedBuildpackPackage
err error
)

if buildpackVersion == "" {
if settings.BuildpackVersion == "" {
packagedBuildpack, err = cutlass.PackageUniquelyVersionedBuildpack(os.Getenv("CF_STACK"), true)
Expect(err).NotTo(HaveOccurred())

buildpackVersion = packagedBuildpack.Version
settings.BuildpackVersion = packagedBuildpack.Version
}

bpDir, err = cutlass.FindRoot()
settings.BuildpackPath, err = cutlass.FindRoot()
Expect(err).NotTo(HaveOccurred())

Expect(cutlass.CopyCfHome()).To(Succeed())
cutlass.SeedRandom()

repo := cutlass.New(filepath.Join(settings.BuildpackPath, "fixtures", "repo"))
defer repo.Destroy()

repo.Buildpacks = []string{"https://github.com/cloudfoundry/staticfile-buildpack#master"}
Expect(repo.Push()).To(Succeed())
Eventually(func() ([]string, error) { return repo.InstanceStates() }, 20*time.Second).Should(Equal([]string{"RUNNING"}))

url, err := repo.GetUrl("/")
Expect(err).NotTo(HaveOccurred())

template, err := template.ParseFiles(filepath.Join(settings.BuildpackPath, "fixtures", "simple", "apt.yml"))
Expect(err).ToNot(HaveOccurred())

settings.FixturePath, err = cutlass.CopyFixture(filepath.Join(settings.BuildpackPath, "fixtures", "simple"))
Expect(err).NotTo(HaveOccurred())
defer os.RemoveAll(settings.FixturePath)

file, err := os.Create(filepath.Join(settings.FixturePath, "apt.yml"))
Expect(err).NotTo(HaveOccurred())

Expect(template.Execute(file, map[string]string{"repoBaseURL": url})).To(Succeed())
Expect(file.Close()).To(Succeed())

suite := spec.New("Integration", spec.Report(report.Terminal{}), spec.Parallel())
suite("Default", testDefault)
suite("PrivateRepo", testPrivateRepo)
Expand All @@ -63,7 +91,7 @@ func PushAppAndConfirm(t *testing.T, app *cutlass.App) {

Expect(app.Push()).To(Succeed())
Eventually(func() ([]string, error) { return app.InstanceStates() }, 20*time.Second).Should(Equal([]string{"RUNNING"}))
Expect(app.ConfirmBuildpack(buildpackVersion)).To(Succeed())
Expect(app.ConfirmBuildpack(settings.BuildpackVersion)).To(Succeed())
}

func DestroyApp(app *cutlass.App) *cutlass.App {
Expand Down

0 comments on commit 7577e05

Please sign in to comment.