From c4b882036d272cc276cbf3a0d108244893c3c8af Mon Sep 17 00:00:00 2001 From: Eric Wong Date: Sun, 1 Jan 2023 10:54:40 +0000 Subject: [PATCH] t/solver_git.t: avoid redundant work for snapshot test We only have to generate the expected tarball and checksum once for testing both -httpd and generic PSGI. And drop the redundant length check since the SHA-256 check is sufficient. This saves 20-30ms on my system. --- t/solver_git.t | 19 +++++++++++++------ 1 file changed, 13 insertions(+), 6 deletions(-) diff --git a/t/solver_git.t b/t/solver_git.t index d8942747..82222031 100644 --- a/t/solver_git.t +++ b/t/solver_git.t @@ -263,6 +263,16 @@ SKIP: { cgiturl = http://example.com/binfoo EOF close $cfgfh or die; + my $exp_digest; + { + my $exp = xqx([qw(git archive --format=tar.gz + --prefix=public-inbox-1.0.0/ v1.0.0)], + { GIT_DIR => $git_dir }); + is($?, 0, 'no error from git archive'); + ok(length($exp) > 1024, 'expected archive generated'); + $exp_digest = git_sha(256, \$exp)->hexdigest; + }; + my $cfg = PublicInbox::Config->new($cfgpath); my $www = PublicInbox::WWW->new($cfg); my $client = sub { @@ -341,14 +351,11 @@ EOF is($res->header('Content-Disposition'), qq'inline; filename="$fn"', 'c-d header'); is($res->header('ETag'), qq'"$v1_0_0_rev"', 'etag header'); - my $exp = xqx([qw(git archive --format=tar.gz - --prefix=public-inbox-1.0.0/ v1.0.0)], - { GIT_DIR => $git_dir }); + my $got = $res->content; - is(length($got), length($exp), - "length matches installed `git archive' output") and - is(git_sha(1, \$got)->hexdigest, git_sha(1, \$exp)->hexdigest, + is(git_sha(256, \$got)->hexdigest, $exp_digest, "content matches installed `git archive' output"); + undef $got; $fn = 'public-inbox-1.0.2.tar.gz'; $res = $cb->(GET("/public-inbox/snapshot/$fn")); -- 2.44.0