Skip to content

Commit 0b59079

Browse files
authored
Merge pull request #198 from StackStorm/relax-string-comparison
Relax string comparison
2 parents dc9990c + 0654ef5 commit 0b59079

File tree

8 files changed

+70
-25
lines changed

8 files changed

+70
-25
lines changed

docs/test_basic.bats

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -8,8 +8,8 @@ load '../test_helpers/bats-assert/load'
88
run st2 --version
99
assert_success
1010

11-
assert_output --regexp "^st2 "
12-
assert_output --partial "on Python"
11+
assert_line --regexp "^st2 "
12+
assert_line --partial "on Python"
1313
}
1414

1515
@test "st2 usage works" {
@@ -24,7 +24,7 @@ load '../test_helpers/bats-assert/load'
2424
run st2 -h
2525
assert_success
2626

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

57-
assert_output "core.http"
57+
assert_line "core.http"
5858

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

77-
assert_output "succeeded"
77+
assert_line "succeeded"
7878

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

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

8787
run eval "st2 execution list -n 1 -j | jq -r '.[].status'"
8888
assert_success
89-
assert_output "succeeded"
89+
assert_line "succeeded"
9090
}
9191

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

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

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

111-
assert_output "$TRIGGER_ID"
111+
assert_line "$TRIGGER_ID"
112112
}
113113

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

118-
assert_output "uname -a"
118+
assert_line "uname -a"
119119

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

123-
assert_output "localhost"
123+
assert_line "localhost"
124124
}

docs/test_integration_packs_doc.bats

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -24,15 +24,15 @@ load '../test_helpers/bats-assert/load'
2424
run eval "st2 action list --pack libcloud -j | jq '. | length'"
2525
assert_success
2626

27-
assert_output --regexp '^[[:digit:]]{1,}$'
27+
assert_line --regexp '^[[:digit:]]{1,}$'
2828
refute_output '0'
2929
}
3030

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

35-
assert_output --regexp '^[[:digit:]]{1,}$'
35+
assert_line --regexp '^[[:digit:]]{1,}$'
3636
refute_output '0'
3737
}
3838

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

51-
assert_output "No matching items found"
51+
assert_line "No matching items found"
5252
}
5353

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

58-
assert_output "No matching items found"
58+
assert_line "No matching items found"
5959
}
6060

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

66-
assert_output "succeeded"
66+
assert_line "succeeded"
6767

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

71-
assert_output "Success."
71+
assert_line "Success."
7272
}
7373

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

78-
assert_output "succeeded"
78+
assert_line "succeeded"
7979

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

83-
assert_output "Successfully set up virtualenv for the following packs: libcloud"
83+
assert_line "Successfully set up virtualenv for the following packs: libcloud"
8484
}
8585

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

143-
assert_output "Success."
143+
assert_line "Success."
144144
}
145145

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

150-
assert_output "Success."
150+
assert_line "Success."
151151
}

docs/test_key_triggers.bats

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -138,7 +138,7 @@ KEY_JSON_FILE="docs/test_key_triggers.json"
138138
run eval "st2 key delete \"$ROBOT_KEY\""
139139
assert_success
140140

141-
assert_output "Resource with id \"$ROBOT_KEY\" has been successfully deleted."
141+
assert_line "Resource with id \"$ROBOT_KEY\" has been successfully deleted."
142142

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

218-
assert_output "Resource with id \"1\" has been successfully deleted."
218+
assert_line "Resource with id \"1\" has been successfully deleted."
219219
}
220220

221221
@test "key-value operations with expiries" {

packs/asserts/README.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,3 +7,5 @@ Contains actions that perform assert valuations.
77
``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.
88

99
``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.
10+
11+
``object_key_string_contains`` - Given an object and a key in the object, evaluate whether value corresponding to key contains an expected string value.
Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
import sys
2+
3+
from st2actions.runners.pythonrunner import Action
4+
5+
__all__ = [
6+
'AssertObjectKeyStringContains'
7+
]
8+
9+
10+
class AssertObjectKeyStringContains(Action):
11+
def run(self, object, key, value):
12+
if not isinstance(object, dict):
13+
raise ValueError('object shoud be of type "dict".')
14+
if key not in object:
15+
sys.stderr.write('KEY %s DOESN\'T EXIST.' % key)
16+
raise ValueError('Key %s doesn\'t exist in object %s' % (key, object))
17+
result = (value in object[key])
18+
if result:
19+
sys.stdout.write('EQUAL')
20+
else:
21+
sys.stdout.write('NOT EQUAL')
22+
raise ValueError('Value not found. Expected "%s", got "%s". ' % (value, object[key]))
23+
return result
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
---
2+
description: Check if key in object contains a given string value.
3+
enabled: true
4+
entry_point: object_key_string_contains.py
5+
name: object_key_string_contains
6+
parameters:
7+
object:
8+
type: object
9+
description: Object input.
10+
required: true
11+
key:
12+
type: string
13+
description: Key in object to pick the value for to test.
14+
required: true
15+
value:
16+
type: string
17+
description: Expected string value.
18+
required: true
19+
runner_type: "python-script"

packs/tests/actions/chains/test_quickstart_python_actions.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ chain:
3030
on-success: "assert_stderr_field_stderr_test"
3131
-
3232
name: "assert_stderr_field_stderr_test"
33-
ref: "asserts.object_key_string_equals"
33+
ref: "asserts.object_key_string_contains"
3434
params:
3535
object: "{{test_stderr_python_action}}"
3636
key: "stderr"

test-requirements.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,4 +20,5 @@ traceback2==1.4.0
2020
unittest2==1.1.0
2121
urllib3==1.24.2
2222
websocket-client==0.54.0
23+
wheel==0.36.0
2324
wrapt==1.11.1

0 commit comments

Comments
 (0)