Skip to content

Commit a24f71e

Browse files
committed
add keep-failed-container within out integration tests
1 parent 9da31d4 commit a24f71e

11 files changed

Lines changed: 87 additions & 22 deletions

scripts/.util/tools.sh

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -148,10 +148,17 @@ function util::tools::cf::install() {
148148
exit 1
149149
esac
150150

151+
# Check if cf already exists in the target directory or system PATH
152+
if [[ -f "${dir}/cf" ]] || command -v cf >/dev/null 2>&1; then
153+
util::print::title "CF CLI already installed (using system version)"
154+
cf version
155+
return 0
156+
fi
157+
151158
if [[ ! -f "${dir}/cf" ]]; then
152159
util::print::title "Installing cf"
153160

154-
curl "https://packages.cloudfoundry.org/stable?release=${os}-binary&version=6.49.0&source=github-rel" \
161+
curl "https://packages.cloudfoundry.org/stable?release=${os}-binary&source=github-rel" \
155162
--silent \
156163
--location \
157164
--output /tmp/cf.tar.gz

scripts/integration.sh

Lines changed: 15 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -21,14 +21,16 @@ OPTIONS
2121
--help -h prints the command usage
2222
--github-token <token> GitHub token to use when making API requests
2323
--platform <cf|docker> Switchblade platform to execute the tests against
24+
--keep-failed-containers Preserve failed test containers for debugging (default: false)
2425
USAGE
2526
}
2627

2728
function main() {
28-
local src stack platform token cached parallel
29+
local src stack platform token cached parallel keep_failed
2930
src="$(find "${ROOTDIR}/src" -mindepth 1 -maxdepth 1 -type d )"
3031
stack="${CF_STACK:-$(jq -r -S .stack "${ROOTDIR}/config.json")}"
3132
platform="cf"
33+
keep_failed="false"
3234

3335
while [[ "${#}" != 0 ]]; do
3436
case "${1}" in
@@ -52,6 +54,11 @@ function main() {
5254
shift 2
5355
;;
5456

57+
--keep-failed-containers)
58+
keep_failed="true"
59+
shift 1
60+
;;
61+
5562
--help|-h)
5663
shift 1
5764
usage
@@ -99,24 +106,26 @@ function main() {
99106

100107
echo "Running integration suite (cached: ${cached}, parallel: ${parallel})"
101108

102-
specs::run "${cached}" "${parallel}" "${stack}" "${platform}" "${token:-}"
109+
specs::run "${cached}" "${parallel}" "${stack}" "${platform}" "${token:-}" "${keep_failed}"
103110
done
104111
}
105112

106113
function specs::run() {
107-
local cached parallel stack platform token
114+
local cached parallel stack platform token keep_failed
108115
cached="${1}"
109116
parallel="${2}"
110117
stack="${3}"
111118
platform="${4}"
112119
token="${5}"
120+
keep_failed="${6}"
113121

114-
local nodes cached_flag serial_flag platform_flag stack_flag token_flag
122+
local nodes cached_flag serial_flag platform_flag stack_flag token_flag keep_failed_flag
115123
cached_flag="--cached=${cached}"
116124
serial_flag="--serial=true"
117125
platform_flag="--platform=${platform}"
118126
stack_flag="--stack=${stack}"
119127
token_flag="--github-token=${token}"
128+
keep_failed_flag="--keep-failed-containers=${keep_failed}"
120129
nodes=1
121130

122131
if [[ "${parallel}" == "true" ]]; then
@@ -142,7 +151,8 @@ function specs::run() {
142151
"${platform_flag}" \
143152
"${token_flag}" \
144153
"${stack_flag}" \
145-
"${serial_flag}"
154+
"${serial_flag}" \
155+
"${keep_failed_flag}"
146156
}
147157

148158
function buildpack::package() {

src/php/integration/apms_test.go

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,13 @@ func testAPMs(platform switchblade.Platform, fixtures, dynatraceURI string) func
2828
})
2929

3030
it.After(func() {
31-
Expect(platform.Delete.Execute(name)).To(Succeed())
31+
if t.Failed() && name != "" {
32+
t.Logf("❌ FAILED TEST - App/Container: %s", name)
33+
t.Logf(" Platform: %s", settings.Platform)
34+
}
35+
if name != "" && (!settings.KeepFailedContainers || !t.Failed()) {
36+
Expect(platform.Delete.Execute(name)).To(Succeed())
37+
}
3238
})
3339

