Skip to content

Commit 6924905

Browse files
authored
Merge pull request #72 from michelleheh/michelle/template-and-compare--with-numbers
Add AbstractBehavior example value-with-numbers
2 parents 5e59eab + e59b1d1 commit 6924905

File tree

2 files changed

+31
-0
lines changed

2 files changed

+31
-0
lines changed

README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -203,6 +203,7 @@ Templates can be useful to assemble your payloads from parts
203203
Abstract Behaviors can be used to parameterize some data.
204204
205205
When an abstract behavior and a behavior extending it both have actions defined, all of them are run when the behavior matches. Actions will run from lowest to highest value of the 'order' field; if this is the same for two actions the action defined earlier in the abstract behavior runs first, followed by actions in the concrete behavior.
206+
Be aware that values with all digits will be interpreted into `int` type (YAML syntax), and it will fail the condition check given that some helper functions are returning `string` types. Pipe to `toString` before the comparison or alternatively put quotes around the values. See example in `abstract_behaviors.yml`.
206207
```yaml
207208
- key: fruit-of-the-day
208209
kind: AbstractBehavior

demo_templates/abstract_behaviors.yml

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,3 +24,33 @@
2424
extend: fruit-of-the-day
2525
values:
2626
day: tuesday
27+
28+
# Be aware that values with all digits will be interpreted into int type, and it will fail the condition check.
29+
# Pipe to toString before the comparison (i.e. eq, contains, etc.) or alternatively put quotes around the values.
30+
- key: value-with-numbers
31+
kind: AbstractBehavior
32+
values:
33+
count: 0
34+
expect:
35+
condition: '{{.HTTPQueryString | toString | eq .Values.count}}'
36+
http:
37+
method: GET
38+
path: /value-with-numbers
39+
actions:
40+
- reply_http:
41+
status_code: 200
42+
body: '{"word": "{{.Values.word}}"}'
43+
44+
- key: count-one
45+
kind: Behavior
46+
extend: value-with-numbers
47+
values:
48+
count: 1
49+
word: one
50+
51+
- key: count-two
52+
kind: Behavior
53+
extend: value-with-numbers
54+
values:
55+
count: 2
56+
word: two

0 commit comments

Comments
 (0)