-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathauditEvent_test.go
More file actions
84 lines (81 loc) · 1.73 KB
/
auditEvent_test.go
File metadata and controls
84 lines (81 loc) · 1.73 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
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
package types
import (
"reflect"
"testing"
)
func TestAuditEvent_ToCSV(t *testing.T) {
type fields struct {
UserID string
ID uint64
EventType string
Content string
}
tests := []struct {
name string
fields fields
want string
}{
{
name: "Happy path",
fields: fields{"jappleseed", uint64(1), "command", "DO THIS NOW"},
want: "jappleseed,1,command,DO THIS NOW",
},
}
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
ae := &AuditEvent{
UserID: tt.fields.UserID,
ID: tt.fields.ID,
EventType: tt.fields.EventType,
Content: tt.fields.Content,
}
if got := ae.ToCSV(); got != tt.want {
t.Errorf("AuditEvent.ToCSV() = %v, want %v", got, tt.want)
}
})
}
}
func TestParseAuditEvent(t *testing.T) {
type args struct {
csv string
}
tests := []struct {
name string
args args
want AuditEvent
wantErr bool
}{
{
name: "Happy path",
args: args{"jappleseed,1,command,DO THIS NOW"},
want: AuditEvent{"jappleseed", uint64(1), "command", "DO THIS NOW"},
},
{
name: "Too many args",
args: args{"jappleseed,1,command,DO THIS NOW,what?"},
wantErr: true,
},
{
name: "Too few args",
args: args{"jappleseed,1,command"},
wantErr: true,
},
{
name: "ID is string",
args: args{"jappleseed,DEAD-BEEF,command,DO THIS NOW"},
wantErr: true,
},
}
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
got, err := ParseAuditEvent(tt.args.csv)
if (err != nil) != tt.wantErr {
t.Errorf("ParseAuditEvent() error = %v, wantErr %v", err, tt.wantErr)
return
}
if !reflect.DeepEqual(got, tt.want) {
t.Errorf("ParseAuditEvent() = %v, want %v", got, tt.want)
}
})
}
}