| File: | t/deploy.t |
| Coverage: | 98.7% |
| line | stmt | bran | cond | sub | pod | time | code |
|---|---|---|---|---|---|---|---|
| 1 | 1 1 1 | 49012 4 56 | use strict; | ||||
| 2 | 1 1 1 | 6 3 33 | use warnings; | ||||
| 3 | |||||||
| 4 | 1 1 1 | 546 60663 25 | use Test::Most; | ||||
| 5 | 1 1 1 | 122280 6 191 | use File::Path 'mkpath'; | ||||
| 6 | 1 1 1 | 643 1192 8 | use lib 't'; | ||||
| 7 | 1 1 1 | 4189 4 7800 | use TestLib qw( t_module t_startup t_teardown t_capture t_action_files ); | ||||
| 8 | |||||||
| 9 | 1 | 223461 | exit main(); | ||||
| 10 | |||||||
| 11 | sub main { | ||||||
| 12 | 1 | 11 | require_ok( t_module() ); | ||||
| 13 | |||||||
| 14 | 1 | 486 | t_startup(); | ||||
| 15 | 1 | 7 | t_action_files('adt/state'); | ||||
| 16 | 1 | 7 | t_module->init; | ||||
| 17 | 1 | 6 | t_module->add('adt'); | ||||
| 18 | |||||||
| 19 | 1 | 5 | deploy(); | ||||
| 20 | |||||||
| 21 | 1 | 2195 | t_teardown(); | ||||
| 22 | 1 | 32 | done_testing(); | ||||
| 23 | 1 | 603 | return 0; | ||||
| 24 | } | ||||||
| 25 | |||||||
| 26 | sub deploy { | ||||||
| 27 | is ( | ||||||
| 28 | 1 1 | 6 10 | ( t_capture( sub { t_module->verify } ) )[0], | ||||
| 29 | "not ok - verify: adt/state\n", | ||||||
| 30 | 'verify all existing actions returns false', | ||||||
| 31 | ); | ||||||
| 32 | is ( | ||||||
| 33 | 1 1 | 7520 43 | ( t_capture( sub { t_module->verify('adt/state') } ) )[0], | ||||
| 34 | "not ok - verify: adt/state\n", | ||||||
| 35 | 'verify undeployed action returns false', | ||||||
| 36 | ); | ||||||
| 37 | |||||||
| 38 | |||||||
| 39 | is ( | ||||||
| 40 | 1 1 | 9442 221 | ( t_capture( sub { t_module->deploy } ) )[2], | ||||
| 41 | "File to deploy required; usage: dest deploy file\n", | ||||||
| 42 | 'deploy without action fails', | ||||||
| 43 | ); | ||||||
| 44 | is ( | ||||||
| 45 | 1 1 | 15730 7 | ( t_capture( sub { t_module->deploy('adt/state') } ) )[0], | ||||
| 46 | join( "\n", | ||||||
| 47 | 'begin - deploy: adt/state', | ||||||
| 48 | 'ok - deploy: adt/state', | ||||||
| 49 | 'ok - verify: adt/state', | ||||||
| 50 | ) . "\n", | ||||||
| 51 | 'deploy with action succeeds', | ||||||
| 52 | ); | ||||||
| 53 | |||||||
| 54 | is ( | ||||||
| 55 | 1 1 | 10791 153 | ( t_capture( sub { t_module->verify } ) )[0], | ||||
| 56 | "ok - verify: adt/state\n", | ||||||
| 57 | 'verify all existing actions returns true', | ||||||
| 58 | ); | ||||||
| 59 | is ( | ||||||
| 60 | 1 1 | 10909 55 | ( t_capture( sub { t_module->verify('adt/state') } ) )[0], | ||||
| 61 | "ok - verify: adt/state\n", | ||||||
| 62 | 'verify undeployed action returns true', | ||||||
| 63 | ); | ||||||
| 64 | |||||||
| 65 | is ( | ||||||
| 66 | 1 1 | 9038 93 | ( t_capture( sub { t_module->revert } ) )[2], | ||||
| 67 | "File to revert required; usage: dest revert file\n", | ||||||
| 68 | 'revert without action throws error', | ||||||
| 69 | ); | ||||||
| 70 | is ( | ||||||
| 71 | 1 1 | 3803 27 | ( t_capture( sub { t_module->revert('adt/state') } ) )[0], | ||||
| 72 | join( "\n", | ||||||
| 73 | 'begin - revert: adt/state', | ||||||
| 74 | 'ok - revert: adt/state', | ||||||
| 75 | ) . "\n", | ||||||
| 76 | 'revert with action succeeds', | ||||||
| 77 | ); | ||||||
| 78 | |||||||
| 79 | 1 1 | 15566 153 | t_capture( sub { t_module->deploy('adt/state') } ); | ||||
| 80 | is ( | ||||||
| 81 | 1 1 | 832 865 | ( t_capture( sub { t_module->redeploy('adt/state') } ) )[0], | ||||
| 82 | join( "\n", | ||||||
| 83 | 'begin - deploy: adt/state', | ||||||
| 84 | 'ok - deploy: adt/state', | ||||||
| 85 | 'ok - verify: adt/state', | ||||||
| 86 | ) . "\n", | ||||||
| 87 | 'redeploy with action succeeds', | ||||||
| 88 | ); | ||||||
| 89 | |||||||
| 90 | 1 | 2682 | my $state_file; | ||||
| 91 | 1 | 108 | ok( open( $state_file, '<', 'state_adt_state.txt' ) || 0, 'open state_adt_state.txt file' ); | ||||
| 92 | 1 | 1180 | my @lines = <$state_file>; | ||||
| 93 | 1 3 | 7 43 | is( scalar( grep { /^adt\/state$/ } @lines ), 2, 'redeploy state check passes' ); | ||||
| 94 | |||||||
| 95 | is ( | ||||||
| 96 | 1 1 | 442 86 | ( t_capture( sub { t_module->revdeploy('adt/state') } ) )[0], | ||||
| 97 | join( "\n", | ||||||
| 98 | 'begin - revert: adt/state', | ||||||
| 99 | 'ok - revert: adt/state', | ||||||
| 100 | 'begin - deploy: adt/state', | ||||||
| 101 | 'ok - deploy: adt/state', | ||||||
| 102 | 'ok - verify: adt/state', | ||||||
| 103 | ) . "\n", | ||||||
| 104 | 'revdeploy with action succeeds', | ||||||
| 105 | ); | ||||||
| 106 | } | ||||||