-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathdecisionmaker_test.go
47 lines (33 loc) · 1.03 KB
/
decisionmaker_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
package main
import (
"github.com/minisu/ipdip/repository/inmemory"
"github.com/stretchr/testify/assert"
"testing"
)
func Test_decisionMaker_create_and_get(t *testing.T) {
m := DecisionMaker{ repository: inmemory.NewInMemoryDecisionRepo() }
name := "Which flavor?"
options := []string{"Vanilla", "Chocolate"}
id, err := m.createDecision(name, options)
if id == [16]byte{} || err != nil {
t.Failed()
}
d, err := m.getDecision(id)
assert.Equal(t, id.String(), d.Id)
assert.Equal(t, name, d.Name)
assert.Equal(t, "", d.DecidedOption)
assert.Equal(t, options, d.Options)
}
func Test_decisionMaker_decide(t *testing.T) {
m := DecisionMaker{ repository: inmemory.NewInMemoryDecisionRepo() }
name := "Which flavor?"
options := []string{"Vanilla", "Chocolate"}
id, err := m.createDecision(name, options)
assert.Nil(t, err)
d, err := m.decide(id)
assert.Contains(t, options, d.DecidedOption)
d, err = m.decide(id)
assert.NotNil(t, err)
d2, err := m.getDecision(id)
assert.Equal(t, d.DecidedOption, d2.DecidedOption)
}