-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathtypes_test.go
54 lines (49 loc) · 1.98 KB
/
types_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
package periskop
import (
"errors"
"testing"
)
var aggregationKeyCases = []struct {
expectedAggregationKey string
errorMessage string
stacktrace []string
}{
{"testingError@af88b146", "error", []string{""}},
{"testingError@b8a5702f", "timeout error", []string{"line 0:", "error in testingError"}},
{"testingError@b8a5702f", "index error", []string{"line 0:", "error in testingError"}},
{"testingError@e1441017", "index error", []string{"line 0:", "index error", "line 1:", "line 4:", "checkTest()"}},
{"testingError@df41ce5a", "index error", []string{"line 0:", "index error", "line 1:", "line 5:", "checkTest()"}},
{"testingError@df41ce5a", "index error", []string{"line 0:", "index error", "line 1:", "line 5:", "checkFunc()"}},
}
func newMockErrorWithContext(stacktrace []string) ErrorWithContext {
errorInstance := newErrorInstance(errors.New("divisin by zero"), "testingError", stacktrace)
return NewErrorWithContext(errorInstance, SeverityError, nil)
}
func TestTypes_aggregationKey(t *testing.T) {
for _, tt := range aggregationKeyCases {
t.Run(tt.expectedAggregationKey, func(t *testing.T) {
errorWithContext := newMockErrorWithContext(tt.stacktrace)
resultAggregationKey := errorWithContext.aggregationKey()
if resultAggregationKey != tt.expectedAggregationKey {
t.Errorf("error in aggregationKey, expected: %s, got %s", tt.expectedAggregationKey, resultAggregationKey)
}
})
}
}
func TestTypes_addError(t *testing.T) {
errorWithContext := newMockErrorWithContext([]string{""})
errorAggregate := newAggregatedError("error@hash", SeverityWarning)
errorAggregate.addError(errorWithContext)
if errorAggregate.TotalCount != 1 {
t.Errorf("expected one error")
}
for i := 0; i < MaxErrors; i++ {
errorAggregate.addError(errorWithContext)
}
if errorAggregate.TotalCount != MaxErrors+1 {
t.Errorf("expected %v total errors", MaxErrors+1)
}
if len(errorAggregate.LatestErrors) != MaxErrors {
t.Errorf("expected %v latest errors", MaxErrors)
}
}