-
Notifications
You must be signed in to change notification settings - Fork 3
/
Device_test.go
125 lines (105 loc) · 3.16 KB
/
Device_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
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
package HologramGo
import (
"github.com/hologram-io/hologram-go"
"encoding/json"
"fmt"
"io/ioutil"
"testing"
)
func TestGetDevices(t *testing.T) {
file, e := ioutil.ReadFile("json/devices.json")
if e != nil {
fmt.Printf("Error opening file: %v\n", e)
}
var payload = HologramGo.Placeholder{}
err := json.Unmarshal(file, &payload)
if err != nil {
fmt.Println("Unable to parse file")
}
var devices = payload["data"].([]interface{})
var device = (HologramGo.Device)(devices[0].(map[string]interface{}))
// Check for expected device id
expectedFloat := (float64)(84)
returnedFloat := device.GetDeviceId()
if expectedFloat != returnedFloat {
t.Fatalf("Expected %s, got %s", expectedFloat, returnedFloat)
}
// Check for expected device user id
expectedFloat = (float64)(4477)
returnedFloat = device.GetDeviceUserId()
if expectedFloat != returnedFloat {
t.Fatalf("Expected %s, got %s", expectedFloat, returnedFloat)
}
// Check for expected device name
expected := "Unnamed Device (90123)"
returned := device.GetDeviceName()
if expected != returned {
t.Fatalf("Expected %s, got %s", expected, returned)
}
// Check for expected device type
expected = "Unknown"
returned = device.GetDeviceType()
if expected != returned {
t.Fatalf("Expected %s, got %s", expected, returned)
}
// Check for expected device creation date
expected = "2016-06-06 21:51:16"
returned = device.GetWhenCreated()
if expected != returned {
t.Fatalf("Expected %s, got %s", expected, returned)
}
// Check for expected device phone number
expected = ""
returned = device.GetPhoneNumber()
if expected != returned {
t.Fatalf("Expected %s, got %s", expected, returned)
}
}
func TestGetDevice(t *testing.T) {
file, e := ioutil.ReadFile("json/device.json")
if e != nil {
fmt.Printf("Error opening file: %v\n", e)
}
var payload = HologramGo.Placeholder{}
err := json.Unmarshal(file, &payload)
if err != nil {
fmt.Println("Unable to parse file")
}
var device = (HologramGo.Device)(payload["data"].(map[string]interface{}))
// Check for expected device id
expectedFloat := (float64)(1)
returnedFloat := device.GetDeviceId()
if expectedFloat != returnedFloat {
t.Fatalf("Expected %s, got %s", expectedFloat, returnedFloat)
}
// Check for expected device user id
expectedFloat = (float64)(231)
returnedFloat = device.GetDeviceUserId()
if expectedFloat != returnedFloat {
t.Fatalf("Expected %s, got %s", expectedFloat, returnedFloat)
}
// Check for expected device name
expected := "Unnamed Device (91590)"
returned := device.GetDeviceName()
if expected != returned {
t.Fatalf("Expected %s, got %s", expected, returned)
}
// Check for expected device type
expected = "Unknown"
returned = device.GetDeviceType()
if expected != returned {
t.Fatalf("Expected %s, got %s", expected, returned)
}
// Check for expected device creation date
expected = "2015-03-25 03:12:13"
returned = device.GetWhenCreated()
if expected != returned {
t.Fatalf("Expected %s, got %s", expected, returned)
}
// Check for expected device phone number
expected = ""
returned = device.GetPhoneNumber()
if expected != returned {
t.Fatalf("Expected %s, got %s", expected, returned)
}
}