-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathstep_test.go
57 lines (47 loc) · 1.24 KB
/
step_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
51
52
53
54
55
56
57
package expandvars_test
import (
"os"
"strings"
"testing"
"github.com/cucumber/godog"
"github.com/stretchr/testify/assert"
"github.com/godogx/expandvars"
)
func TestExpandStep(t *testing.T) {
t.Parallel()
expanders := []interface{}{
// Raw replacer.
strings.NewReplacer("$TO", "Berlin"),
// Our expanders.
expandvars.Pairs{
"HUSBAND": "John",
},
func() expandvars.Pairs {
return expandvars.Pairs{
"WIFE": "Jane",
}
},
func() expandvars.Expander {
return func(s string) string {
return strings.ReplaceAll(s, "$DURATION", "and stay there for 3 days")
}
},
func(s string) string {
return strings.ReplaceAll(s, "$FROM", "Paris")
},
expandvars.Expander(func(s string) string {
return strings.ReplaceAll(s, "$TRANSPORT", "by bus")
}),
// Os.
expandvars.EnvExpander,
}
// Set os env.
assert.NoError(t, os.Setenv("GREETINGS", "Hi Dave"))
defer func() {
_ = os.Unsetenv("GREETINGS") //nolint:errcheck
}()
step := &godog.Step{Text: "$GREETINGS, $HUSBAND & $WIFE are going from $FROM to $TO $TRANSPORT $DURATION"}
expected := "Hi Dave, John & Jane are going from Paris to Berlin by bus and stay there for 3 days"
expandvars.ExpandStep(step, expanders...)
assert.Equal(t, expected, step.Text)
}