Skip to content

Commit 385fd59

Browse files
committed
split and update tests
1 parent c22f4ce commit 385fd59

3 files changed

Lines changed: 69 additions & 51 deletions

File tree

vars/process_test.go

Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,51 @@
1+
package vars
2+
3+
import (
4+
"testing"
5+
6+
"github.com/stretchr/testify/assert"
7+
)
8+
9+
func TestVarsProcess(t *testing.T) {
10+
t.Parallel()
11+
12+
tests := []struct {
13+
name string
14+
vars map[string]string
15+
input string
16+
contains []string
17+
excludes []string
18+
}{
19+
{
20+
name: "replaces known vars",
21+
vars: map[string]string{"ID": "af248b4b-a0e1-4e0f-94c6-4f0b4e0c7c42"},
22+
input: "curl http://do.the.thing/pie/{{.ID}}",
23+
contains: []string{"af248b4b-a0e1-4e0f-94c6-4f0b4e0c7c42"},
24+
excludes: []string{"{{.ID}}"},
25+
},
26+
{
27+
name: "leaves unknown vars untouched",
28+
vars: map[string]string{"ID": "af248b4b-a0e1-4e0f-94c6-4f0b4e0c7c42"},
29+
input: "curl http://do.the.thing/pie/{{.ID}}/{{.Subid}}",
30+
contains: []string{"af248b4b-a0e1-4e0f-94c6-4f0b4e0c7c42", "{{.Subid}}"},
31+
excludes: []string{"{{.ID}}"},
32+
},
33+
}
34+
35+
for _, tt := range tests {
36+
tt := tt
37+
t.Run(tt.name, func(t *testing.T) {
38+
t.Parallel()
39+
40+
v := Vars(tt.vars)
41+
out := v.Process(tt.input)
42+
43+
for _, s := range tt.contains {
44+
assert.Contains(t, out, s)
45+
}
46+
for _, s := range tt.excludes {
47+
assert.NotContains(t, out, s)
48+
}
49+
})
50+
}
51+
}

vars/set_test.go

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
package vars
2+
3+
import (
4+
"testing"
5+
6+
"github.com/stretchr/testify/assert"
7+
)
8+
9+
func TestVarsSet(t *testing.T) {
10+
t.Parallel()
11+
12+
v := Vars{}
13+
v.Set("foo", "bar")
14+
v.Set("baz", "biz")
15+
16+
assert.Equal(t, "bar", map[string]string(v)["foo"])
17+
assert.Equal(t, "biz", map[string]string(v)["baz"])
18+
}

vars/vars_test.go

Lines changed: 0 additions & 51 deletions
This file was deleted.

0 commit comments

Comments
 (0)