Skip to content

Commit 303485e

Browse files
committed
template: Add TEST_USE_REAL_URL to fix Travis
See the comments for `TEST_USE_REAL_URL` in `tests/template.bats` as well as: https://travis-ci.org/mbland/go-script-bash/jobs/200488089 https://travis-ci.org/mbland/go-script-bash/jobs/200488076
1 parent 1cb75cd commit 303485e

File tree

1 file changed

+25
-1
lines changed

1 file changed

+25
-1
lines changed

tests/template.bats

Lines changed: 25 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,33 @@
22

33
load environment
44

5+
# By default, the test will try to clone its own repo to avoid flakiness due to
6+
# an external dependency. However, doing so causes a failure on Travis, since it
7+
# uses shallow clones to produce test runs, resulting in the error:
8+
#
9+
# fatal: attempt to fetch/clone from a shallow repository
10+
#
11+
# However, since Travis already depends on having a good connection to GitHub,
12+
# we'll use the real URL. Alternatively, `git` could be stubbed out via
13+
# `stub_program_in_path` from `_GO_CORE_DIR/lib/bats/helpers`, but the potential
14+
# for neither flakiness nor complexity seems that great, and this approach
15+
# provides extra confidence that the mechanism works as advertised.
16+
#
17+
# A developer can also run the test locally against the real URL by setting
18+
# `TEST_USE_REAL_URL` on the command line. The value of `GO_CORE_URL` is
19+
# subsequently displayed in the name of the test case to validate which repo is
20+
# being used during the test run.
21+
TEST_USE_REAL_URL="${TEST_USE_REAL_URL:-$TRAVIS}"
22+
GO_CORE_URL="${TEST_USE_REAL_URL:+$_GO_CORE_URL}"
23+
GO_CORE_URL="${GO_CORE_URL:-$_GO_CORE_DIR}"
24+
525
setup() {
626
test_filter
727
mkdir "$TEST_GO_ROOTDIR"
28+
29+
if [[ -e "$GO_CORE_URL/.git/shallow" ]]; then
30+
skip "Can't clone shallow repositories"
31+
fi
832
}
933

1034
teardown() {
@@ -29,7 +53,7 @@ create_template_script() {
2953
chmod 700 "$TEST_GO_ROOTDIR/go-template"
3054
}
3155

32-
@test "$SUITE: clone the go-script-bash repository" {
56+
@test "$SUITE: clone the go-script-bash repository from $GO_CORE_URL" {
3357
create_template_script "$_GO_CORE_DIR" "$_GO_CORE_VERSION"
3458
run "$TEST_GO_ROOTDIR/go-template"
3559

0 commit comments

Comments
 (0)