-
Notifications
You must be signed in to change notification settings - Fork 5
/
Copy pathtemplate_test.go
48 lines (41 loc) · 1.04 KB
/
template_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
package template
import (
"strings"
"testing"
)
type EmbedTemplate struct {
Template
}
func (m *EmbedTemplate) Message() string {
return "world"
}
func TestCustomStepIsCalled(t *testing.T) {
t.Run("Using interfaces", func(t *testing.T) {
s := &EmbedTemplate{}
res := s.customStep(s)
check(res, " world ", t)
})
t.Run("Define custom step via anonymous function", func(t *testing.T) {
m := new(Anonymous)
res := m.customStep(func() string {
return "world"
})
check(res, " world ", t)
})
t.Run("Using anonymous functions adapted to an interface", func(t *testing.T) {
customStepStep := MessageRetrieverAdapter(func() string {
return "world"
})
if customStepStep == nil {
t.Fatal("Can not continue with a nil custom step")
}
template := Template{}
res := template.customStep(customStepStep)
check(res, " world ", t)
})
}
func check(res string, expected string, t *testing.T) {
if !strings.Contains(res, expected) {
t.Errorf("Expected string '%s' was not found on returned string '%s'\n", expected, res)
}
}