-
Notifications
You must be signed in to change notification settings - Fork 8
/
events_structs_test.go
84 lines (78 loc) · 2.45 KB
/
events_structs_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
package scalingo
import (
"encoding/json"
"fmt"
"testing"
)
var eventsSpecializeCases = map[string]struct {
Event *Event
// Expected
DetailedEventName string
DetailedEventString string
}{
"test event specialization": {
Event: &Event{
User: EventUser{
Username: "user1",
},
Type: EventRestart,
RawTypeData: json.RawMessage([]byte(`{"scope": ["web"]}`)),
},
DetailedEventName: "*scalingo.EventRestartType",
DetailedEventString: "containers [web] began to restart",
},
"test edit app event without with null force_https": {
Event: &Event{
Type: EventEditApp,
RawTypeData: json.RawMessage([]byte(`{"force_https": null}`)),
},
DetailedEventName: "*scalingo.EventEditAppType",
DetailedEventString: "application settings have been updated",
},
"test edit app event, force https enabled": {
Event: &Event{
Type: EventEditApp,
RawTypeData: json.RawMessage([]byte(`{"force_https": true}`)),
},
DetailedEventName: "*scalingo.EventEditAppType",
DetailedEventString: "application settings have been updated, Force HTTPS has been enabled",
},
"test edit app event, force https disabled": {
Event: &Event{
Type: EventEditApp,
RawTypeData: json.RawMessage([]byte(`{"force_https": false}`)),
},
DetailedEventName: "*scalingo.EventEditAppType",
DetailedEventString: "application settings have been updated, Force HTTPS has been disabled",
},
"test app run event for a command run by an operator": {
Event: &Event{
Type: EventRun,
RawTypeData: json.RawMessage([]byte(`{"command": ""}`)),
},
DetailedEventName: "*scalingo.EventRunType",
DetailedEventString: "one-off container for maintenance/support purposes",
},
"test app run event for a command run by a collaborator": {
Event: &Event{
Type: EventRun,
RawTypeData: json.RawMessage([]byte(`{"command": "bash"}`)),
},
DetailedEventName: "*scalingo.EventRunType",
DetailedEventString: "one-off container with command 'bash'",
},
}
func TestEvent_Specialize(t *testing.T) {
for msg, c := range eventsSpecializeCases {
t.Run(msg, func(t *testing.T) {
dev := c.Event.Specialize()
tdev := fmt.Sprintf("%T", dev)
if tdev != c.DetailedEventName {
t.Errorf("Expecting event of type %v, got %v", c.DetailedEventName, tdev)
}
if dev.String() != c.DetailedEventString {
t.Errorf("Expecting event string\n===\n%s\n=== got\n%s\n===", c.DetailedEventString, dev.String())
}
})
}
}