t5730: introduce fetch command helper

Assembling a "raw" fetch command to be fed directly to "test-tool serve-v2" is extracted into a test helper. Suggested-by: Junio C Hamano <gitster@pobox.com> Signed-off-by: Kim Altintop <kim@eagain.st> Reviewed-by: Jonathan Tan <jonathantanmy@google.com> Signed-off-by: Junio C Hamano <gitster@pobox.com>

Kim Altintop committed Aug 13, 2021 at 06:23 UTC bac01c6469b2489042b867d409894a3152ec98a1
1 file changed +37 -36
t/t5703-upload-pack-ref-in-want.sh
+37 -36
@@ -40,6 +40,30 @@ write_command () {
40 fi
41 }
42
43 +# Write a complete fetch command to stdout, suitable for use with `test-tool
44 +# pkt-line`. "want-ref", "want", and "have" lines are read from stdin.
45 +#
46 +# Examples:
47 +#
48 +# write_fetch_command <<-EOF
49 +# want-ref refs/heads/main
50 +# have $(git rev-parse a)
51 +# EOF
52 +#
53 +# write_fetch_command <<-EOF
54 +# want $(git rev-parse b)
55 +# have $(git rev-parse a)
56 +# EOF
57 +#
58 +write_fetch_command () {
59 + write_command fetch &&
60 + echo "0001" &&
61 + echo "no-progress" &&
62 + cat &&
63 + echo "done" &&
64 + echo "0000"
65 +}
66 +
67 # c(o/foo) d(o/bar)
68 # \ /
69 # b e(baz) f(main)
@@ -77,15 +101,11 @@ test_expect_success 'config controls ref-in-want advertisement' '
101 '
102
103 test_expect_success 'invalid want-ref line' '
80 - test-tool pkt-line pack >in <<-EOF &&
81 - $(write_command fetch)
82 - 0001
83 - no-progress
104 + write_fetch_command >pkt <<-EOF &&
105 want-ref refs/heads/non-existent
85 - done
86 - 0000
106 EOF
107
108 + test-tool pkt-line pack <pkt >in &&
109 test_must_fail test-tool serve-v2 --stateless-rpc 2>out <in &&
110 grep "unknown ref" out
111 '
@@ -97,16 +117,11 @@ test_expect_success 'basic want-ref' '
117 EOF
118 git rev-parse f >expected_commits &&
119
100 - oid=$(git rev-parse a) &&
101 - test-tool pkt-line pack >in <<-EOF &&
102 - $(write_command fetch)
103 - 0001
104 - no-progress
120 + write_fetch_command >pkt <<-EOF &&
121 want-ref refs/heads/main
106 - have $oid
107 - done
108 - 0000
122 + have $(git rev-parse a)
123 EOF
124 + test-tool pkt-line pack <pkt >in &&
125
126 test-tool serve-v2 --stateless-rpc >out <in &&
127 check_output
@@ -121,17 +136,12 @@ test_expect_success 'multiple want-ref lines' '
136 EOF
137 git rev-parse c d >expected_commits &&
138
124 - oid=$(git rev-parse b) &&
125 - test-tool pkt-line pack >in <<-EOF &&
126 - $(write_command fetch)
127 - 0001
128 - no-progress
139 + write_fetch_command >pkt <<-EOF &&
140 want-ref refs/heads/o/foo
141 want-ref refs/heads/o/bar
131 - have $oid
132 - done
133 - 0000
142 + have $(git rev-parse b)
143 EOF
144 + test-tool pkt-line pack <pkt >in &&
145
146 test-tool serve-v2 --stateless-rpc >out <in &&
147 check_output
@@ -144,16 +154,12 @@ test_expect_success 'mix want and want-ref' '
154 EOF
155 git rev-parse e f >expected_commits &&
156
147 - test-tool pkt-line pack >in <<-EOF &&
148 - $(write_command fetch)
149 - 0001
150 - no-progress
157 + write_fetch_command >pkt <<-EOF &&
158 want-ref refs/heads/main
159 want $(git rev-parse e)
160 have $(git rev-parse a)
154 - done
155 - 0000
161 EOF
162 + test-tool pkt-line pack <pkt >in &&
163
164 test-tool serve-v2 --stateless-rpc >out <in &&
165 check_output
@@ -166,16 +172,11 @@ test_expect_success 'want-ref with ref we already have commit for' '
172 EOF
173 >expected_commits &&
174
169 - oid=$(git rev-parse c) &&
170 - test-tool pkt-line pack >in <<-EOF &&
171 - $(write_command fetch)
172 - 0001
173 - no-progress
175 + write_fetch_command >pkt <<-EOF &&
176 want-ref refs/heads/o/foo
175 - have $oid
176 - done
177 - 0000
177 + have $(git rev-parse c)
178 EOF
179 + test-tool pkt-line pack <pkt >in &&
180
181 test-tool serve-v2 --stateless-rpc >out <in &&
182 check_output