-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain_test.go
87 lines (76 loc) · 2.05 KB
/
main_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
package main
import (
"testing"
"github.com/stretchr/testify/assert"
)
func TestSanitizeStationIDs(t *testing.T) {
// Set up environment variables
t.Setenv("STATION_IDS", "KATX,KRAX,KTLX")
t.Setenv("PUSHOVER_API_TOKEN", "your_api_token")
t.Setenv("PUSHOVER_USER_KEY", "your_user_key")
input := "KATX, KRAX; KTLX"
expected := []string{"KATX", "KRAX", "KTLX"}
result := sanitizeStationIDs(input)
assert.Equal(t, expected, result)
}
func TestRadarMode(t *testing.T) {
tests := []struct {
vcp string
expected string
err bool
}{
{"R35", "Clear Air", false},
{"R215", "Precipitation", false},
{"R999", "", true},
}
for _, test := range tests {
result, err := radarMode(test.vcp)
if test.err {
assert.Error(t, err)
} else {
assert.NoError(t, err)
assert.Equal(t, test.expected, result)
}
}
}
func TestCompareRadarData(t *testing.T) {
oldData := &RadarData{
VCP: "R35",
Status: "Operational",
PowerSource: "Commercial",
GenState: "Running",
}
newData := &RadarData{
VCP: "R215",
Status: "Operational",
PowerSource: "Backup",
GenState: "Stopped",
}
changed, message := compareRadarData(oldData, newData)
assert.True(t, changed)
assert.Contains(t, message, "The Radar is in Precipitation Mode -- Precipitation Detected")
assert.Contains(t, message, "Power source changed from Commercial to Backup")
assert.Contains(t, message, "Generator state changed from Running to Stopped")
}
func TestGenStateSimp(t *testing.T) {
tests := []struct {
genInput string
expected string
expectErr bool
}{
{"Switched to Auxiliary Power|Utility PWR Available|Generator On", "On", false},
{"Switched to Auxiliary Power|Generator On", "On", false},
{"Utility PWR Available|Generator On", "On", false},
{"Utility PWR Available", "Off", false},
{"Unknown Input", "", true},
}
for _, test := range tests {
result, err := genStateSimp(test.genInput)
if test.expectErr {
assert.Error(t, err)
} else {
assert.NoError(t, err)
assert.Equal(t, test.expected, result)
}
}
}