3440
context("appdynamics", func() {

src/php/integration/app_frameworks_test.go

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,13 @@ func testAppFrameworks(platform switchblade.Platform, fixtures string) func(*tes
2828
})
2929

3030
it.After(func() {
31-
Expect(platform.Delete.Execute(name)).To(Succeed())
31+
if t.Failed() && name != "" {
32+
t.Logf("❌ FAILED TEST - App/Container: %s", name)
33+
t.Logf(" Platform: %s", settings.Platform)
34+
}
35+
if name != "" && (!settings.KeepFailedContainers || !t.Failed()) {
36+
Expect(platform.Delete.Execute(name)).To(Succeed())
37+
}
3238
})
3339

3440
context("CakePHP", func() {

src/php/integration/composer_test.go

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,13 @@ func testComposer(platform switchblade.Platform, fixtures string) func(*testing.
2828
})
2929

3030
it.After(func() {
31-
Expect(platform.Delete.Execute(name)).To(Succeed())
31+
if t.Failed() && name != "" {
32+
t.Logf("❌ FAILED TEST - App/Container: %s", name)
33+
t.Logf(" Platform: %s", settings.Platform)
34+
}
35+
if name != "" && (!settings.KeepFailedContainers || !t.Failed()) {
36+
Expect(platform.Delete.Execute(name)).To(Succeed())
37+
}
3238
})
3339

3440
context("default PHP composer app", func() {

src/php/integration/default_test.go

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,13 @@ func testDefault(platform switchblade.Platform, fixtures string) func(*testing.T
2828
})
2929

3030
it.After(func() {
31-
Expect(platform.Delete.Execute(name)).To(Succeed())
31+
if t.Failed() && name != "" {
32+
t.Logf("❌ FAILED TEST - App/Container: %s", name)
33+
t.Logf(" Platform: %s", settings.Platform)
34+
}
35+
if name != "" && (!settings.KeepFailedContainers || !t.Failed()) {
36+
Expect(platform.Delete.Execute(name)).To(Succeed())
37+
}
3238
})
3339

3440
context("default PHP web app", func() {

src/php/integration/init_test.go

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -21,17 +21,19 @@ var settings struct {
2121
Path string
2222
}
2323

24-
Cached bool
25-
Serial bool
26-
FixturesPath string
27-
GitHubToken string
28-
Platform string
29-
Stack string
24+
Cached bool
25+
Serial bool
26+
KeepFailedContainers bool
27+
FixturesPath string
28+
GitHubToken string
29+
Platform string
30+
Stack string
3031
}
3132

3233
func init() {
3334
flag.BoolVar(&settings.Cached, "cached", false, "run cached buildpack tests")
3435
flag.BoolVar(&settings.Serial, "serial", false, "run serial buildpack tests")
36+
flag.BoolVar(&settings.KeepFailedContainers, "keep-failed-containers", false, "preserve failed test containers for debugging")
3537
flag.StringVar(&settings.Platform, "platform", "cf", `switchblade platform to test against ("cf" or "docker")`)
3638
flag.StringVar(&settings.GitHubToken, "github-token", "", "use the token to make GitHub API requests")
3739
flag.StringVar(&settings.Stack, "stack", "cflinuxfs4", "stack to use as default when pusing apps")

src/php/integration/modules_test.go

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,6 @@ package integration_test
33
import (
44
"fmt"
55
"os"
6-
"os/exec"
76
"path/filepath"
87
"testing"
98

@@ -31,7 +30,13 @@ func testModules(platform switchblade.Platform, fixtures string) func(*testing.T
3130
})
3231

3332
it.After(func() {
34-
Expect(platform.Delete.Execute(name)).To(Succeed())
33+
if t.Failed() && name != "" {
34+
t.Logf("❌ FAILED TEST - App/Container: %s", name)
35+
t.Logf(" Platform: %s", settings.Platform)
36+
}
37+
if name != "" && (!settings.KeepFailedContainers || !t.Failed()) {
38+
Expect(platform.Delete.Execute(name)).To(Succeed())
39+
}
3540
})
3641

3742
ItLoadsAllTheModules := func(deployment switchblade.Deployment) {

src/php/integration/offline_test.go

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,13 @@ func testOffline(platform switchblade.Platform, fixtures string) func(*testing.T
2727
})
2828

2929
it.After(func() {
30-
Expect(platform.Delete.Execute(name)).To(Succeed())
30+
if t.Failed() && name != "" {
31+
t.Logf("❌ FAILED TEST - App/Container: %s", name)
32+
t.Logf(" Platform: %s", settings.Platform)
33+
}
34+
if name != "" && (!settings.KeepFailedContainers || !t.Failed()) {
35+
Expect(platform.Delete.Execute(name)).To(Succeed())
36+
}
3137
})
3238

3339
context("vendored PHP web app", func() {

src/php/integration/python_extension_test.go

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,13 @@ func testPythonExtension(platform switchblade.Platform, fixtures string) func(*t
2626
})
2727

2828
it.After(func() {
29-
Expect(platform.Delete.Execute(name)).To(Succeed())
29+
if t.Failed() && name != "" {
30+
t.Logf("❌ FAILED TEST - App/Container: %s", name)
31+
t.Logf(" Platform: %s", settings.Platform)
32+
}
33+
if name != "" && (!settings.KeepFailedContainers || !t.Failed()) {
34+
Expect(platform.Delete.Execute(name)).To(Succeed())
35+
}
3036
})
3137

3238
context("app with buildpack-supported custom extension in python", func() {

0 commit comments

Comments
 (0)