Skip to content

Commit 9bae8eb

Browse files
committed
t: add object presence assertion for SSH remotes
In subsequent commits in this PR we expect to resolve a pair of issues which prevent us from testing the SSH object transfer protocol with more than a single object. The SSH transfer protocol was introduced in PR git-lfs#4446, and in commit 691de51 of that PR, the "batch transfers with ssh endpoint (git-lfs-transfer)" test in our t/t-batch-transfer.sh test script was added to validate that the new protocol worked as expected. This test pushes and then fetches a single object, so the issues which arise when handling multiple objects in a batch do not cause the test to fail. Hence we intend to add two other tests to accompany the existing one so as to validate the SSH transfer protocol with multiple objects. As these tests will all perform object transfers only over SSH, our HTTP-based lfstest-gitserver test helper program will not be used in any of them. That program retains a copy of each object it receives in memory to simulate a remote Git LFS server. As a consequence, many of our tests use the assert_server_object() function defined in our t/testhelpers.sh library to confirm that an object has been received by the remote server; this function makes an HTTP batch request to the lfstest-gitserver program and checks the JSON response. In our tests of the SSH transfer protocol, by contrast, object data will be proxied by the lfs-ssh-echo helper program to the git-lfs-transfer command, which will write the data into a separate bare Git repository in the location provided as command argument. In fact this is how the existing test already operates; it uses the ssh_remote() function from our t/testhelpers.sh library to establish the SSH URL for its remote repository. The URLs returned by this function always include the directory path from our REMOTEDIR variable. We expect to also use the ssh_remote() function in our new tests to establish their remote repositories. In both our existing test and the ones we will add in a subsequent commit in this PR, we would like to confirm that the Git LFS objects we push have been successfully written into the "lfs/objects" cache in the remote repositories. To simplify such checks, we define a new assert_remote_object() assertion function in our shell test library. Unlike the assert_server_object() function, which makes an HTTP request, our new assertion acts in a similar manner to the existing assert_local_object() function by simply validating the size and existence of an object file in the appropriate subdirectory of the "lfs/objects" cache hierarchy of a bare repository. However, our new assert_remote_object() function constructs the path to the repository using the REMOTEDIR variable, rather than checking the object's presence in the current local repository as the assert_local_object() function does. With the assert_remote_object() function defined, we then update our existing "batch transfers with ssh endpoint (git-lfs-transfer)" test to make use of it after pushing an object over the SSH transfer protocol, and we will use the function for the same purpose in the additional tests we expect to introduce in a later commit in this PR.
1 parent 39f9786 commit 9bae8eb

File tree

2 files changed

+17
-0
lines changed

2 files changed

+17
-0
lines changed

t/t-batch-transfer.sh

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -186,6 +186,7 @@ begin_test "batch transfers with ssh endpoint (git-lfs-transfer)"
186186

187187
GIT_TRACE=1 git push origin main >push.log 2>&1
188188
grep "lfs-ssh-echo.*git-lfs-transfer .*$reponame.git upload" push.log
189+
assert_remote_object "$reponame" "$(calc_oid "$contents")" "${#contents}"
189190

190191
cd ..
191192
GIT_TRACE=1 git clone "$sshurl" "$reponame-2" 2>&1 | tee trace.log

t/testhelpers.sh

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -176,6 +176,22 @@ assert_server_object() {
176176
}
177177
}
178178

179+
# assert_remote_object() confirms that an object file with the given OID and
180+
# size is stored in the "remote" copy of a repository
181+
assert_remote_object() {
182+
local reponame="$1"
183+
local oid="$2"
184+
local size="$3"
185+
local destination="$(canonical_path "$REMOTEDIR/$reponame.git")"
186+
187+
pushd "$destination"
188+
local cfg="$(git lfs env | grep LocalMediaDir)"
189+
local f="${cfg:14}/${oid:0:2}/${oid:2:2}/$oid"
190+
actualsize="$(wc -c <"$f" | tr -d '[[:space:]]')"
191+
[ "$size" -eq "$actualsize" ]
192+
popd
193+
}
194+
179195
check_server_lock_ssh() {
180196
local reponame="$1"
181197
local id="$2"

0 commit comments

Comments
 (0)