forked from ovh/venom
-
Notifications
You must be signed in to change notification settings - Fork 0
/
process_testcase_test.go
50 lines (41 loc) · 1.16 KB
/
process_testcase_test.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
package venom
import (
"fmt"
"testing"
"github.com/stretchr/testify/assert"
"gopkg.in/yaml.v2"
)
func TestProcessVariableAssigments(t *testing.T) {
assign := AssignStep{}
assign.Assignments = make(map[string]Assignment)
assign.Assignments["assignVar"] = Assignment{
From: "here.some.value",
}
assign.Assignments["assignVarWithRegex"] = Assignment{
From: "here.some.value",
Regex: `this is (?s:(.*))`,
}
b, _ := yaml.Marshal(assign)
t.Log("\n" + string(b))
var stepIn TestStep
assert.NoError(t, yaml.Unmarshal(b, &stepIn))
tcVars := H{
"here.some.value": "this is the \nvalue",
}
result, is, err := ProcessVariableAssigments("", tcVars, stepIn, TestLogger{t})
assert.True(t, is)
assert.NoError(t, err)
assert.NotNil(t, result)
t.Log(result)
assert.Equal(t, "map[assignVar:this is the \nvalue assignVarWithRegex:the \nvalue]", fmt.Sprint(result))
var wrongStepIn TestStep
b = []byte(`type: exec
script: echo 'foo'
`)
assert.NoError(t, yaml.Unmarshal(b, &wrongStepIn))
result, is, err = ProcessVariableAssigments("", tcVars, wrongStepIn, TestLogger{t})
assert.False(t, is)
assert.NoError(t, err)
assert.Nil(t, result)
assert.Empty(t, result)
}