From 09ab74033e0e574223935f0a73a15196908c2b2d Mon Sep 17 00:00:00 2001 From: ramonskie Date: Sat, 24 Jan 2026 12:53:15 +0100 Subject: [PATCH] add keep-failed-containers flag when running integration tests --- scripts/integration.sh | 38 ++++++++++++++------- src/ruby/integration/cache_test.go | 4 ++- src/ruby/integration/default_test.go | 4 ++- src/ruby/integration/init_test.go | 14 ++++---- src/ruby/integration/multibuildpack_test.go | 4 ++- src/ruby/integration/offline_test.go | 4 ++- src/ruby/integration/override_test.go | 4 ++- src/ruby/integration/proxy_test.go | 4 ++- 8 files changed, 52 insertions(+), 24 deletions(-) diff --git a/scripts/integration.sh b/scripts/integration.sh index bc6fdc1cd..3e2743ccb 100755 --- a/scripts/integration.sh +++ b/scripts/integration.sh @@ -18,17 +18,19 @@ function usage() { integration.sh --github-token [OPTIONS] Runs the integration tests. OPTIONS - --help -h prints the command usage - --github-token GitHub token to use when making API requests - --platform Switchblade platform to execute the tests against + --help -h prints the command usage + --github-token GitHub token to use when making API requests + --platform Switchblade platform to execute the tests against + --keep-failed-containers Preserve failed test containers for debugging (default: false) USAGE } function main() { - local src stack platform token cached parallel + local src stack platform token cached parallel keep_failed src="$(find "${ROOTDIR}/src" -mindepth 1 -maxdepth 1 -type d )" stack="${CF_STACK:-$(jq -r -S .stack "${ROOTDIR}/config.json")}" platform="cf" + keep_failed="false" while [[ "${#}" != 0 ]]; do case "${1}" in @@ -52,6 +54,11 @@ function main() { shift 2 ;; + --keep-failed-containers) + keep_failed="true" + shift 1 + ;; + --help|-h) shift 1 usage @@ -94,24 +101,26 @@ function main() { echo "Running integration suite (cached: ${cached}, parallel: ${parallel})" - specs::run "${cached}" "${parallel}" "${stack}" "${platform}" "${token:-}" + specs::run "${cached}" "${parallel}" "${stack}" "${platform}" "${token:-}" "${keep_failed}" done } function specs::run() { - local cached parallel stack platform token + local cached parallel stack platform token keep_failed cached="${1}" parallel="${2}" stack="${3}" platform="${4}" token="${5}" + keep_failed="${6}" - local nodes cached_flag serial_flag platform_flag stack_flag token_flag + local nodes cached_flag serial_flag platform_flag stack_flag token_flag keep_failed_flag cached_flag="--cached=${cached}" serial_flag="--serial=true" platform_flag="--platform=${platform}" stack_flag="--stack=${stack}" token_flag="--github-token=${token}" + keep_failed_flag="" nodes=1 if [[ "${parallel}" == "true" ]]; then @@ -119,6 +128,10 @@ function specs::run() { serial_flag="" fi + if [[ "${keep_failed}" == "true" ]]; then + keep_failed_flag="--keep-failed-containers" + fi + local buildpack_file buildpack_file="$(buildpack::package "1.2.3" "${cached}" "${stack}")" @@ -131,11 +144,12 @@ function specs::run() { -mod vendor \ -v \ "${src}/integration" \ - "${cached_flag}" \ - "${platform_flag}" \ - "${token_flag}" \ - "${stack_flag}" \ - "${serial_flag}" + ${cached_flag} \ + ${platform_flag} \ + ${token_flag} \ + ${stack_flag} \ + ${serial_flag} \ + ${keep_failed_flag} } function buildpack::package() { diff --git a/src/ruby/integration/cache_test.go b/src/ruby/integration/cache_test.go index bd9e32db6..6a7f8eda0 100644 --- a/src/ruby/integration/cache_test.go +++ b/src/ruby/integration/cache_test.go @@ -32,7 +32,9 @@ func testCache(platform switchblade.Platform, fixtures string) func(*testing.T, }) it.After(func() { - Expect(platform.Delete.Execute(name)).To(Succeed()) + if name != "" && (!settings.KeepFailedContainers || !t.Failed()) { + Expect(platform.Delete.Execute(name)).To(Succeed()) + } }) it("uses the cache for manifest dependencies when deployed twice", func() { diff --git a/src/ruby/integration/default_test.go b/src/ruby/integration/default_test.go index cd800f65b..68d23166c 100644 --- a/src/ruby/integration/default_test.go +++ b/src/ruby/integration/default_test.go @@ -29,7 +29,9 @@ func testDefault(platform switchblade.Platform, fixtures string) func(*testing.T }) it.After(func() { - Expect(platform.Delete.Execute(name)).To(Succeed()) + if name != "" && (!settings.KeepFailedContainers || !t.Failed()) { + Expect(platform.Delete.Execute(name)).To(Succeed()) + } }) context("when the ruby version is specified in the app", func() { diff --git a/src/ruby/integration/init_test.go b/src/ruby/integration/init_test.go index e3ca10d80..3149836cd 100644 --- a/src/ruby/integration/init_test.go +++ b/src/ruby/integration/init_test.go @@ -24,17 +24,19 @@ var settings struct { Path string } - Cached bool - Serial bool - FixturesPath string - GitHubToken string - Platform string - Stack string + Cached bool + Serial bool + KeepFailedContainers bool + FixturesPath string + GitHubToken string + Platform string + Stack string } func init() { flag.BoolVar(&settings.Cached, "cached", false, "run cached buildpack tests") flag.BoolVar(&settings.Serial, "serial", false, "run serial buildpack tests") + flag.BoolVar(&settings.KeepFailedContainers, "keep-failed-containers", false, "preserve failed test containers for debugging") flag.StringVar(&settings.Platform, "platform", "cf", `switchblade platform to test against ("cf" or "docker")`) flag.StringVar(&settings.GitHubToken, "github-token", "", "use the token to make GitHub API requests") flag.StringVar(&settings.Stack, "stack", "cflinuxfs4", "stack to use as default when pusing apps") diff --git a/src/ruby/integration/multibuildpack_test.go b/src/ruby/integration/multibuildpack_test.go index cc17c7b7e..da6632786 100644 --- a/src/ruby/integration/multibuildpack_test.go +++ b/src/ruby/integration/multibuildpack_test.go @@ -27,7 +27,9 @@ func testMultiBuildpack(platform switchblade.Platform, fixtures string) func(*te }) it.After(func() { - Expect(platform.Delete.Execute(name)).To(Succeed()) + if name != "" && (!settings.KeepFailedContainers || !t.Failed()) { + Expect(platform.Delete.Execute(name)).To(Succeed()) + } }) context("when ruby is a supply for the binary buildpack", func() { diff --git a/src/ruby/integration/offline_test.go b/src/ruby/integration/offline_test.go index ab5d9172e..b1e204671 100644 --- a/src/ruby/integration/offline_test.go +++ b/src/ruby/integration/offline_test.go @@ -27,7 +27,9 @@ func testOffline(platform switchblade.Platform, fixtures string) func(*testing.T }) it.After(func() { - Expect(platform.Delete.Execute(name)).To(Succeed()) + if name != "" && (!settings.KeepFailedContainers || !t.Failed()) { + Expect(platform.Delete.Execute(name)).To(Succeed()) + } }) it("runs a vendored cached app", func() { diff --git a/src/ruby/integration/override_test.go b/src/ruby/integration/override_test.go index 8220e1f95..da3a7daae 100644 --- a/src/ruby/integration/override_test.go +++ b/src/ruby/integration/override_test.go @@ -26,7 +26,9 @@ func testOverride(platform switchblade.Platform, fixtures string) func(*testing. }) it.After(func() { - Expect(platform.Delete.Execute(name)).To(Succeed()) + if name != "" && (!settings.KeepFailedContainers || !t.Failed()) { + Expect(platform.Delete.Execute(name)).To(Succeed()) + } }) it("forces node from override buildpack", func() { diff --git a/src/ruby/integration/proxy_test.go b/src/ruby/integration/proxy_test.go index 83e415205..7e4b1eec2 100644 --- a/src/ruby/integration/proxy_test.go +++ b/src/ruby/integration/proxy_test.go @@ -27,7 +27,9 @@ func testProxy(platform switchblade.Platform, fixtures, uri string) func(*testin }) it.After(func() { - Expect(platform.Delete.Execute(name)).To(Succeed()) + if name != "" && (!settings.KeepFailedContainers || !t.Failed()) { + Expect(platform.Delete.Execute(name)).To(Succeed()) + } }) it("builds an app with the proxy set", func() {