Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
24 changes: 12 additions & 12 deletions docs/test_basic.bats
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,8 @@ load '../test_helpers/bats-assert/load'
run st2 --version
assert_success

assert_output --regexp "^st2 "
assert_output --partial "on Python"
assert_line --regexp "^st2 "
assert_line --partial "on Python"
}

@test "st2 usage works" {
Expand All @@ -24,7 +24,7 @@ load '../test_helpers/bats-assert/load'
run st2 -h
assert_success

assert_output --regexp "^usage:"
assert_line --regexp "^usage:"
assert_output --partial "CLI for StackStorm event-driven automation platform."
assert_output --partial "Enable debug mode"
}
Expand Down Expand Up @@ -54,7 +54,7 @@ load '../test_helpers/bats-assert/load'
run eval "st2 action get -j core.http | jq -r '.ref'"
assert_success

assert_output "core.http"
assert_line "core.http"

run eval "st2 action get -j core.http | jq -r '.parameters.method.enum | .[]'"
assert_success
Expand All @@ -74,19 +74,19 @@ load '../test_helpers/bats-assert/load'
run eval "st2 run -j core.local -- date -R | jq -r '.status'"
assert_success

assert_output "succeeded"
assert_line "succeeded"

run eval "st2 run -j core.local -- date -R | jq -r '.parameters.cmd'"
assert_success
assert_output "date -R"
assert_line "date -R"

run eval "st2 execution list -n 1 -j | jq -r '.[].action.ref'"
assert_success
assert_output "core.local"
assert_line "core.local"

run eval "st2 execution list -n 1 -j | jq -r '.[].status'"
assert_success
assert_output "succeeded"
assert_line "succeeded"
}

@test "sensor list works" {
Expand All @@ -100,25 +100,25 @@ load '../test_helpers/bats-assert/load'
run eval "st2 trigger list -j -a=all | jq -r '.[].pack = \"core\" | length'"
assert_success

[[ "$output" -gt 15 ]]
assert_line --regexp "[[:digit:]]{1,}"
}

@test "trigger get works" {
TRIGGER_ID=$(st2 trigger list -j -a=all | jq -r '.[4].id')
run eval "st2 trigger get -j $TRIGGER_ID | jq -r '.id'"
assert_success

assert_output "$TRIGGER_ID"
assert_line "$TRIGGER_ID"
}

@test "core.remote action works" {
run eval "st2 run -j core.remote hosts=\"localhost\" -- uname -a | jq -r '.parameters.cmd'"
assert_success

assert_output "uname -a"
assert_line "uname -a"

run eval "st2 run -j core.remote hosts=\"localhost\" -- uname -a | jq -r '.parameters.hosts'"
assert_success

assert_output "localhost"
assert_line "localhost"
}
20 changes: 10 additions & 10 deletions docs/test_integration_packs_doc.bats
Original file line number Diff line number Diff line change
Expand Up @@ -24,15 +24,15 @@ load '../test_helpers/bats-assert/load'
run eval "st2 action list --pack libcloud -j | jq '. | length'"
assert_success

assert_output --regexp '^[[:digit:]]{1,}$'
assert_line --regexp '^[[:digit:]]{1,}$'
refute_output '0'
}

@test "list actions in consul pack" {
run eval "st2 action list --pack consul -j | jq '. | length'"
assert_success

assert_output --regexp '^[[:digit:]]{1,}$'
assert_line --regexp '^[[:digit:]]{1,}$'
refute_output '0'
}

Expand All @@ -48,39 +48,39 @@ load '../test_helpers/bats-assert/load'
run st2 action list --pack libcloud -j
assert_success

assert_output "No matching items found"
assert_line "No matching items found"
}

@test "no actions in consul pack" {
run st2 action list --pack consul -j
assert_success

assert_output "No matching items found"
assert_line "No matching items found"
}

@test "packs can be downloaded using packs.download" {
DOWNLOAD_RESULTS=$(st2 run packs.download packs=libcloud -j)
run eval "echo '$DOWNLOAD_RESULTS' | jq -r '.status'"
assert_success

assert_output "succeeded"
assert_line "succeeded"

run eval "echo '$DOWNLOAD_RESULTS' | jq -r '.result.result.libcloud'"
assert_success

assert_output "Success."
assert_line "Success."
}

