Skip to content

Commit f42b6dc

Browse files
authored
Merge pull request #1097 from cloudfoundry/keep-failed-container
add keep-failed-containers flag when running integration tests
2 parents 57d0594 + 09ab740 commit f42b6dc

8 files changed

Lines changed: 52 additions & 24 deletions

File tree

scripts/integration.sh

Lines changed: 26 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -18,17 +18,19 @@ function usage() {
1818
integration.sh --github-token <token> [OPTIONS]
1919
Runs the integration tests.
2020
OPTIONS
21-
--help -h prints the command usage
22-
--github-token <token> GitHub token to use when making API requests
23-
--platform <cf|docker> Switchblade platform to execute the tests against
21+
--help -h prints the command usage
22+
--github-token <token> GitHub token to use when making API requests
23+
--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
@@ -94,31 +101,37 @@ function main() {
94101

95102
echo "Running integration suite (cached: ${cached}, parallel: ${parallel})"
96103

97-
specs::run "${cached}" "${parallel}" "${stack}" "${platform}" "${token:-}"
104+
specs::run "${cached}" "${parallel}" "${stack}" "${platform}" "${token:-}" "${keep_failed}"
98105
done
99106
}
100107

101108
function specs::run() {
102-
local cached parallel stack platform token
109+
local cached parallel stack platform token keep_failed
103110
cached="${1}"
104111
parallel="${2}"
105112
stack="${3}"
106113
platform="${4}"
107114
token="${5}"
115+
keep_failed="${6}"
108116

109-
local nodes cached_flag serial_flag platform_flag stack_flag token_flag
117+
local nodes cached_flag serial_flag platform_flag stack_flag token_flag keep_failed_flag
110118
cached_flag="--cached=${cached}"
111119
serial_flag="--serial=true"
112120
platform_flag="--platform=${platform}"
113121
stack_flag="--stack=${stack}"
114122
token_flag="--github-token=${token}"
123+
keep_failed_flag=""
115124
nodes=1
116125

117126
if [[ "${parallel}" == "true" ]]; then
118127
nodes=3
119128
serial_flag=""
120129
fi
121130

131+
if [[ "${keep_failed}" == "true" ]]; then
132+
keep_failed_flag="--keep-failed-containers"
133+
fi
134+
122135
local buildpack_file
123136
buildpack_file="$(buildpack::package "1.2.3" "${cached}" "${stack}")"
124137

@@ -131,11 +144,12 @@ function specs::run() {
131144
-mod vendor \
132145
-v \
133146
"${src}/integration" \
134-
"${cached_flag}" \
135-
"${platform_flag}" \
136-
"${token_flag}" \
137-
"${stack_flag}" \
138-
"${serial_flag}"
147+
${cached_flag} \
148+
${platform_flag} \
149+
${token_flag} \
150+
${stack_flag} \
151+
${serial_flag} \
152+
${keep_failed_flag}
139153
}
140154

141155
function buildpack::package() {

src/ruby/integration/cache_test.go

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,9 @@ func testCache(platform switchblade.Platform, fixtures string) func(*testing.T,
3232
})
3333

3434
it.After(func() {
35-
Expect(platform.Delete.Execute(name)).To(Succeed())
35+
if name != "" && (!settings.KeepFailedContainers || !t.Failed()) {
36+
Expect(platform.Delete.Execute(name)).To(Succeed())
37+
}
3638
})
3739

3840
it("uses the cache for manifest dependencies when deployed twice", func() {

src/ruby/integration/default_test.go

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

3131
it.After(func() {
32-
Expect(platform.Delete.Execute(name)).To(Succeed())
32+
if name != "" && (!settings.KeepFailedContainers || !t.Failed()) {
33+
Expect(platform.Delete.Execute(name)).To(Succeed())
34+
}
3335
})
3436

3537
context("when the ruby version is specified in the app", func() {

src/ruby/integration/init_test.go

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -24,17 +24,19 @@ var settings struct {
2424
Path string
2525
}
2626

27-
Cached bool
28-
Serial bool
29-
FixturesPath string
30-
GitHubToken string
31-
Platform string
32-
Stack string
27+
Cached bool
28+
Serial bool
29+
KeepFailedContainers bool
30+
FixturesPath string
31+
GitHubToken string
32+
Platform string
33+
Stack string
3334
}
3435

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

src/ruby/integration/multibuildpack_test.go

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,9 @@ func testMultiBuildpack(platform switchblade.Platform, fixtures string) func(*te
2727
})
2828

2929
it.After(func() {
30-
Expect(platform.Delete.Execute(name)).To(Succeed())
30+
if name != "" && (!settings.KeepFailedContainers || !t.Failed()) {
31+
Expect(platform.Delete.Execute(name)).To(Succeed())
32+
}
3133
})
3234

3335
context("when ruby is a supply for the binary buildpack", func() {

src/ruby/integration/offline_test.go

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,9 @@ 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 name != "" && (!settings.KeepFailedContainers || !t.Failed()) {
31+
Expect(platform.Delete.Execute(name)).To(Succeed())
32+
}
3133
})
3234

3335
it("runs a vendored cached app", func() {

src/ruby/integration/override_test.go

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

2828
it.After(func() {
29-
Expect(platform.Delete.Execute(name)).To(Succeed())
29+
if name != "" && (!settings.KeepFailedContainers || !t.Failed()) {
30+
Expect(platform.Delete.Execute(name)).To(Succeed())
31+
}
3032
})
3133

3234
it("forces node from override buildpack", func() {

src/ruby/integration/proxy_test.go

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,9 @@ func testProxy(platform switchblade.Platform, fixtures, uri string) func(*testin
2727
})
2828

2929
it.After(func() {
30-
Expect(platform.Delete.Execute(name)).To(Succeed())
30+
if name != "" && (!settings.KeepFailedContainers || !t.Failed()) {
31+
Expect(platform.Delete.Execute(name)).To(Succeed())
32+
}
3133
})
3234

3335
it("builds an app with the proxy set", func() {

0 commit comments

Comments
 (0)