-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathmock_flusher_test.go
More file actions
59 lines (53 loc) · 1.13 KB
/
mock_flusher_test.go
File metadata and controls
59 lines (53 loc) · 1.13 KB
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
package buffer
import (
"reflect"
"testing"
"time"
)
func Test_newStringCounter(t *testing.T) {
type args struct {
errInput string
flushCost time.Duration
elements []string
}
tests := []struct {
name string
args args
want map[string]int
wantErr error
}{
{
name: "normal",
args: args{
errInput: "",
flushCost: time.Millisecond,
elements: []string{"A", "B", "C", "D", "D"},
},
want: map[string]int{"A": 1, "B": 1, "C": 1, "D": 2},
wantErr: nil,
},
{
name: "error",
args: args{
errInput: "A",
flushCost: time.Millisecond,
elements: []string{"A", "B", "C", "D", "D"},
},
want: map[string]int{},
wantErr: errErrInput,
},
}
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
co := newStringCounter(tt.args.errInput, tt.args.flushCost)
gotErr := co.Flush(tt.args.elements)
if gotErr != tt.wantErr {
t.Errorf("stringCounter got error = %v, want error %v", gotErr, tt.wantErr)
}
got := co.result()
if !reflect.DeepEqual(got, tt.want) {
t.Errorf("stringCounter got = %v, want %v", got, tt.want)
}
})
}
}