-
Notifications
You must be signed in to change notification settings - Fork 4
Expand file tree
/
Copy pathcameras_test.go
More file actions
62 lines (45 loc) · 1.73 KB
/
cameras_test.go
File metadata and controls
62 lines (45 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
package securityspy_test
import (
"encoding/xml"
"testing"
"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/require"
"golift.io/securityspy/v2"
)
func TestUnmarshalXMLCameraSchedule(t *testing.T) {
t.Parallel()
asert := assert.New(t)
var s securityspy.CameraSchedule
err := xml.Unmarshal([]byte("<tag>3</tag>"), &s)
require.NoError(t, err, "valid data must not produce an error")
asert.Equal(3, s.ID, "the data was not unmarshalled properly")
}
func TestAll(t *testing.T) {
t.Parallel()
asert := assert.New(t)
secspyServer, _, _ := testServerWithCamera(t)
cams := secspyServer.Cameras.All()
asert.Len(cams, 2, "the data contains two cameras, two cameras must be returned")
}
func TestByNum(t *testing.T) {
t.Parallel()
asert := assert.New(t)
secspyServer, _, _ := testServerWithCamera(t)
cam := secspyServer.Cameras.ByNum(1)
asert.Equal("Porch", cam.Name, "camera 1 is Porch in the test data")
require.Nil(t, secspyServer.Cameras.ByNum(99), "a non-existent camera must return nil")
}
func TestByName(t *testing.T) {
t.Parallel()
asert := assert.New(t)
secspyServer, _, _ := testServerWithCamera(t)
cam := secspyServer.Cameras.ByName("Porch")
asert.Equal(1, cam.Number, "camera 1 is Porch in the test data")
require.Nil(t, secspyServer.Cameras.ByName("not here"), "a non-existent camera must return nil")
cam = secspyServer.Cameras.ByName("porch2")
require.Nil(t, cam, "there is no camera named porch2")
cam = secspyServer.Cameras.ByName("porch")
asert.Equal(1, cam.Number, "camera 1 is Porch in the test data")
require.Nil(t, secspyServer.Cameras.ByName("not here"), "a non-existent camera must return nil")
}
/* Having a comment at the end of the file like this allows commenting the whole file easily. */