sbotools2

Maintenance fork of the original sbotools version 2
git clone git://git.server.ky/slackcoder/sbotools2
Log | Files | Refs | README

03-travis.t (8465B)


      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 lib "$RealBin/../SBO-Lib/lib";
     11 use Test::Sbotools qw/ sboconfig sbosnap sbofind sboinstall sboremove sbocheck sboupgrade /;
     12 
     13 if (defined $ENV{TRAVIS} and $ENV{TRAVIS} eq 'true') {
     14 	plan tests => 41;
     15 } else {
     16 	plan skip_all => 'Only run these tests under Travis CI (TRAVIS=true)';
     17 }
     18 $ENV{TEST_ONLINE} //= 0;
     19 
     20 # Since this is only run under Travis CI, we can blow away the repo without consequence
     21 system(qw! rm -rf /usr/sbo !);
     22 
     23 # Disable GPG verification
     24 sboconfig qw/ --gpg-key FALSE /;
     25 
     26 # 1-3: Test SLACKWARE_VERSION
     27 sboconfig qw/ -V 15.0 /, { expected => "Setting SLACKWARE_VERSION to 15.0...\n" };
     28 SKIP: {
     29 	skip 'Not doing online tests without TEST_ONLINE=1', 2 if $ENV{TEST_ONLINE} ne '1';
     30 
     31 	sbosnap 'fetch', { expected => qr/\APulling SlackBuilds tree\.\.\.\n/ };
     32 	sbofind 'sbotools', { expected => qr"SBo:\s+sbotools2\s+\d+[.]\d+[.]\d+\nPath:\s+/usr/sbo/repo/system/sbotools2\n" };
     33 }
     34 
     35 # 4-10: Test alternative REPO
     36 is (system(qw!rm -rf /usr/sbo!), 0, 'Removing /usr/sbo works');
     37 ok (! -e "/usr/sbo/repo/SLACKBUILDS.TXT", "SLACKBUILDS.TXT doesn't exist");
     38 sboconfig qw! -r https://github.com/Ponce/slackbuilds.git !, { expected => "Setting REPO to https://github.com/Ponce/slackbuilds.git...\n", name => 'Alternative REPO' };
     39 SKIP: {
     40 	skip 'Not doing online tests without TEST_ONLINE=1', 4 if $ENV{TEST_ONLINE} ne '1';
     41 
     42 	sbosnap 'fetch', { expected => qr!Pulling SlackBuilds tree.*Cloning into '/usr/sbo/repo'!s };
     43 	ok (-e "/usr/sbo/repo/SLACKBUILDS.TXT", "SLACKBUILDS.TXT exists (REPO)");
     44 	ok (! -e "/usr/sbo/repo/SLACKBUILDS.TXT.gz", "SLACKBUILDS.TXT.gz doesn't exist (REPO)");
     45 	sbofind 'sbotools', { expected => qr"SBo:    sbotools .*\nPath:   /usr/sbo/repo/system/sbotools\n\n" };
     46 }
     47 
     48 # 11-17: Test local overrides
     49 sboconfig '-o', "$RealBin/LO", { expected => "Setting LOCAL_OVERRIDES to $RealBin/LO...\n", name => 'LOCAL_OVERRIDES' };
     50 my $skip = 0;
     51 SKIP: {
     52 	if ($ENV{TEST_ONLINE} ne '1') { $skip = !(system(qw! mkdir -p /usr/sbo/repo !) == 0 and system(qw! touch /usr/sbo/repo/SLACKBUILDS.TXT !) == 0) }
     53 	skip "Online testing disabled (TEST_ONLINE!=1) and could not create dummy SLACKBUILDS.TXT", 9 if $skip;
     54 
     55 	sbofind 'nonexistentslackbuild', { expected => sub {
     56 m!\QLocal:  nonexistentslackbuild6 1.0
     57 Path:   $RealBin/LO/nonexistentslackbuild6!
     58 	and
     59 m!\QLocal:  nonexistentslackbuild5 1.0
     60 Path:   $RealBin/LO/nonexistentslackbuild5!
     61 	and
     62 m!\QLocal:  nonexistentslackbuild4 1.0
     63 Path:   $RealBin/LO/nonexistentslackbuild4!
     64 	and
     65 m!\QLocal:  nonexistentslackbuild2 1.0
     66 Path:   $RealBin/LO/nonexistentslackbuild2!
     67 	and
     68 m!\QLocal:  nonexistentslackbuild7 1.0
     69 Path:   $RealBin/LO/nonexistentslackbuild7!
     70 	and
     71 m!\QLocal:  nonexistentslackbuild 1.0
     72 Path:   $RealBin/LO/nonexistentslackbuild!
     73 	and
     74 m!\QLocal:  nonexistentslackbuild8 1.0
     75 Path:   $RealBin/LO/nonexistentslackbuild8!
     76 	} };
     77 
     78 	sboinstall qw/ -r nonexistentslackbuild /,
     79 		{ expected => qr/nonexistentslackbuild added to install queue[.].*perf[.]dummy.* saved.*Cleaning for nonexistentslackbuild-1[.]0/s };
     80 	sboremove qw/ --nointeractive nonexistentslackbuild /, { expected => qr/Removing 1 package\(s\).*nonexistentslackbuild.*All operations have completed/s };
     81 	is (system(qw!touch /var/log/packages/nonexistentslackbuild-0.9-noarch-1_SBo!), 0, 'Old version fake installed');
     82 	sbocheck { expected => qr/Updating SlackBuilds tree.*Checking for updated SlackBuilds.*nonexistentslackbuild 0[.]9.*needs updating/s };
     83 	sboupgrade qw/ -r nonexistentslackbuild /, { expected => qr/nonexistentslackbuild added to upgrade queue.*Upgrade queue: nonexistentslackbuild/s };
     84 
     85 # 18: Test missing dep
     86 	sboinstall 'nonexistentslackbuild2', { input => 'n', exit => 0, expected => "Unable to locate nonexistentslackbuild3 in the SlackBuilds.org tree.\nDo you want to ignore it and continue? [n] " };
     87 }
     88 
     89 # 19-23: Test sboupgrade --all
     90 SKIP: {
     91 	my @files = glob("/var/log/packages/nonexistentslackbuild-*");
     92 	skip 'nonexistentslackbuild not installed', 1 if @files == 0;
     93 
     94 	is (system(qw!/sbin/removepkg nonexistentslackbuild!), 0, 'removepkging nonexistentslackbuild works');
     95 }
     96 SKIP: {
     97 	skip "Online testing disabled (TEST_ONLINE!=1) and could not create dummy SLACKBUILDS.txt", 4 if $skip;
     98 
     99 	my @files = glob("/var/log/packages/nonexistentslackbuild-*");
    100 	skip 'Cannot test if nonexistentslackbuild is already installed', 4 if @files;
    101 
    102 	is (system(qw!touch /var/log/packages/nonexistentslackbuild-0.9-noarch-1_SBo!), 0, 'installpkg old version works');
    103 	sboupgrade qw/ -r --all /, { expected => qr/Checking for updated SlackBuilds.*nonexistentslackbuild added to upgrade queue.*Cleaning for nonexistentslackbuild/s };
    104 	ok (-e "/var/log/packages/nonexistentslackbuild-1.0-noarch-1_SBo", 'updated package is installed');
    105 	ok (! -e  "/var/log/packages/nonexistentslackbuild-0.9-noarch-1_SBo", 'old package is removed');
    106 }
    107 
    108 if (not glob("/var/log/packages/nonexistentslackbuild-*")) {
    109 	sboinstall qw/ -r nonexistentslackbuild /, { test => 0 };
    110 }
    111 if (not glob("/var/log/packages/nonexistentslackbuild4-*")) {
    112 	sboinstall 'nonexistentslackbuild4', { input => "y\ny\ny", test => 0 };
    113 }
    114 # 24-25: Test sboupgrade -f
    115 sboupgrade qw/ -f nonexistentslackbuild /, { input => "y\ny", expected => qr/Proceed with nonexistentslackbuild\?.*Upgrade queue: nonexistentslackbuild\n/s };
    116 sboupgrade qw/ -f nonexistentslackbuild4 /, { input => "y\ny", expected => qr/Proceed with nonexistentslackbuild4\?.*Upgrade queue: nonexistentslackbuild4\n/s };
    117 
    118 # 26: Test sboupgrade -f -z
    119 sboupgrade qw/ -f -z nonexistentslackbuild4 /, {
    120 	input => "y\ny\ny",
    121 	expected => qr/nonexistentslackbuild5 added to upgrade queue.*nonexistentslackbuild4 added to upgrade queue.*Upgrade queue: nonexistentslackbuild5 nonexistentslackbuild4\n/s
    122 };
    123 
    124 # 27-34: Test GPG verification
    125 SKIP: {
    126 	skip 'Not doing online tests without TEST_ONLINE=1', 4 if $ENV{TEST_ONLINE} ne '1';
    127 
    128         # Since this is only run under Travis CI, we can blow away the repo without consequence
    129         system(qw! rm -rf /usr/sbo !);
    130         system(qw! gpg --batch --yes --delete-key D3076BC3E783EE747F09B8B70368EF579C7BA3B6 2>&1 >/dev/null !);
    131 
    132         sboconfig qw/ --gpg-key D3076BC3E783EE747F09B8B70368EF579C7BA3B6 /;
    133         sbosnap(("import-key", "https://slackbuilds.org/GPG-KEY"), { expected => qr!.*key imported.*! });
    134 
    135         sboconfig qw! -r https://git.slackbuilds.org/slackbuilds !, { expected => "Setting REPO to https://git.slackbuilds.org/slackbuilds...\n", name => 'Official Git' };
    136 
    137         sbosnap 'fetch', { expected => qr!Pulling SlackBuilds tree.*Cloning into '/usr/sbo/repo'.*Verifying.*!s };
    138         ok (-e "/usr/sbo/repo/SLACKBUILDS.TXT", "SLACKBUILDS.TXT exists (REPO)");
    139         ok (! -e "/usr/sbo/repo/SLACKBUILDS.TXT.gz", "SLACKBUILDS.TXT.gz doesn't exist (REPO)");
    140         sbofind 'sbotools', { expected => qr"SBo:    sbotools .*\nPath:   /usr/sbo/repo/system/sbotools\n\n" };
    141 }
    142 
    143 # 35-41 Test GPG verification
    144 SKIP: {
    145 	skip 'Not doing online tests without TEST_ONLINE=1', 4 if $ENV{TEST_ONLINE} ne '1';
    146 
    147         # Since this is only run under Travis CI, we can blow away the repo without consequence
    148         system(qw! rm -rf /usr/sbo !);
    149         system(qw! gpg --batch --yes --delete-key D3076BC3E783EE747F09B8B70368EF579C7BA3B6 2>&1 >/dev/null !);
    150 
    151         sboconfig qw/ --gpg-key D3076BC3E783EE747F09B8B70368EF579C7BA3B6 /;
    152         sbosnap(("import-key", "https://slackbuilds.org/GPG-KEY"), { expected => qr!.*key imported.*! });
    153 
    154         sboconfig qw! -r rsync://slackbuilds.org/slackbuilds/15.0/ !, { expected => "Setting REPO to rsync://slackbuilds.org/slackbuilds/15.0/...\n", name => 'Official Rsync' };
    155 
    156         sbosnap 'fetch', { expected => qr!Pulling SlackBuilds tree.*Verifying CHECKSUMS.md5.*Verifying file integrity using CHECKSUMS.md5.*!s };
    157 	ok (-e "/usr/sbo/repo/SLACKBUILDS.TXT", "SLACKBUILDS.TXT exists (REPO)");
    158 	ok (-e "/usr/sbo/repo/SLACKBUILDS.TXT.gz", "SLACKBUILDS.TXT.gz exists (REPO)");
    159 	sbofind 'sbotools', { expected => qr"SBo:    sbotools .*\nPath:   /usr/sbo/repo/system/sbotools\n\n" };
    160 }
    161 
    162 # Cleanup
    163 capture_merged {
    164 	system(qw!/sbin/removepkg nonexistentslackbuild!);
    165 	system(qw!/sbin/removepkg nonexistentslackbuild4!);
    166 	system(qw!/sbin/removepkg nonexistentslackbuild5!);
    167 	unlink "$RealBin/LO/nonexistentslackbuild/perf.dummy";
    168 	unlink "$RealBin/LO/nonexistentslackbuild4/perf.dummy";
    169 	unlink "$RealBin/LO/nonexistentslackbuild5/perf.dummy";
    170 };