-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmigration_test.go
More file actions
96 lines (89 loc) · 3.12 KB
/
migration_test.go
File metadata and controls
96 lines (89 loc) · 3.12 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
85
86
87
88
89
90
91
92
93
94
95
96
package flashduty
import (
"encoding/json"
"strings"
"testing"
"time"
)
// These tests lock in the int64 -> Timestamp/TimestampMilli migration: they fail
// if a migrated instant field is reverted to a raw integer, or if a trap field
// (duration/offset) is wrongly converted to a timestamp.
func TestMigration_IncidentDetail_SecondsRenderRFC3339(t *testing.T) {
withLocal(t, "UTC")
d := IncidentDetail{
IncidentID: "abc",
StartTime: Timestamp(time.Date(2026, 5, 28, 8, 0, 0, 0, time.UTC).Unix()),
// AckTime / CloseTime left zero (omitempty) -> must be dropped, not "1970"
}
b, err := json.Marshal(d)
if err != nil {
t.Fatalf("marshal: %v", err)
}
s := string(b)
if !strings.Contains(s, `"start_time":"2026-05-28T08:00:00Z"`) {
t.Errorf("start_time not RFC3339: %s", s)
}
if strings.Contains(s, "ack_time") || strings.Contains(s, "close_time") {
t.Errorf("zero omitempty time fields should be dropped, not rendered: %s", s)
}
}
func TestMigration_TimelineEvent_MillisRenderRFC3339(t *testing.T) {
withLocal(t, "UTC")
e := TimelineEvent{
Type: "ack",
Timestamp: TimestampMilli(time.Date(2026, 5, 28, 8, 0, 0, 0, time.UTC).UnixMilli()),
}
b, err := json.Marshal(e)
if err != nil {
t.Fatalf("marshal: %v", err)
}
if !strings.Contains(string(b), `"timestamp":"2026-05-28T08:00:00Z"`) {
t.Errorf("ms timestamp not RFC3339: %s", b)
}
}
func TestMigration_ScheduleLayer_TrapsStayNumeric_InstantsRender(t *testing.T) {
withLocal(t, "UTC")
layer := ScheduleLayer{
RotationDuration: 86400, // duration -> MUST stay numeric
HandoffTime: 3600, // within-cycle offset -> numeric
RestrictEnd: 3600, // cyclic-window offset -> numeric
EnableTime: Timestamp(time.Date(2026, 5, 28, 8, 0, 0, 0, time.UTC).Unix()),
LayerStart: Timestamp(time.Date(2026, 5, 28, 9, 0, 0, 0, time.UTC).Unix()),
}
b, err := json.Marshal(layer)
if err != nil {
t.Fatalf("marshal: %v", err)
}
s := string(b)
for _, num := range []string{`"rotation_duration":86400`, `"handoff_time":3600`, `"restrict_end":3600`} {
if !strings.Contains(s, num) {
t.Errorf("trap field not left numeric (want %s): %s", num, s)
}
}
if !strings.Contains(s, `"enable_time":"2026-05-28T08:00:00Z"`) {
t.Errorf("enable_time not RFC3339: %s", s)
}
if !strings.Contains(s, `"layer_start":"2026-05-28T09:00:00Z"`) {
t.Errorf("layer_start not RFC3339: %s", s)
}
}
func TestMigration_CreateIncidentOutput_Decode(t *testing.T) {
var out CreateIncidentOutput
body := `{"incident_id":"69db2ef1a0fe7db6448b14f1","title":"API test incident for docs"}`
if err := json.Unmarshal([]byte(body), &out); err != nil {
t.Fatalf("decode: %v", err)
}
if out.IncidentID != "69db2ef1a0fe7db6448b14f1" || out.Title != "API test incident for docs" {
t.Errorf("got %+v", out)
}
}
func TestMigration_CreateStatusIncidentOutput_Decode(t *testing.T) {
var out CreateStatusIncidentOutput
body := `{"change_id":6294539747131,"change_name":"API Test Incident"}`
if err := json.Unmarshal([]byte(body), &out); err != nil {
t.Fatalf("decode: %v", err)
}
if out.ChangeID != 6294539747131 || out.ChangeName != "API Test Incident" {
t.Errorf("got %+v", out)
}
}