-
Notifications
You must be signed in to change notification settings - Fork 4
/
errors_test.go
105 lines (100 loc) · 2.99 KB
/
errors_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
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
package sophos_test
import (
"testing"
"github.com/esurdam/go-sophos"
)
func TestErrors_Error(t *testing.T) {
tests := []struct {
name string
ee sophos.Errors
want string
}{
{"testNoFatalErrors", sophos.Errors{
{
Oattrs: []string{
"class",
"type",
},
Class: "packetfilter",
Fatal: 0,
Format: "The %_O object requires %_d for the %_A attribute.",
Msgtype: "DATATYPE_OBJECT_ATTRIBUTE",
Name: "The group object requires a Perl array for the members list attribute.",
NeverHide: 0,
Type: "group",
}, {
Oattrs: []string{
"class",
"type",
},
Class: "packetfilter",
Fatal: 0,
Format: "The %_O object requires %_d for the %_A attribute.",
Msgtype: "DATATYPE_OBJECT_ATTRIBUTE",
Name: "The group object requires a Perl array for the members list attribute.",
NeverHide: 0,
Type: "group",
},
}, "client do: error from UTM server: The group object requires a Perl array for the members list attribute."},
{"testFatalErrors", sophos.Errors{
{
Oattrs: []string{
"class",
"type",
},
Class: "packetfilter",
Fatal: 1,
Format: "The %_O object requires %_d for the %_A attribute.",
Msgtype: "DATATYPE_OBJECT_ATTRIBUTE",
Name: "The TEST object requires a TEST array for the members list attribute.",
NeverHide: 0,
Type: "group",
}}, "client do: FATAL error from UTM server: The TEST object requires a TEST array for the members list attribute."},
{"testNoErrors", sophos.Errors{}, "error accessing UTM interface: check status code. No Errors were retuned in response body."},
}
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
if got := tt.ee.Error(); got != tt.want {
t.Errorf("Errors.Error() = %v, want %v", got, tt.want)
}
})
}
}
func TestIsFatalErr(t *testing.T) {
type args struct {
err error
}
tests := []struct {
name string
args args
want bool
}{
{"testIsFatalErrorsT", args{sophos.Errors{{Fatal: 1}}}, true},
{"testIsFatal*ErrorsT", args{&sophos.Errors{{Fatal: 1}}}, true},
{"testIsFatalErrorT", args{sophos.Error{Fatal: 1}}, true},
{"testIsFatal*ErrorT", args{&sophos.Error{Fatal: 1}}, true},
{"testIsFatalErrorsT", args{sophos.Errors{{Fatal: 0}}}, false},
{"testIsFatal*ErrorsT", args{&sophos.Errors{{Fatal: 0}}}, false},
{"testIsFatalErrorT", args{sophos.Error{Fatal: 0}}, false},
{"testIsFatal*ErrorT", args{&sophos.Error{Fatal: 0}}, false},
{"testIsFatalnil", args{nil}, false},
}
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
if got := sophos.IsFatalErr(tt.args.err); got != tt.want {
t.Errorf("IsFatalErr() = %v, want %v", got, tt.want)
}
})
}
// what an error is demo
var err error
err = &sophos.Errors{{Fatal: 1, Name: "boom boom"}}
for _, e := range *err.(*sophos.Errors) {
if !e.IsFatal() {
t.Error("error should be fatal")
}
if e.Name != "boom boom" {
t.Error("error should be boom boom")
}
}
}