| File: | t/prereqs.t |
| Coverage: | 98.1% |
| line | stmt | bran | cond | sub | pod | time | code |
|---|---|---|---|---|---|---|---|
| 1 | 1 1 1 | 42614 19 60 | use strict; | ||||
| 2 | 1 1 1 | 7 3 32 | use warnings; | ||||
| 3 | |||||||
| 4 | 1 1 1 | 427 121718 14 | use Test::Most; | ||||
| 5 | 1 1 1 | 148970 1172 8 | use lib 't'; | ||||
| 6 | 1 1 1 | 370 6 7978 | use TestLib qw( t_module t_startup t_teardown t_capture t_action_files ); | ||||
| 7 | |||||||
| 8 | 1 | 243667 | exit main(); | ||||
| 9 | |||||||
| 10 | sub main { | ||||||
| 11 | 1 | 10 | require_ok( t_module() ); | ||||
| 12 | |||||||
| 13 | 1 | 396 | t_startup(); | ||||
| 14 | 1 | 36 | t_action_files( | ||||
| 15 | [ 'adt/state_sixth', 'adt_alt/state_fifth', undef ], | ||||||
| 16 | [ 'adt/state_first', undef, 'adt_alt/state_second' ], | ||||||
| 17 | [ 'adt/state_fourth', 'adt_alt/state_third', 'adt_alt/state_fifth' ], | ||||||
| 18 | [ 'adt_alt/state_third', 'adt_alt/state_second', 'adt/state_fourth' ], | ||||||
| 19 | [ 'adt_alt/state_fifth', 'adt/state_fourth', 'adt/state_sixth' ], | ||||||
| 20 | [ 'adt_alt/state_second', 'adt/state_first', 'adt_alt/state_third' ], | ||||||
| 21 | ); | ||||||
| 22 | 1 | 7 | t_module->init; | ||||
| 23 | 1 | 5 | t_module->add('adt'); | ||||
| 24 | 1 | 5 | t_module->add('adt_alt'); | ||||
| 25 | |||||||
| 26 | 1 | 6 | single_prereqs(); | ||||
| 27 | 1 | 14748 | multi_prereqs(); | ||||
| 28 | 1 | 363 | update(); | ||||
| 29 | |||||||
| 30 | 1 | 557 | t_teardown(); | ||||
| 31 | 1 | 26 | done_testing(); | ||||
| 32 | 1 | 905 | return 0; | ||||
| 33 | } | ||||||
| 34 | |||||||
| 35 | sub single_prereqs { | ||||||
| 36 | is( | ||||||
| 37 | 1 1 | 4 9 | ( t_capture( sub { t_module->status } ) )[0], | ||||
| 38 | join( "\n", | ||||||
| 39 | 'diff - adt', | ||||||
| 40 | ' + adt/state_first', | ||||||
| 41 | ' + adt/state_fourth', | ||||||
| 42 | ' + adt/state_sixth', | ||||||
| 43 | 'diff - adt_alt', | ||||||
| 44 | ' + adt_alt/state_fifth', | ||||||
| 45 | ' + adt_alt/state_second', | ||||||
| 46 | ' + adt_alt/state_third', | ||||||
| 47 | ) . "\n", | ||||||
| 48 | 'status() of adt/* and adt_alt/* actions', | ||||||
| 49 | ); | ||||||
| 50 | |||||||
| 51 | { | ||||||
| 52 | 1 1 1 | 340 12 6 | my ( $out, $err, $exp ) = t_capture( sub { t_module->deploy('adt_alt/state_second') } ); | ||||
| 53 | |||||||
| 54 | 1 | 268 | is( | ||||
| 55 | $out, | ||||||
| 56 | join( "\n", | ||||||
| 57 | 'begin - deploy: adt/state_first', | ||||||
| 58 | 'ok - deploy: adt/state_first', | ||||||
| 59 | 'ok - verify: adt/state_first', | ||||||
| 60 | 'begin - deploy: adt_alt/state_second', | ||||||
| 61 | 'ok - deploy: adt_alt/state_second', | ||||||
| 62 | 'ok - verify: adt_alt/state_second', | ||||||
| 63 | ) . "\n", | ||||||
| 64 | 'single deploy with single prereq', | ||||||
| 65 | ); | ||||||
| 66 | |||||||
| 67 | 1 | 23672 | ok( ! $err, 'no warnings in last command' ); | ||||
| 68 | 1 | 2827 | ok( ! $exp, 'no exceptions in last command' ); | ||||
| 69 | } | ||||||
| 70 | |||||||
| 71 | is( | ||||||
| 72 | 1 1 | 527 43 | ( t_capture( sub { t_module->status } ) )[0], | ||||
| 73 | join( "\n", | ||||||
| 74 | 'diff - adt', | ||||||
| 75 | ' + adt/state_fourth', | ||||||
| 76 | ' + adt/state_sixth', | ||||||
| 77 | 'diff - adt_alt', | ||||||
| 78 | ' + adt_alt/state_fifth', | ||||||
| 79 | ' + adt_alt/state_third', | ||||||
| 80 | ) . "\n", | ||||||
| 81 | 'status() of adt/* and adt_alt/* actions after limited deployment', | ||||||
| 82 | ); | ||||||
| 83 | |||||||
| 84 | 1 | 4864 | _revert_to_clean(); | ||||
| 85 | } | ||||||
| 86 | |||||||
| 87 | sub _revert_to_clean { | ||||||
| 88 | { | ||||||
| 89 | 2 2 2 | 22 9 116 | my ( $out, $err, $exp ) = t_capture( sub { t_module->revert('adt/state_first') } ); | ||||
| 90 | |||||||
| 91 | 2 | 646 | is( | ||||
| 92 | $out, | ||||||
| 93 | join( "\n", | ||||||
| 94 | 'begin - revert: adt_alt/state_second', | ||||||
| 95 | 'ok - revert: adt_alt/state_second', | ||||||
| 96 | 'begin - revert: adt/state_first', | ||||||
| 97 | 'ok - revert: adt/state_first', | ||||||
| 98 | ) . "\n", | ||||||
| 99 | 'single revert with single prereq', | ||||||
| 100 | ); | ||||||
| 101 | |||||||
| 102 | 2 | 15859 | ok( ! $err, 'no warnings in last command' ); | ||||
| 103 | 2 | 919 | ok( ! $exp, 'no exceptions in last command' ); | ||||
| 104 | } | ||||||
| 105 | |||||||
| 106 | is( | ||||||
| 107 | 2 2 | 8101 82 | ( t_capture( sub { t_module->status } ) )[0], | ||||
| 108 | join( "\n", | ||||||
| 109 | 'diff - adt', | ||||||
| 110 | ' + adt/state_first', | ||||||
| 111 | ' + adt/state_fourth', | ||||||
| 112 | ' + adt/state_sixth', | ||||||
| 113 | 'diff - adt_alt', | ||||||
| 114 | ' + adt_alt/state_fifth', | ||||||
| 115 | ' + adt_alt/state_second', | ||||||
| 116 | ' + adt_alt/state_third', | ||||||
| 117 | ) . "\n", | ||||||
| 118 | 'status() of adt/* and adt_alt/* actions after revert', | ||||||
| 119 | ); | ||||||
| 120 | } | ||||||
| 121 | |||||||
| 122 | sub multi_prereqs { | ||||||
| 123 | { | ||||||
| 124 | 1 1 1 | 6 6 16 | my ( $out, $err, $exp ) = t_capture( sub { t_module->deploy('adt_alt/state_fifth') } ); | ||||
| 125 | |||||||
| 126 | 1 | 201 | is( | ||||
| 127 | $out, | ||||||
| 128 | join( "\n", | ||||||
| 129 | 'begin - deploy: adt/state_first', | ||||||
| 130 | 'ok - deploy: adt/state_first', | ||||||
| 131 | 'ok - verify: adt/state_first', | ||||||
| 132 | 'begin - deploy: adt_alt/state_second', | ||||||
| 133 | 'ok - deploy: adt_alt/state_second', | ||||||
| 134 | 'ok - verify: adt_alt/state_second', | ||||||
| 135 | 'begin - deploy: adt_alt/state_third', | ||||||
| 136 | 'ok - deploy: adt_alt/state_third', | ||||||
| 137 | 'ok - verify: adt_alt/state_third', | ||||||
| 138 | 'begin - deploy: adt/state_fourth', | ||||||
| 139 | 'ok - deploy: adt/state_fourth', | ||||||
| 140 | 'ok - verify: adt/state_fourth', | ||||||
| 141 | 'begin - deploy: adt_alt/state_fifth', | ||||||
| 142 | 'ok - deploy: adt_alt/state_fifth', | ||||||
| 143 | 'ok - verify: adt_alt/state_fifth', | ||||||
| 144 | ) . "\n", | ||||||
| 145 | 'single deploy with multiple prereqs', | ||||||
| 146 | ); | ||||||
| 147 | |||||||
| 148 | 1 | 15100 | ok( ! $err, 'no warnings in last command' ); | ||||
| 149 | 1 | 552 | ok( ! $exp, 'no exceptions in last command' ); | ||||
| 150 | } | ||||||
| 151 | |||||||
| 152 | is( | ||||||
| 153 | 1 1 | 813 59 | ( t_capture( sub { t_module->status } ) )[0], | ||||
| 154 | join( "\n", | ||||||
| 155 | 'diff - adt', | ||||||
| 156 | ' + adt/state_sixth', | ||||||
| 157 | 'ok - adt_alt', | ||||||
| 158 | ) . "\n", | ||||||
| 159 | 'status() of adt/* and adt_alt/* actions after revert', | ||||||
| 160 | ); | ||||||
| 161 | |||||||
| 162 | { | ||||||
| 163 | 1 1 1 | 570 10 30 | my ( $out, $err, $exp ) = t_capture( sub { t_module->revert('adt_alt/state_third') } ); | ||||
| 164 | |||||||
| 165 | 1 | 393 | is( | ||||
| 166 | $out, | ||||||
| 167 | join( "\n", | ||||||
| 168 | 'begin - revert: adt_alt/state_fifth', | ||||||
| 169 | 'ok - revert: adt_alt/state_fifth', | ||||||
| 170 | 'begin - revert: adt/state_fourth', | ||||||
| 171 | 'ok - revert: adt/state_fourth', | ||||||
| 172 | 'begin - revert: adt_alt/state_third', | ||||||
| 173 | 'ok - revert: adt_alt/state_third', | ||||||
| 174 | ) . "\n", | ||||||
| 175 | 'single deploy with multiple prereqs', | ||||||
| 176 | ); | ||||||
| 177 | |||||||
| 178 | 1 | 3839 | ok( ! $err, 'no warnings in last command' ); | ||||
| 179 | 1 | 252 | ok( ! $exp, 'no exceptions in last command' ); | ||||
| 180 | } | ||||||
| 181 | |||||||
| 182 | is( | ||||||
| 183 | 1 1 | 278 41 | ( t_capture( sub { t_module->status } ) )[0], | ||||
| 184 | join( "\n", | ||||||
| 185 | 'diff - adt', | ||||||
| 186 | ' + adt/state_fourth', | ||||||
| 187 | ' + adt/state_sixth', | ||||||
| 188 | 'diff - adt_alt', | ||||||
| 189 | ' + adt_alt/state_fifth', | ||||||
| 190 | ' + adt_alt/state_third', | ||||||
| 191 | ) . "\n", | ||||||
| 192 | 'status() of adt/* and adt_alt/* actions after revert', | ||||||
| 193 | ); | ||||||
| 194 | |||||||
| 195 | 1 | 339 | _revert_to_clean(); | ||||
| 196 | } | ||||||
| 197 | |||||||
| 198 | sub update { | ||||||
| 199 | is( | ||||||
| 200 | 1 1 | 6 67 | ( t_capture( sub { t_module->update } ) )[0], | ||||
| 201 | join( "\n", | ||||||
| 202 | 'begin - deploy: adt/state_first', | ||||||
| 203 | 'ok - deploy: adt/state_first', | ||||||
| 204 | 'ok - verify: adt/state_first', | ||||||
| 205 | 'begin - deploy: adt_alt/state_second', | ||||||
| 206 | 'ok - deploy: adt_alt/state_second', | ||||||
| 207 | 'ok - verify: adt_alt/state_second', | ||||||
| 208 | 'begin - deploy: adt_alt/state_third', | ||||||
| 209 | 'ok - deploy: adt_alt/state_third', | ||||||
| 210 | 'ok - verify: adt_alt/state_third', | ||||||
| 211 | 'begin - deploy: adt/state_fourth', | ||||||
| 212 | 'ok - deploy: adt/state_fourth', | ||||||
| 213 | 'ok - verify: adt/state_fourth', | ||||||
| 214 | 'begin - deploy: adt_alt/state_fifth', | ||||||
| 215 | 'ok - deploy: adt_alt/state_fifth', | ||||||
| 216 | 'ok - verify: adt_alt/state_fifth', | ||||||
| 217 | 'begin - deploy: adt/state_sixth', | ||||||
| 218 | 'ok - deploy: adt/state_sixth', | ||||||
| 219 | 'ok - verify: adt/state_sixth', | ||||||
| 220 | ) . "\n", | ||||||
| 221 | 'update() of clean state', | ||||||
| 222 | ); | ||||||
| 223 | |||||||
| 224 | is( | ||||||
| 225 | 1 1 | 2526 94 | ( t_capture( sub { t_module->status } ) )[0], | ||||
| 226 | join( "\n", | ||||||
| 227 | 'ok - adt', | ||||||
| 228 | 'ok - adt_alt', | ||||||
| 229 | ) . "\n", | ||||||
| 230 | 'status() of adt/* and adt_alt/* actions after revert', | ||||||
| 231 | ); | ||||||
| 232 | |||||||
| 233 | 1 | 575 | t_action_files('adt_new/state'); | ||||
| 234 | 1 | 25 | my $watch_file; | ||||
| 235 | 1 | 28 | ok( open( $watch_file, '>', 'dest.watch' ) or 0, 'write out new dest.watch file' ); | ||||
| 236 | 1 | 484 | print $watch_file "adt\nadt_alt\nadt_new"; | ||||
| 237 | 1 | 25 | close $watch_file; | ||||
| 238 | |||||||
| 239 | { | ||||||
| 240 | 1 1 1 | 5 29 24 | my ( $out, $err, $exp ) = t_capture( sub { t_module->update } ); | ||||
| 241 | |||||||
| 242 | 1 | 265 | is( | ||||
| 243 | $err, | ||||||
| 244 | "Added adt_new to the watch list\n", | ||||||
| 245 | 'update() based on changed dest.watch file adds new watch', | ||||||
| 246 | ); | ||||||
| 247 | |||||||
| 248 | 1 | 1545 | is( | ||||
| 249 | $out, | ||||||
| 250 | join( "\n", | ||||||
| 251 | 'begin - deploy: adt_new/state', | ||||||
| 252 | 'ok - deploy: adt_new/state', | ||||||
| 253 | 'ok - verify: adt_new/state', | ||||||
| 254 | ) . "\n", | ||||||
| 255 | 'update() based on changed dest.watch file runs OK', | ||||||
| 256 | ); | ||||||
| 257 | } | ||||||
| 258 | } | ||||||