-
-
Notifications
You must be signed in to change notification settings - Fork 521
/
helpers_test.go
105 lines (83 loc) · 1.94 KB
/
helpers_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 cameradar
import (
"testing"
"github.com/stretchr/testify/assert"
)
func TestReplace(t *testing.T) {
validStream1 := Stream{
Device: "fakeDevice",
Address: "fakeAddress",
Port: 1,
}
validStream2 := Stream{
Device: "fakeDevice",
Address: "differentFakeAddress",
Port: 2,
}
invalidStream := Stream{
Device: "invalidDevice",
Address: "anotherFakeAddress",
Port: 3,
}
invalidStreamModified := Stream{
Device: "updatedDevice",
Address: "anotherFakeAddress",
Port: 3,
}
testCases := []struct {
streams []Stream
newStream Stream
expectedStreams []Stream
}{
{
streams: []Stream{validStream1, validStream2, invalidStream},
newStream: invalidStreamModified,
expectedStreams: []Stream{validStream1, validStream2, invalidStreamModified},
},
}
for _, test := range testCases {
streams := replace(test.streams, test.newStream)
assert.Equal(t, len(test.expectedStreams), len(streams))
for _, expectedStream := range test.expectedStreams {
assert.Contains(t, streams, expectedStream)
}
}
}
func TestGetCameraRTSPURL(t *testing.T) {
validStream := Stream{
Address: "1.2.3.4",
Username: "ullaakut",
Password: "ba69897483886f0d2b0afb6345b76c0c",
Routes: []string{"cameradar.sdp"},
Port: 1337,
}
testCases := []struct {
stream Stream
expectedRTSPURL string
}{
{
stream: validStream,
expectedRTSPURL: "rtsp://ullaakut:[email protected]:1337/cameradar.sdp",
},
}
for _, test := range testCases {
assert.Equal(t, test.expectedRTSPURL, GetCameraRTSPURL(test.stream))
}
}
func TestGetCameraAdminPanelURL(t *testing.T) {
validStream := Stream{
Address: "1.2.3.4",
}
testCases := []struct {
stream Stream
expectedRTSPURL string
}{
{
stream: validStream,
expectedRTSPURL: "http://1.2.3.4/",
},
}
for _, test := range testCases {
assert.Equal(t, test.expectedRTSPURL, GetCameraAdminPanelURL(test.stream))
}
}