Skip to content

Commit db8cb4e

Browse files
committed
wip - tests
1 parent 1657cf6 commit db8cb4e

File tree

3 files changed

+86
-0
lines changed

3 files changed

+86
-0
lines changed

Diff for: engine/engine_test.go

+23
Original file line numberDiff line numberDiff line change
@@ -235,6 +235,29 @@ func TestFunctionCustomState(t *testing.T) {
235235
assert.Equal(t, []string{"STATE_HELLO"}, customStates)
236236
}
237237

238+
func TestFunctionConditions(t *testing.T) {
239+
input := map[string]interface{}{}
240+
res, err := runTask("functionConditions.yaml", input, nil)
241+
242+
require.Nil(t, err)
243+
244+
assert.Equal(t, map[string]interface{}{
245+
"value": "Hello foobar !",
246+
}, res.Steps["asExpected"].Output)
247+
assert.Equal(t, "SAID_HELLO", res.Steps["asExpected"].State)
248+
assert.Equal(t, "Said hello to foobar", res.Steps["asExpected"].Error)
249+
250+
assert.Equal(t, map[string]interface{}{
251+
"value": "Hello foo !",
252+
}, res.Steps["notExpected"].Output)
253+
assert.Equal(t, "NOT_EXPECTED", res.Steps["notExpected"].State)
254+
assert.Equal(t, "Expected bar, got foo", res.Steps["notExpected"].Error)
255+
256+
assert.Nil(t, res.Steps["skipped"].Output)
257+
assert.Equal(t, "PRUNE", res.Steps["skipped"].State)
258+
assert.Equal(t, "No hello foo !", res.Steps["skipped"].Error)
259+
}
260+
238261
func TestFunctionPreHook(t *testing.T) {
239262
input := map[string]interface{}{}
240263
res, err := runTask("functionPreHook.yaml", input, nil)

Diff for: engine/functions_tests/hello-with-conditions.yaml

+34
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
name: hello-with-conditions
2+
description: Say hello with conditions
3+
action:
4+
type: echo::hello::world
5+
configuration:
6+
name: '{{.function_args.name}}'
7+
custom_states:
8+
- SAID_HELLO
9+
- NOT_EXPECTED
10+
conditions:
11+
- type: skip
12+
if:
13+
- value: '{{.function_args.skip | default `false`}}'
14+
operator: EQ
15+
expected: 'true'
16+
then:
17+
this: PRUNE
18+
message: 'No hello {{.function_args.name}} !'
19+
- type: check
20+
if:
21+
- value: '{{.function_args.name}}'
22+
operator: NE
23+
expected: '{{.function_args.expected}}'
24+
then:
25+
this: NOT_EXPECTED
26+
message: 'Expected {{.function_args.expected}}, got {{.function_args.name}}'
27+
- type: check
28+
if:
29+
- value: '{{.function_args.name}}'
30+
operator: EQ
31+
expected: '{{.function_args.expected}}'
32+
then:
33+
this: SAID_HELLO
34+
message: 'Said hello to {{.function_args.name}}'

Diff for: engine/templates_tests/functionConditions.yaml

+29
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
name: functionConditions
2+
description: Test function conditions
3+
title_format: "[test] Test function conditions"
4+
auto_runnable: true
5+
steps:
6+
asExpected:
7+
description: Say hello to foobar
8+
action:
9+
type: hello-with-conditions
10+
configuration:
11+
name: foobar
12+
expected: foobar
13+
14+
notExpected:
15+
description: Say hello to foo but expect bar
16+
action:
17+
type: hello-with-conditions
18+
configuration:
19+
name: foo
20+
expected: bar
21+
22+
skipped:
23+
description: Say hello to foo but expect bar
24+
action:
25+
type: hello-with-conditions
26+
configuration:
27+
name: foo
28+
expected: foor
29+
skip: true

0 commit comments

Comments
 (0)