-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathconfigure_test.go
More file actions
73 lines (64 loc) · 1.26 KB
/
configure_test.go
File metadata and controls
73 lines (64 loc) · 1.26 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
package glsensor
import (
"encoding/json"
"strings"
"testing"
)
const testConf = `{
"name" : "DeviceName",
"location" : "DeviceLocation",
"region" : "DeviceRegion",
"sensors" : [
{
"type" : "DS18B20",
"name" : "DS18B20-01",
"id" : "0216249a9eee"
},
{
"type" : "DS18B20",
"name" : "DS18B20-02",
"id" : "01159047f8ff"
},
{
"type" : "DHT11",
"name" : "KY-015-01",
"pin" : 17
}
],
"destinations" : [
{
"type" : "console",
"name" : "Basic Console"
},
{
"name" : "Primary Influx storage",
"type": "Influx",
"server": "InfluxServiceStorage",
"port" : 8086,
"user" : "testuser",
"password" : "test",
"collection" : "testCollection"
}
]
}`
const noSensor string = `{
"type" : "NonExisting",
"name" : "DS18B20-02",
"id" : "01159047f8ff"
} `
var cfg DeviceConf
var server Server
func TestDeviceStructureReading(t *testing.T) {
cfg, _ = ReadConfiguration(strings.NewReader(testConf))
if cfg.Name != "DeviceName" {
t.Fatal("Bad parsing of the name")
}
}
func TestSensorStructReading(t *testing.T) {
var sensor SensorConf
dec := json.NewDecoder(strings.NewReader(noSensor))
err := dec.Decode(&sensor)
if err == nil {
t.Fatal("Fails reading of non existing handler for a sensor")
}
}