/
mock.go
135 lines (111 loc) · 3.17 KB
/
mock.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
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
package spec
import (
"github.com/pivotal-sydney/whiteboardbot/model"
"time"
"strconv"
"encoding/json"
. "github.com/pivotal-sydney/whiteboardbot/app"
"github.com/nlopes/slack"
)
type MockSlackClient struct {
PostMessageCalled bool
Message string
Entry *model.Entry
Status string
}
func (slackClient *MockSlackClient) PostMessage(message string, channel string, status string) {
slackClient.PostMessageCalled = true
slackClient.Message = message
slackClient.Status = status
}
func (slackClient *MockSlackClient) PostMessageWithMarkdown(message string, channel string, status string) {
slackClient.PostMessageCalled = true
slackClient.Message = message
slackClient.Status = status
}
func (slackClient *MockSlackClient) PostEntry(entry *model.Entry, channel string, status string) {
slackClient.Entry = entry
slackClient.Status = status
}
func (slackClient *MockSlackClient) GetUserDetails(user string) (slackUser SlackUser) {
slackUser.Username = user
if slackUser.Username == "UUserId" {
slackUser.Username = "user-name"
}
if slackUser.Username == "UUserId2" {
slackUser.Username = "user-name-two"
}
if slackUser.Username == "" {
slackUser.Username = "aleung"
}
slackUser.Author = "Andrew Leung"
slackUser.TimeZone = "Australia/Sydney"
return
}
func (slackClient *MockSlackClient) GetChannelDetails(channel string) (slackChannel *slack.Channel) {
slackChannel = &slack.Channel{}
if channel == "CChannelId" {
slackChannel.Name = "channel-name"
} else if channel == "CChannelId2" {
slackChannel.Name = "channel-name-two"
} else {
slackChannel.Name = "unknown"
}
return
}
type MockClock struct{}
func (clock MockClock) Now() time.Time {
return time.Date(2015, 1, 2, 0, 0, 0, 0, time.UTC)
}
type MockRestClient struct {
PostCalledCount int
Request model.WhiteboardRequest
StandupItems model.StandupItems
}
func (client MockRestClient) GetStandupItems(standupId int) (items model.StandupItems, ok bool) {
items = client.StandupItems
ok = true
return
}
func (client *MockRestClient) Post(request model.WhiteboardRequest) (itemId string, ok bool) {
client.PostCalledCount++
client.Request = request
ok = true
itemId = "1"
return
}
func (*MockRestClient) GetStandup(standupId string) (standup model.Standup, ok bool) {
id, _ := strconv.Atoi(standupId)
standup.Id = id
standup.TimeZone = "Australia/Sydney"
standup.Title = "Sydney"
ok = true
return
}
type MockStore struct {
StoreMap map[string]string
}
func (store *MockStore) Get(key string) (value string, ok bool) {
if store.StoreMap == nil {
store.StoreMap = make(map[string]string)
}
value, ok = store.StoreMap[key]
return
}
func (store *MockStore) Set(key string, value string) {
if store.StoreMap == nil {
store.StoreMap = make(map[string]string)
}
store.StoreMap[key] = value
}
func (store *MockStore) GetStandup(channel string) (standup model.Standup, ok bool) {
var standupJson string
standupJson, _ = store.Get(channel)
err := json.Unmarshal([]byte(standupJson), &standup)
ok = err == nil
return
}
func (store *MockStore) SetStandup(channel string, standup model.Standup) {
standupJson, _ := json.Marshal(standup)
store.Set(channel, string(standupJson))
}