From 75eccbfc3a1df8809d145ce5d1ad2f3c72b43e81 Mon Sep 17 00:00:00 2001 From: Bryce Kwon Date: Sat, 31 Oct 2026 14:52:28 -0700 Subject: Write the snapshot header and content checks once --- tests/t0110-snapshot.sh | 40 +++++++++++++++++++--------------------- 1 file changed, 19 insertions(+), 21 deletions(-) (limited to 'tests/t0110-snapshot.sh') diff --git a/tests/t0110-snapshot.sh b/tests/t0110-snapshot.sh index 6221efc..5478114 100755 --- a/tests/t0110-snapshot.sh +++ b/tests/t0110-snapshot.sh @@ -10,6 +10,19 @@ test_description='Verify snapshot' . ./setup.sh +check_snapshot_headers() { + head -n 1 tmp | grep "Status: 200 OK" && + head -n 2 tmp | grep "^Content-Type: $2$" && + head -n 3 tmp | grep "Content-Disposition: inline; filename=.master.$1." +} + +check_snapshot_content() { + ls master/ >output && + test_line_count = 5 output && + grep "^5$" master/file-5 && + test_line_count = 1 master/file-5 +} + # Registers the checks for one compressed tar format. test_tar_snapshot() { ext=$1 @@ -24,9 +37,7 @@ test_tar_snapshot() { " test_expect_success $prereq "check $ext response headers" " - head -n 1 tmp | grep 'Status: 200 OK' && - head -n 2 tmp | grep '^Content-Type: $type\$' && - head -n 3 tmp | grep 'Content-Disposition: inline; filename=.master.$ext.' + check_snapshot_headers $ext $type " test_expect_success $prereq "verify $ext format" " @@ -37,10 +48,7 @@ test_tar_snapshot() { test_expect_success $prereq "untar $ext and verify the content" " rm -rf master && '$tool' -dc 'master.$ext' | tar -xf - && - ls master/ >output && - test_line_count = 5 output && - grep '^5\$' master/file-5 && - test_line_count = 1 master/file-5 + check_snapshot_content " } @@ -51,19 +59,14 @@ test_expect_success 'get foo/snapshot/master.tar' ' ' test_expect_success 'check tar response headers' ' - head -n 1 tmp | grep "Status: 200 OK" && - head -n 2 tmp | grep "^Content-Type: application/x-tar$" && - head -n 3 tmp | grep "Content-Disposition: inline; filename=.master.tar." + check_snapshot_headers tar application/x-tar ' test_expect_success 'untar and verify the content' ' strip_headers master.tar && rm -rf master && tar -xf master.tar && - ls master/ >output && - test_line_count = 5 output && - grep "^5$" master/file-5 && - test_line_count = 1 master/file-5 + check_snapshot_content ' test_tar_snapshot tar.gz application/gzip gzip GZIP @@ -77,9 +80,7 @@ test_expect_success 'get foo/snapshot/master.zip' ' ' test_expect_success 'check zip response headers' ' - head -n 1 tmp | grep "Status: 200 OK" && - head -n 2 tmp | grep "^Content-Type: application/zip$" && - head -n 3 tmp | grep "Content-Disposition: inline; filename=.master.zip." + check_snapshot_headers zip application/zip ' test_expect_success 'strip off the header lines' ' @@ -93,10 +94,7 @@ test_expect_success UNZIP 'verify zip format' ' test_expect_success UNZIP 'unzip and verify the content' ' rm -rf master && "$GIT_UNZIP" master.zip && - ls master/ >output && - test_line_count = 5 output && - grep "^5$" master/file-5 && - test_line_count = 1 master/file-5 + check_snapshot_content ' # A tag named v1.0 sheds its v in the snapshot name unless dropping it would -- cgit