11-git.t (2385B)
1 #!/usr/bin/env perl 2 3 use 5.16.0; 4 use strict; 5 use warnings FATAL => 'all'; 6 use Test::More; 7 use Capture::Tiny qw/ capture_merged /; 8 use FindBin '$RealBin'; 9 use lib $RealBin; 10 use Test::Sbotools qw/ set_gpg_verify set_repo sbosnap /; 11 12 if ($ENV{TEST_INSTALL}) { 13 plan tests => 5; 14 } else { 15 plan skip_all => 'Only run these tests if TEST_INSTALL=1'; 16 } 17 18 sub cleanup { 19 capture_merged { 20 system(qw!rm -rf !, "/tmp/gitrepo"); 21 if (defined $ENV{TRAVIS} and $ENV{TRAVIS} eq 'true') { 22 system(qw!userdel test!); 23 system(qw!groupdel test!); 24 } 25 }; 26 } 27 28 sub slurp { 29 my $file = shift; 30 local $/; 31 open my $fh, '<', $file or return undef; 32 my $contents = <$fh>; 33 return $contents; 34 } 35 36 cleanup(); 37 38 # initialise repo 39 capture_merged { system(<<"END"); }; 40 rm -fr /tmp/gitrepo; 41 mkdir -p /tmp/gitrepo; 42 cd /tmp/gitrepo; 43 44 git init; 45 echo -n "Hello" > test; 46 git add test; 47 git commit -m 'initial'; 48 49 git checkout -b b1; 50 echo -n "Hello World." > test; 51 git commit -am 'branch commit'; 52 53 git checkout master; 54 echo -n "Hello World" > test; 55 git commit -am 'master commit'; 56 END 57 58 if (defined $ENV{TRAVIS} and $ENV{TRAVIS} eq 'true') { 59 capture_merged { system(<<"END"); }; 60 groupadd -g 199 test 61 useradd -u 199 -g 199 -d /tmp test 62 chown -R 199:199 /tmp/gitrepo 63 64 git config --system --add safe.directory /tmp/gitrepo/.git 65 END 66 } 67 68 set_gpg_verify('FALSE'); 69 set_repo("/tmp/gitrepo/"); 70 71 # 1: sbosnap get initial repo 72 sbosnap 'fetch', { expected => qr!Pulling SlackBuilds tree.*Cloning into '/usr/sbo/repo'!s }; 73 74 # 2-3: check ownership of repodir if under TRAVIS 75 SKIP: { 76 skip "Only run under Travis CI", 2 unless defined $ENV{TRAVIS} and $ENV{TRAVIS} eq 'true'; 77 78 my @fnames = glob "/tmp/gitrepo/.git/objects/*/*"; 79 80 my @stat = stat shift @fnames; 81 is ($stat[4], 199, "Correct owner uid for /tmp/gitrepo"); 82 is ($stat[5], 199, "Correct owner gid for /tmp/gitrepo"); 83 } 84 85 # make a conflict 86 capture_merged { system(<<"END"); }; 87 cd /tmp/gitrepo 88 if find /tmp/gitrepo . -maxdepth 0 -user test; then 89 sudo -u test git reset --hard b1 90 else 91 git reset --hard b1 92 fi 93 END 94 95 # 4: sbosnap update through merge conflict 96 sbosnap 'update', { expected => qr!Updating SlackBuilds tree.*master.*->.*origin/master.*forced update.*HEAD is now at!s }; 97 98 # 5: make sure test repo is merged correctly 99 is (slurp('/usr/sbo/repo/test'), 'Hello World.', 'repo test file updated correctly'); 100 101 # Cleanup 102 END { 103 cleanup(); 104 }