-
Notifications
You must be signed in to change notification settings - Fork 21
/
handle_actions_test.go
72 lines (59 loc) · 1.61 KB
/
handle_actions_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
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
package openmock
import (
"testing"
"github.com/prashantv/gostub"
"github.com/stretchr/testify/assert"
)
type FakePerformer struct {
ReceivedContext Context
Performed bool
}
func (fp *FakePerformer) Perform(context Context) error {
fp.Performed = true
fp.ReceivedContext = context
return nil
}
func TestContextUpdate(t *testing.T) {
t.Run("update context for performing action", func(t *testing.T) {
mock := Mock{
Actions: []ActionDispatcher{{}},
Values: map[string]interface{}{
"foo": "bar",
},
}
fakePerformer := FakePerformer{}
defer gostub.StubFunc(&GetActualAction, &fakePerformer).Reset()
mock.DoActions(Context{})
assert.Equal(t, "bar", fakePerformer.ReceivedContext.Values["foo"])
})
t.Run("does not perform action if condition renders falsy", func(t *testing.T) {
unActingMock := Mock{
Expect: Expect{
Condition: "{{.Values.perform}}",
},
Actions: []ActionDispatcher{{}},
Values: map[string]interface{}{
"perform": false,
},
}
fakePerformer := FakePerformer{}
defer gostub.StubFunc(&GetActualAction, &fakePerformer).Reset()
unActingMock.DoActions(Context{})
assert.False(t, fakePerformer.Performed)
})
t.Run("does performs action if condition renders truthy", func(t *testing.T) {
actingMock := Mock{
Expect: Expect{
Condition: "{{.Values.perform}}",
},
Actions: []ActionDispatcher{{}},
Values: map[string]interface{}{
"perform": true,
},
}
fakePerformer := FakePerformer{}
defer gostub.StubFunc(&GetActualAction, &fakePerformer).Reset()
actingMock.DoActions(Context{})
assert.True(t, fakePerformer.Performed)
})
}