@@ -17,15 +17,15 @@ func TestNextToken(t *testing.T) {
17
17
s , testCalls := sinkTest (t )
18
18
for _ , c := range testCalls {
19
19
token := s .NextToken (t )
20
- assert .Equal (t , c .token , token )
20
+ assert .Equal (t , c .Token , token )
21
21
}
22
22
}
23
23
24
24
func TestNextTokenTimeout (t * testing.T ) {
25
25
s , testCalls := sinkTest (t , WithTimeout (10 * time .Millisecond ))
26
26
for _ , c := range testCalls {
27
27
token := s .NextToken (t )
28
- assert .Equal (t , c .token , token )
28
+ assert .Equal (t , c .Token , token )
29
29
}
30
30
31
31
// Create a new T so we can expect it to fail without failing the overall test.
@@ -38,17 +38,17 @@ func TestNextTokens(t *testing.T) {
38
38
s , testCalls := sinkTest (t )
39
39
for i := 0 ; i < 5 ; i ++ {
40
40
tokens := s .NextTokens (t , 2 )
41
- assert .Equal (t , testCalls [2 * i ].token , tokens [0 ])
42
- assert .Equal (t , testCalls [2 * i + 1 ].token , tokens [1 ])
41
+ assert .Equal (t , testCalls [2 * i ].Token , tokens [0 ])
42
+ assert .Equal (t , testCalls [2 * i + 1 ].Token , tokens [1 ])
43
43
}
44
44
}
45
45
46
46
func TestNextTokensTimeout (t * testing.T ) {
47
47
s , testCalls := sinkTest (t , WithTimeout (10 * time .Millisecond ))
48
48
for i := 0 ; i < 5 ; i ++ {
49
49
tokens := s .NextTokens (t , 2 )
50
- assert .Equal (t , testCalls [2 * i ].token , tokens [0 ])
51
- assert .Equal (t , testCalls [2 * i + 1 ].token , tokens [1 ])
50
+ assert .Equal (t , testCalls [2 * i ].Token , tokens [0 ])
51
+ assert .Equal (t , testCalls [2 * i + 1 ].Token , tokens [1 ])
52
52
}
53
53
54
54
// Create a new T so we can expect it to fail without failing the overall test.
@@ -61,17 +61,17 @@ func TestNextCall(t *testing.T) {
61
61
s , testCalls := sinkTest (t )
62
62
for _ , c := range testCalls {
63
63
token , attributes := s .NextCall (t )
64
- require .Equal (t , c .token , token )
65
- require .Equal (t , c .attrs , attributes )
64
+ require .Equal (t , c .Token , token )
65
+ require .Equal (t , c .Attrs , attributes )
66
66
}
67
67
}
68
68
69
69
func TestNextCallTimeout (t * testing.T ) {
70
70
s , testCalls := sinkTest (t , WithTimeout (10 * time .Millisecond ))
71
71
for _ , c := range testCalls {
72
72
token , attributes := s .NextCall (t )
73
- require .Equal (t , c .token , token )
74
- require .Equal (t , c .attrs , attributes )
73
+ require .Equal (t , c .Token , token )
74
+ require .Equal (t , c .Attrs , attributes )
75
75
}
76
76
77
77
// Create a new T so we can expect it to fail without failing the overall test.
@@ -83,14 +83,14 @@ func TestNextCallTimeout(t *testing.T) {
83
83
func TestExpectToken (t * testing.T ) {
84
84
s , testCalls := sinkTest (t )
85
85
for _ , c := range testCalls {
86
- s .ExpectToken (t , c .token )
86
+ s .ExpectToken (t , c .Token )
87
87
}
88
88
}
89
89
90
90
func TestExpectTokenTimeout (t * testing.T ) {
91
91
s , testCalls := sinkTest (t , WithTimeout (10 * time .Millisecond ))
92
92
for _ , c := range testCalls {
93
- s .ExpectToken (t , c .token )
93
+ s .ExpectToken (t , c .Token )
94
94
}
95
95
96
96
// Create a new T so we can expect it to fail without failing the overall test.
@@ -102,14 +102,14 @@ func TestExpectTokenTimeout(t *testing.T) {
102
102
func TestExpectTokens (t * testing.T ) {
103
103
s , testCalls := sinkTest (t )
104
104
for i := 0 ; i < 5 ; i ++ {
105
- s .ExpectTokens (t , testCalls [2 * i ].token , testCalls [2 * i + 1 ].token )
105
+ s .ExpectTokens (t , testCalls [2 * i ].Token , testCalls [2 * i + 1 ].Token )
106
106
}
107
107
}
108
108
109
109
func TestExpectTokensTimeout (t * testing.T ) {
110
110
s , testCalls := sinkTest (t , WithTimeout (10 * time .Millisecond ))
111
111
for i := 0 ; i < 5 ; i ++ {
112
- s .ExpectTokens (t , testCalls [2 * i ].token , testCalls [2 * i + 1 ].token )
112
+ s .ExpectTokens (t , testCalls [2 * i ].Token , testCalls [2 * i + 1 ].Token )
113
113
}
114
114
115
115
// Create a new T so we can expect it to fail without failing the overall test.
@@ -121,14 +121,14 @@ func TestExpectTokensTimeout(t *testing.T) {
121
121
func TestExpectCall (t * testing.T ) {
122
122
s , testCalls := sinkTest (t )
123
123
for _ , c := range testCalls {
124
- s .ExpectCall (t , c .token , c .attrs )
124
+ s .ExpectCall (t , c .Token , c .Attrs )
125
125
}
126
126
}
127
127
128
128
func TestExpectCallTimeout (t * testing.T ) {
129
129
s , testCalls := sinkTest (t , WithTimeout (10 * time .Millisecond ))
130
130
for _ , c := range testCalls {
131
- s .ExpectCall (t , c .token , c .attrs )
131
+ s .ExpectCall (t , c .Token , c .Attrs )
132
132
}
133
133
134
134
// Create a new T so we can expect it to fail without failing the overall test.
@@ -137,6 +137,35 @@ func TestExpectCallTimeout(t *testing.T) {
137
137
assert .True (t , tt .Failed ())
138
138
}
139
139
140
+ func TestExpectCalls (t * testing.T ) {
141
+ s , testCalls := sinkTest (t )
142
+ testCallsOutOfOrder := make ([]* Call , 0 , 10 )
143
+ for i := 0 ; i < len (testCalls ); i += 2 {
144
+ testCallsOutOfOrder = append (testCallsOutOfOrder , testCalls [i ])
145
+ }
146
+ for i := 1 ; i < len (testCalls ); i += 2 {
147
+ testCallsOutOfOrder = append (testCallsOutOfOrder , testCalls [i ])
148
+ }
149
+ s .ExpectCalls (t , testCallsOutOfOrder ... )
150
+ }
151
+
152
+ func TestExpectCallsTimeout (t * testing.T ) {
153
+ s , testCalls := sinkTest (t , WithTimeout (10 * time .Millisecond ))
154
+ testCallsOutOfOrder := make ([]* Call , 0 , 10 )
155
+ for i := 0 ; i < len (testCalls ); i += 2 {
156
+ testCallsOutOfOrder = append (testCallsOutOfOrder , testCalls [i ])
157
+ }
158
+ for i := 1 ; i < len (testCalls ); i += 2 {
159
+ testCallsOutOfOrder = append (testCallsOutOfOrder , testCalls [i ])
160
+ }
161
+ s .ExpectCalls (t , testCallsOutOfOrder ... )
162
+
163
+ // Create a new T so we can expect it to fail without failing the overall test.
164
+ tt := new (testing.T )
165
+ s .ExpectCalls (tt , new (Call ))
166
+ assert .True (t , tt .Failed ())
167
+ }
168
+
140
169
func TestExpectNoCalls (t * testing.T ) {
141
170
s , _ := sinkTest (t )
142
171
s .NextTokens (t , 10 ) // drain the channel
@@ -156,24 +185,24 @@ func TestExpectNoCallsFailure(t *testing.T) {
156
185
func TestWithCallBuffer (t * testing.T ) {
157
186
s , testCalls := sinkTest (t , WithCallBuffer (5 ))
158
187
for i := 0 ; i < 10 ; i ++ {
159
- s .ExpectCall (t , testCalls [i ].token , testCalls [i ].attrs )
188
+ s .ExpectCall (t , testCalls [i ].Token , testCalls [i ].Attrs )
160
189
}
161
190
}
162
191
163
- func sinkTest (t * testing.T , opts ... SinkOpt ) (* Sink , []* call ) {
192
+ func sinkTest (t * testing.T , opts ... SinkOpt ) (* Sink , []* Call ) {
164
193
s := NewSink (opts ... )
165
- testCalls := make ([]* call , 0 , 10 )
194
+ testCalls := make ([]* Call , 0 , 10 )
166
195
for i := 0 ; i < 10 ; i ++ {
167
- testCalls = append (testCalls , & call {
168
- token : []byte (fmt .Sprintf ("token-%d" , i )),
169
- attrs : map [string ]any {
196
+ testCalls = append (testCalls , & Call {
197
+ Token : []byte (fmt .Sprintf ("token-%d" , i )),
198
+ Attrs : map [string ]any {
170
199
"key" : fmt .Sprintf ("value-%d" , i ),
171
200
},
172
201
})
173
202
}
174
203
go func () {
175
204
for _ , c := range testCalls {
176
- require .NoError (t , s .Callback (context .Background (), c .token , c .attrs ))
205
+ require .NoError (t , s .Callback (context .Background (), c .Token , c .Attrs ))
177
206
}
178
207
}()
179
208
return s , testCalls
0 commit comments