3 test_description
="Test bundle-uri bundle_uri_parse_line()"
6 TEST_PASSES_SANITIZE_LEAK
=true
9 test_expect_success
'bundle_uri_parse_line() just URIs' '
11 bundle.one.uri=http://example.com/bundle.bdl
12 bundle.two.uri=https://example.com/bundle.bdl
13 bundle.three.uri=file:///usr/share/git/bundle.bdl
16 cat >expect <<-\EOF &&
21 uri = http://example.com/bundle.bdl
23 uri = https://example.com/bundle.bdl
25 uri = file:///usr/share/git/bundle.bdl
28 test-tool bundle-uri parse-key-values in >actual 2>err &&
29 test_must_be_empty err &&
30 test_cmp_config_output expect actual
33 test_expect_success
'bundle_uri_parse_line(): relative URIs' '
35 bundle.one.uri=bundle.bdl
36 bundle.two.uri=../bundle.bdl
37 bundle.three.uri=sub/dir/bundle.bdl
40 cat >expect <<-\EOF &&
45 uri = <uri>/bundle.bdl
49 uri = <uri>/sub/dir/bundle.bdl
52 test-tool bundle-uri parse-key-values in >actual 2>err &&
53 test_must_be_empty err &&
54 test_cmp_config_output expect actual
57 test_expect_success
'bundle_uri_parse_line(): relative URIs and parent paths' '
59 bundle.one.uri=bundle.bdl
60 bundle.two.uri=../bundle.bdl
61 bundle.three.uri=../../bundle.bdl
64 cat >expect <<-\EOF &&
69 uri = <uri>/bundle.bdl
73 uri = <uri>/../bundle.bdl
76 # TODO: We would prefer if parsing a bundle list would not cause
77 # a die() and instead would give a warning and allow the rest of
78 # a Git command to continue. This test_must_fail is necessary for
79 # now until the interface for relative_url() allows for reporting
80 # an error instead of die()ing.
81 test_must_fail test-tool bundle-uri parse-key-values in >actual 2>err &&
82 grep "fatal: cannot strip one component off url" err
85 test_expect_success
'bundle_uri_parse_line() parsing edge cases: empty key or value' '
91 cat >err.expect <<-EOF &&
92 error: bundle-uri: line has empty key or value
93 error: bad line: '\''=bogus-value'\''
94 error: bundle-uri: line has empty key or value
95 error: bad line: '\''bogus-key='\''
98 cat >expect <<-\EOF &&
104 test_must_fail test-tool bundle-uri parse-key-values in >actual 2>err &&
105 test_cmp err.expect err &&
106 test_cmp_config_output expect actual
109 test_expect_success
'bundle_uri_parse_line() parsing edge cases: empty lines' '
111 bundle.one.uri=http://example.com/bundle.bdl
113 bundle.two.uri=https://example.com/bundle.bdl
115 bundle.three.uri=file:///usr/share/git/bundle.bdl
118 cat >err.expect <<-\EOF &&
119 error: bundle-uri: got an empty line
120 error: bad line: '\'''\''
121 error: bundle-uri: got an empty line
122 error: bad line: '\'''\''
125 # We fail, but try to continue parsing regardless
126 cat >expect <<-\EOF &&
131 uri = http://example.com/bundle.bdl
133 uri = https://example.com/bundle.bdl
135 uri = file:///usr/share/git/bundle.bdl
138 test_must_fail test-tool bundle-uri parse-key-values in >actual 2>err &&
139 test_cmp err.expect err &&
140 test_cmp_config_output expect actual
143 test_expect_success
'bundle_uri_parse_line() parsing edge cases: duplicate lines' '
145 bundle.one.uri=http://example.com/bundle.bdl
146 bundle.two.uri=https://example.com/bundle.bdl
147 bundle.one.uri=https://example.com/bundle-2.bdl
148 bundle.three.uri=file:///usr/share/git/bundle.bdl
151 cat >err.expect <<-\EOF &&
152 error: bad line: '\''bundle.one.uri=https://example.com/bundle-2.bdl'\''
155 # We fail, but try to continue parsing regardless
156 cat >expect <<-\EOF &&
161 uri = http://example.com/bundle.bdl
163 uri = https://example.com/bundle.bdl
165 uri = file:///usr/share/git/bundle.bdl
168 test_must_fail test-tool bundle-uri parse-key-values in >actual 2>err &&
169 test_cmp err.expect err &&
170 test_cmp_config_output expect actual
173 test_expect_success
'parse config format: just URIs' '
174 cat >expect <<-\EOF &&
179 uri = http://example.com/bundle.bdl
181 uri = https://example.com/bundle.bdl
183 uri = file:///usr/share/git/bundle.bdl
186 test-tool bundle-uri parse-config expect >actual 2>err &&
187 test_must_be_empty err &&
188 test_cmp_config_output expect actual
191 test_expect_success
'parse config format: relative URIs' '
201 uri = sub/dir/bundle.bdl
204 cat >expect <<-\EOF &&
209 uri = <uri>/bundle.bdl
213 uri = <uri>/sub/dir/bundle.bdl
216 test-tool bundle-uri parse-config in >actual 2>err &&
217 test_must_be_empty err &&
218 test_cmp_config_output expect actual
221 test_expect_success
'parse config format edge cases: empty key or value' '
227 error: bad config line 1 in file in1
230 cat >expect <<-\EOF &&
236 test_must_fail test-tool bundle-uri parse-config in1 >actual 2>err &&
238 test_cmp_config_output expect actual &&
245 error: bad config line 1 in file in2
248 test_must_fail test-tool bundle-uri parse-config in2 >actual 2>err &&
250 test_cmp_config_output expect actual
253 test_expect_success
'parse config format: creationToken heuristic' '
254 cat >expect <<-\EOF &&
258 heuristic = creationToken
260 uri = http://example.com/bundle.bdl
261 creationToken = 123456
263 uri = https://example.com/bundle.bdl
264 creationToken = 12345678901234567890
266 uri = file:///usr/share/git/bundle.bdl
270 test-tool bundle-uri parse-config expect >actual 2>err &&
271 test_must_be_empty err &&
272 test_cmp_config_output expect actual
275 test_expect_success
'parse config format edge cases: creationToken heuristic' '
276 cat >expect <<-\EOF &&
280 heuristic = creationToken
282 uri = http://example.com/bundle.bdl
283 creationToken = bogus
286 test-tool bundle-uri parse-config expect >actual 2>err &&
287 grep "could not parse bundle list key creationToken with value '\''bogus'\''" err