-
Notifications
You must be signed in to change notification settings - Fork 2
/
print_test.go
69 lines (63 loc) · 1.25 KB
/
print_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
package eclint_test
import (
"bytes"
"context"
"errors"
"testing"
"gitlab.com/greut/eclint"
)
func TestPrintErrors(t *testing.T) {
tests := []struct {
Name string
HasOutput bool
Errors []error
}{
{
Name: "no errors",
HasOutput: false,
Errors: []error{},
}, {
Name: "simple error",
HasOutput: true,
Errors: []error{
errors.New("random error"),
},
}, {
Name: "validation error",
HasOutput: true,
Errors: []error{
eclint.ValidationError{},
},
}, {
Name: "complete validation error",
HasOutput: true,
Errors: []error{
eclint.ValidationError{
Line: []byte("Hello"),
Index: 1,
Position: 2,
},
},
},
}
ctx := context.TODO()
for _, tc := range tests {
tc := tc
// Test the nominal case
t.Run(tc.Name, func(t *testing.T) {
t.Parallel()
buf := bytes.NewBuffer(make([]byte, 0, 1024))
opt := &eclint.Option{
Stdout: buf,
}
err := eclint.PrintErrors(ctx, opt, tc.Name, tc.Errors)
if err != nil {
t.Error("no errors were expected")
}
outputLength := buf.Len()
if (outputLength > 0) != tc.HasOutput {
t.Errorf("unexpected output length got %d, wanted %v", outputLength, tc.HasOutput)
}
})
}
}