|
| 1 | +#!/usr/bin/env bats |
| 2 | + |
| 3 | +source test/e2e/helpers.sh |
| 4 | + |
| 5 | +setup() { |
| 6 | + load 'bats/support/load' |
| 7 | + load 'bats/assert/load' |
| 8 | + load 'bats/file/load' |
| 9 | +} |
| 10 | + |
| 11 | +teardown() { |
| 12 | + run kubectl delete builds.shipwright.io --all |
| 13 | + run kubectl delete buildruns.shipwright.io --all |
| 14 | + run kubectl delete buildstrategies.shipwright.io --all |
| 15 | +} |
| 16 | + |
| 17 | +@test "shp buildrun gather collects BuildRun diagnostics" { |
| 18 | + build_name=$(random_name) |
| 19 | + buildrun_name=$(random_name) |
| 20 | + output_image=$(get_output_image build-e2e) |
| 21 | + |
| 22 | + run shp build create ${build_name} \ |
| 23 | + --source-git-url=https://github.com/shipwright-io/sample-go \ |
| 24 | + --source-context-dir=source-build \ |
| 25 | + --output-image=${output_image} |
| 26 | + assert_success |
| 27 | + |
| 28 | + run shp buildrun create ${buildrun_name} --buildref-name=${build_name} |
| 29 | + assert_success |
| 30 | + |
| 31 | + # verify that logs exist |
| 32 | + run shp buildrun logs --follow ${buildrun_name} |
| 33 | + assert_success |
| 34 | + |
| 35 | + # verify gathering of buildrun diagnostics |
| 36 | + run shp buildrun gather ${buildrun_name} --output "${BATS_TEST_TMPDIR}" |
| 37 | + assert_success |
| 38 | + assert_output --partial "BuildRun diagnostics written to" |
| 39 | + |
| 40 | + gather_dir="${BATS_TEST_TMPDIR}/buildrun-${buildrun_name}-gather" |
| 41 | + assert_file_exist "${gather_dir}/buildrun.yaml" |
| 42 | + assert_file_exist "${gather_dir}/taskrun.yaml" |
| 43 | + assert_file_exist "${gather_dir}/pod.yaml" |
| 44 | + |
| 45 | + # ensure log files exist in logs/ directory |
| 46 | + run find "${gather_dir}/logs" -type f -name "*.log" |
| 47 | + assert_success |
| 48 | + refute_output "" |
| 49 | + |
| 50 | + # shp buildrun gather --archive writes diagnostics as a .tar.gz archive |
| 51 | + run shp buildrun gather ${buildrun_name} --output "${BATS_TEST_TMPDIR}/archive" --archive |
| 52 | + assert_success |
| 53 | + assert_file_exist "${BATS_TEST_TMPDIR}/archive/buildrun-${buildrun_name}-gather.tar.gz" |
| 54 | + refute_file_exist "${BATS_TEST_TMPDIR}/archive/buildrun-${buildrun_name}-gather" |
| 55 | +} |
0 commit comments