@@ -11,6 +11,8 @@ setup() {
11
11
test_filter
12
12
export GO_SCRIPT_BASH_VERSION=" $_GO_CORE_VERSION "
13
13
export GO_SCRIPTS_DIR=" $_GO_TEST_DIR /tmp/go-template-test-scripts"
14
+ export GO_SCRIPT_BASH_REPO_URL=" https://github.com/mbland/go-script-bash.git"
15
+ export GO_SCRIPT_BASH_DOWNLOAD_URL=" ${GO_SCRIPT_BASH_REPO_URL% .git} /archive"
14
16
}
15
17
16
18
teardown () {
@@ -24,7 +26,7 @@ teardown() {
24
26
assert_output_matches " Usage: $_GO_CORE_DIR /go-template <command>"
25
27
}
26
28
27
- @test " $SUITE : download the go-script-bash release from $GO_CORE_URL " {
29
+ @test " $SUITE : download the go-script-bash release from $GO_SCRIPT_BASH_REPO_URL " {
28
30
run " $_GO_CORE_DIR /go-template"
29
31
30
32
# Without a command argument, the script will print the top-level help and
@@ -42,16 +44,77 @@ teardown() {
42
44
43
45
@test " $SUITE : fail to download a nonexistent repo" {
44
46
GO_SCRIPT_BASH_REPO_URL=' bogus-repo-that-does-not-exist' \
47
+ GO_SCRIPT_BASH_DOWNLOAD_URL=' bogus-url-that-does-not-exist' \
45
48
run " $_GO_CORE_DIR /go-template"
46
- assert_failure " Downloading framework from 'bogus-repo-that-does-not-exist/archive/$GO_SCRIPT_BASH_VERSION .tar.gz'..." \
47
- " curl: (6) Could not resolve host: bogus-repo-that-does-not-exist" \
48
- " Failed to download from 'bogus-repo-that-does-not-exist/archive/$GO_SCRIPT_BASH_VERSION .tar.gz'; aborting."
49
+ assert_failure " Downloading framework from 'bogus-url-that-does-not-exist/$GO_SCRIPT_BASH_VERSION .tar.gz'..." \
50
+ " curl: (6) Could not resolve host: bogus-url-that-does-not-exist" \
51
+ " Failed to download from 'bogus-url-that-does-not-exist/$GO_SCRIPT_BASH_VERSION .tar.gz'." \
52
+ " Using git clone as fallback" \
53
+ " Cloning framework from 'bogus-repo-that-does-not-exist'..." \
54
+ " fatal: repository 'bogus-repo-that-does-not-exist' does not exist" \
55
+ " Failed to clone 'bogus-repo-that-does-not-exist'; aborting."
49
56
}
50
57
51
58
@test " $SUITE : fail to download a nonexistent version" {
52
59
GO_SCRIPT_BASH_VERSION=' vnonexistent' \
53
60
run " $_GO_CORE_DIR /go-template"
54
61
assert_failure " Downloading framework from 'https://github.com/mbland/go-script-bash/archive/vnonexistent.tar.gz'..." \
55
62
" curl: (22) The requested URL returned error: 404 Not Found" \
56
- " Failed to download from 'https://github.com/mbland/go-script-bash/archive/vnonexistent.tar.gz'; aborting."
63
+ " Failed to download from 'https://github.com/mbland/go-script-bash/archive/vnonexistent.tar.gz'." \
64
+ " Using git clone as fallback" \
65
+ " Cloning framework from 'https://github.com/mbland/go-script-bash.git'..." \
66
+ " Cloning into '/Users/paquete/octobot/repos/go-script-bash/tests/tmp/go-template-test-scripts/go-script-bash'..." \
67
+ " warning: Could not find remote branch vnonexistent to clone." \
68
+ " fatal: Remote branch vnonexistent not found in upstream origin" \
69
+ " Failed to clone 'https://github.com/mbland/go-script-bash.git'; aborting."
57
70
}
71
+
72
+ @test " $SUITE : fail to find curl uses git clone" {
73
+ PATH=" $BATS_TEST_BINDIR :$PATH "
74
+ stub_program_in_path curl " exit 1"
75
+ run " $_GO_CORE_DIR /go-template"
76
+ restore_program_in_path curl
77
+
78
+ # Without a command argument, the script will print the top-level help and
79
+ # return an error, but the core repo should exist as expected.
80
+ assert_output_matches " Failed to find cURL or tar"
81
+ assert_output_matches " Using git clone as fallback"
82
+ assert_output_matches " Cloning framework from '$GO_SCRIPT_BASH_REPO_URL '\.\.\."
83
+
84
+ # Use `.*/scripts/go-script-bash` to account for the fact that `git clone` on
85
+ # MSYS2 will output `C:/Users/<user>/AppData/Local/Temp/` in place of `/tmp`.
86
+ assert_output_matches " Cloning into '.*/$GO_SCRIPTS_DIR /go-script-bash'\.\.\."
87
+ assert_output_matches " Clone of '$GO_SCRIPT_BASH_REPO_URL ' successful\." $' \n\n '
88
+ assert_output_matches " Usage: $_GO_CORE_DIR /go-template <command>"
89
+ [[ -f " $_GO_ROOTDIR /$GO_SCRIPTS_DIR /go-script-bash/go-core.bash" ]]
90
+
91
+ cd " $_GO_ROOTDIR /$GO_SCRIPTS_DIR /go-script-bash"
92
+ run git log --oneline -n 1
93
+ assert_success
94
+ assert_output_matches " go-script-bash $_GO_CORE_VERSION "
95
+ }
96
+
97
+ @test " $SUITE : fail to find tar uses git clone" {
98
+ PATH=" $BATS_TEST_BINDIR :$PATH "
99
+ stub_program_in_path tar " exit 1"
100
+ run " $_GO_CORE_DIR /go-template"
101
+ restore_program_in_path tar
102
+
103
+ # Without a command argument, the script will print the top-level help and
104
+ # return an error, but the core repo should exist as expected.
105
+ assert_output_matches " Failed to find cURL or tar"
106
+ assert_output_matches " Using git clone as fallback"
107
+ assert_output_matches " Cloning framework from '$GO_SCRIPT_BASH_REPO_URL '\.\.\."
108
+
109
+ # Use `.*/scripts/go-script-bash` to account for the fact that `git clone` on
110
+ # MSYS2 will output `C:/Users/<user>/AppData/Local/Temp/` in place of `/tmp`.
111
+ assert_output_matches " Cloning into '.*/$GO_SCRIPTS_DIR /go-script-bash'\.\.\."
112
+ assert_output_matches " Clone of '$GO_SCRIPT_BASH_REPO_URL ' successful\." $' \n\n '
113
+ assert_output_matches " Usage: $_GO_CORE_DIR /go-template <command>"
114
+ [[ -f " $_GO_ROOTDIR /$GO_SCRIPTS_DIR /go-script-bash/go-core.bash" ]]
115
+
116
+ cd " $_GO_ROOTDIR /$GO_SCRIPTS_DIR /go-script-bash"
117
+ run git log --oneline -n 1
118
+ assert_success
119
+ assert_output_matches " go-script-bash $_GO_CORE_VERSION "
120
+ }
0 commit comments