-
Notifications
You must be signed in to change notification settings - Fork 142
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add exit code test to validate logic is as expected
- Loading branch information
1 parent
5df60ff
commit 8706474
Showing
7 changed files
with
121 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
architecture: amd64 | ||
|
||
actions: | ||
- action: run | ||
chroot: false | ||
command: not-a-command |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,84 @@ | ||
#!/bin/bash | ||
|
||
TEST=0 | ||
FAILURES=0 | ||
VERBOSE=0 | ||
|
||
function test_failed { | ||
local MSG="$1" | ||
TEST=$(($TEST + 1)) | ||
FAILURES=$(($FAILURES + 1)) | ||
echo "Test ${TEST}: ${MSG}" | ||
} | ||
|
||
function test_passed { | ||
TEST=$(($TEST + 1)) | ||
echo "Test ${TEST}: PASS" | ||
} | ||
|
||
function run_cmd { | ||
local CMD="$@" | ||
echo "Running ${CMD}" | ||
if [[ $VERBOSE == 0 ]]; then | ||
$CMD &>/dev/null | ||
else | ||
$CMD | ||
fi | ||
return $? | ||
} | ||
|
||
function expect_success { | ||
local CMD="$@" | ||
|
||
run_cmd $CMD && test_passed || test_failed "${CMD} failed with exitcode $?, expected success" | ||
} | ||
|
||
function expect_failure { | ||
local CMD="$@" | ||
run_cmd $CMD && test_failed "${CMD} succeeded, failure expected." || test_passed | ||
} | ||
|
||
function rename_command { | ||
newname="$1" | ||
shift | ||
(exec -a "$newname" "$@") | ||
return $? | ||
} | ||
|
||
|
||
expect_success debos --help | ||
expect_failure debos --not-a-valid-option | ||
expect_failure debos | ||
expect_failure debos good.yaml good.yaml | ||
expect_failure debos --disable-fakemachine --fakemachine-backend=uml good.yaml | ||
expect_failure debos non-existent-file.yaml | ||
expect_failure debos garbled.yaml | ||
expect_failure debos --fakemachine-backend=uml good.yaml | ||
expect_failure debos verify-fail.yaml | ||
expect_success debos --dry-run good.yaml | ||
expect_failure debos --memory=NotANumber good.yaml | ||
expect_failure debos --cpus=-1 good.yaml | ||
expect_failure debos --scratchsize=NotANumber good.yaml | ||
expect_success debos good.yaml | ||
expect_failure debos bad.yaml | ||
expect_failure debos pre-machine-failure.yaml | ||
expect_failure debos post-machine-failure.yaml | ||
expect_failure rename_command NOT_DEBOS debos good.yaml | ||
|
||
expect_failure sudo debos non-existent-file.yaml --disable-fakemachine | ||
expect_failure sudo debos garbled.yaml --disable-fakemachine | ||
expect_failure sudo debos verify-fail.yaml --disable-fakemachine | ||
expect_success sudo debos --dry-run good.yaml --disable-fakemachine | ||
expect_success sudo debos good.yaml --disable-fakemachine | ||
expect_failure sudo debos bad.yaml --disable-fakemachine | ||
expect_failure sudo debos pre-machine-failure.yaml --disable-fakemachine | ||
expect_failure sudo debos post-machine-failure.yaml --disable-fakemachine | ||
|
||
echo | ||
if [[ $FAILURES -ne 0 ]]; then | ||
SUCCESSES=$(( $TEST - $FAILURES )) | ||
echo "Error: Only $SUCCESSES/$TEST tests passed" | ||
exit 1 | ||
fi | ||
|
||
echo "All tests passed" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
This isn't | ||
::: | ||
|
||
very good YAML |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
architecture: amd64 | ||
|
||
actions: | ||
- action: run | ||
chroot: false | ||
command: ls |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
architecture: amd64 | ||
|
||
actions: | ||
- action: run | ||
chroot: false | ||
command: not-a-command | ||
postprocess: true |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
architecture: amd64 | ||
|
||
actions: | ||
- action: image-partition | ||
imagename: test | ||
imagesize: 500000000000000TB | ||
partitiontype: gpt | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
architecture: amd64 | ||
|
||
actions: | ||
- action: unpack | ||
compression: gz | ||
file: ~ |