@@ -103,58 +103,56 @@ func TestThreadedClient(t *testing.T) {
103
103
groupingKey string
104
104
policy DeliveryPolicy
105
105
wantPostType1 gomock.Matcher
106
- wantPostType2 gomock.Matcher
107
- wantthreadTSs timestampMap
106
+ wantThreadTSs timestampMap
108
107
}{
109
108
"Post, basic" : {
110
109
threadTSs : timestampMap {},
111
110
groupingKey : "" ,
112
111
policy : Post ,
113
112
wantPostType1 : EqChatPost (),
114
- wantthreadTSs : timestampMap {},
113
+ wantThreadTSs : timestampMap {},
115
114
},
116
115
"Post, no parent, with grouping" : {
117
116
threadTSs : timestampMap {},
118
117
groupingKey : groupingKey ,
119
118
policy : Post ,
120
119
wantPostType1 : EqChatPost (),
121
- wantthreadTSs : timestampMap {channel : {groupingKey : ts1 }},
120
+ wantThreadTSs : timestampMap {channel : {groupingKey : ts1 }},
122
121
},
123
122
"Post, with parent, with grouping" : {
124
123
threadTSs : timestampMap {channel : {groupingKey : ts2 }},
125
124
groupingKey : groupingKey ,
126
125
policy : Post ,
127
126
wantPostType1 : EqChatPost (),
128
- wantthreadTSs : timestampMap {channel : {groupingKey : ts2 }},
127
+ wantThreadTSs : timestampMap {channel : {groupingKey : ts2 }},
129
128
},
130
129
"PostAndUpdate, no parent. First post should not be updated" : {
131
130
threadTSs : timestampMap {},
132
131
groupingKey : groupingKey ,
133
132
policy : PostAndUpdate ,
134
133
wantPostType1 : EqChatPost (),
135
- wantthreadTSs : timestampMap {channel : {groupingKey : ts1 }},
134
+ wantThreadTSs : timestampMap {channel : {groupingKey : ts1 }},
136
135
},
137
136
"PostAndUpdate, with parent. First post should be updated" : {
138
137
threadTSs : timestampMap {channel : {groupingKey : ts2 }},
139
138
groupingKey : groupingKey ,
140
139
policy : PostAndUpdate ,
141
- wantPostType1 : EqChatPost (),
142
- wantPostType2 : EqChatUpdate (),
143
- wantthreadTSs : timestampMap {channel : {groupingKey : ts2 }},
140
+ wantPostType1 : EqChatUpdate (),
141
+ wantThreadTSs : timestampMap {channel : {groupingKey : ts2 }},
144
142
},
145
- "Update, no parent. Only call should be post " : {
143
+ "Update, no parent. There should be no call, no new thread " : {
146
144
threadTSs : timestampMap {},
147
145
groupingKey : groupingKey ,
148
146
policy : Update ,
149
- wantPostType1 : EqChatPost () ,
150
- wantthreadTSs : timestampMap {channel : { groupingKey : ts1 } },
147
+ wantPostType1 : nil ,
148
+ wantThreadTSs : timestampMap {},
151
149
},
152
150
"Update, with parent. Only call should be update" : {
153
151
threadTSs : timestampMap {channel : {groupingKey : ts2 }},
154
152
groupingKey : groupingKey ,
155
153
policy : Update ,
156
154
wantPostType1 : EqChatUpdate (),
157
- wantthreadTSs : timestampMap {channel : {groupingKey : ts2 }},
155
+ wantThreadTSs : timestampMap {channel : {groupingKey : ts2 }},
158
156
},
159
157
}
160
158
for name , tc := range tests {
@@ -163,19 +161,19 @@ func TestThreadedClient(t *testing.T) {
163
161
defer ctrl .Finish ()
164
162
m := mocks .NewMockSlackClient (ctrl )
165
163
166
- m .EXPECT ().
167
- SendMessageContext (gomock .Any (), gomock .Eq (channel ), tc .wantPostType1 ).
168
- Return (channelID , ts1 , "" , nil )
164
+ expectedFunctionCall := m .EXPECT ().
165
+ SendMessageContext (gomock .Any (), gomock .Eq (channel ), tc .wantPostType1 )
169
166
170
- if tc .wantPostType2 != nil {
171
- m .EXPECT ().
172
- SendMessageContext (gomock .Any (), gomock .Eq (channelID ), tc .wantPostType2 )
167
+ if tc .wantPostType1 != nil {
168
+ expectedFunctionCall .Return (channelID , ts1 , "" , nil )
169
+ } else {
170
+ expectedFunctionCall .MaxTimes (0 )
173
171
}
174
172
175
173
client := NewThreadedClient (m , & state {rate .NewLimiter (rate .Inf , 1 ), tc .threadTSs , channelMap {}})
176
174
err := client .SendMessage (context .TODO (), channel , tc .groupingKey , false , tc .policy , []slack.MsgOption {})
177
175
assert .NoError (t , err )
178
- assert .Equal (t , tc .wantthreadTSs , client .ThreadTSs )
176
+ assert .Equal (t , tc .wantThreadTSs , client .ThreadTSs )
179
177
})
180
178
}
181
179
}
0 commit comments