-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathwrapper_test.go
83 lines (78 loc) · 1.72 KB
/
wrapper_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
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
package csvprocessor_test
import (
"context"
"reflect"
"testing"
"github.com/sivaramasubramanian/csvprocessor"
)
func TestPanicSafe(t *testing.T) {
type args struct {
transformer csvprocessor.CsvRowTransformer
log csvprocessor.Logger
}
tests := []struct {
name string
args args
want csvprocessor.CsvRowTransformer
}{
{
name: "Test panic is recovered",
args: args{
transformer: func(ctx context.Context, s []string) []string {
panic("test")
},
log: t.Logf,
},
},
{
name: "Test non-panic transformer",
args: args{
transformer: csvprocessor.NoOpTransformer(),
log: t.Logf,
},
},
}
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
csvprocessor.PanicSafe(tt.args.transformer, tt.args.log)(context.TODO(), []string{})
})
}
}
func TestDebugWrapper(t *testing.T) {
var calls = 0
type args struct {
transformer csvprocessor.CsvRowTransformer
log csvprocessor.Logger
callCount int
}
tests := []struct {
name string
args args
want csvprocessor.CsvRowTransformer
}{
{
name: "Test debug logs are called",
args: args{
transformer: csvprocessor.NoOpTransformer(),
log: callCount(t.Logf, &calls),
callCount: 2,
},
},
}
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
csvprocessor.DebugWrapper(tt.args.transformer, tt.args.log)(context.TODO(), []string{})
if tt.args.callCount > 0 {
if !reflect.DeepEqual(calls, tt.args.callCount) {
t.Errorf("DebugWrapper() = %v, want %v", calls, tt.want)
}
}
})
}
}
func callCount(log csvprocessor.Logger, count *int) csvprocessor.Logger {
return func(format string, args ...any) {
*count++
log(format, args...)
}
}