@test "can run packs.setup_virtualenv for a pack downloaded in previous step" {
run eval "st2 run packs.setup_virtualenv packs=libcloud -j | jq -r '.status'"
assert_success

assert_output "succeeded"
assert_line "succeeded"

run eval "st2 run packs.setup_virtualenv packs=libcloud -j | jq -r '.result.result'"
assert_success

assert_output "Successfully set up virtualenv for the following packs: libcloud"
assert_line "Successfully set up virtualenv for the following packs: libcloud"
}

@test "packs register registers all packs" {
Expand Down Expand Up @@ -140,12 +140,12 @@ load '../test_helpers/bats-assert/load'
run eval "st2 run packs.download packs=bitcoin -j | jq -r '.result.result.bitcoin'"
assert_success

assert_output "Success."
assert_line "Success."
}

@test "pack reinstall with no config" {
run eval "st2 run packs.download packs=bitcoin -j | jq -r '.result.result.bitcoin'"
assert_success

assert_output "Success."
assert_line "Success."
}
4 changes: 2 additions & 2 deletions docs/test_key_triggers.bats
Original file line number Diff line number Diff line change
Expand Up @@ -138,7 +138,7 @@ KEY_JSON_FILE="docs/test_key_triggers.json"
run eval "st2 key delete \"$ROBOT_KEY\""
assert_success

assert_output "Resource with id \"$ROBOT_KEY\" has been successfully deleted."
assert_line "Resource with id \"$ROBOT_KEY\" has been successfully deleted."

KEY_DELETE_RESULTS=$(st2 trigger-instance list --trigger=$TRIGGER_KEY_DELETE -n 1 -j)
run eval "echo '$KEY_DELETE_RESULTS' | jq -r '.[].trigger'"
Expand Down Expand Up @@ -215,7 +215,7 @@ KEY_JSON_FILE="docs/test_key_triggers.json"
run eval "st2 key delete 1 -j"
assert_success

assert_output "Resource with id \"1\" has been successfully deleted."
assert_line "Resource with id \"1\" has been successfully deleted."
}

@test "key-value operations with expiries" {
Expand Down
2 changes: 2 additions & 0 deletions packs/asserts/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,3 +7,5 @@ Contains actions that perform assert valuations.
``object_key_number_equals`` - Given an object and a key in the object, evaluate whether value corresponding to key is equal to an expected numerical value.

``object_key_string_equals`` - Given an object and a key in the object, evaluate whether value corresponding to key is equal to an expected string value.

``object_key_string_contains`` - Given an object and a key in the object, evaluate whether value corresponding to key contains an expected string value.
23 changes: 23 additions & 0 deletions packs/asserts/actions/object_key_string_contains.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
import sys

from st2actions.runners.pythonrunner import Action

__all__ = [
'AssertObjectKeyStringContains'
]


class AssertObjectKeyStringContains(Action):
def run(self, object, key, value):
if not isinstance(object, dict):
raise ValueError('object shoud be of type "dict".')
if key not in object:
sys.stderr.write('KEY %s DOESN\'T EXIST.' % key)
raise ValueError('Key %s doesn\'t exist in object %s' % (key, object))
result = (value in object[key])
if result:
sys.stdout.write('EQUAL')
else:
sys.stdout.write('NOT EQUAL')
raise ValueError('Value not found. Expected "%s", got "%s". ' % (value, object[key]))
return result
19 changes: 19 additions & 0 deletions packs/asserts/actions/object_key_string_contains.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
---
description: Check if key in object contains a given string value.
enabled: true
entry_point: object_key_string_contains.py
name: object_key_string_contains
parameters:
object:
type: object
description: Object input.
required: true
key:
type: string
description: Key in object to pick the value for to test.
required: true
value:
type: string
description: Expected string value.
required: true
runner_type: "python-script"
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ chain:
on-success: "assert_stderr_field_stderr_test"
-
name: "assert_stderr_field_stderr_test"
ref: "asserts.object_key_string_equals"
ref: "asserts.object_key_string_contains"
params:
object: "{{test_stderr_python_action}}"
key: "stderr"
Expand Down
1 change: 1 addition & 0 deletions test-requirements.txt
Original file line number Diff line number Diff line change
Expand Up @@ -20,4 +20,5 @@ traceback2==1.4.0
unittest2==1.1.0
urllib3==1.24.2
websocket-client==0.54.0
wheel==0.36.0
wrapt==1.11.1