Example #1
0
// creates new test Network
func testNewNetwork() (network *core.Network) {
	if len(testNetworkName) != 0 {
		network = core.NewNetwork(testNetworkName, testNetworkKey)
		network.Description = testNetworkDesc
	}
	return
}
Example #2
0
// Test Network JSON marshaling
func TestJsonNetwork(t *testing.T) {
	network := core.NewNetwork("net-name", "net-key")
	network.Description = "custom description"
	testCheckJson(t, network, `{"name":"net-name","key":"net-key","description":"custom description"}`)

	network.Description = ""
	network.Id = 100
	testCheckJson(t, network, `{"id":100,"name":"net-name","key":"net-key"}`)
}
Example #3
0
// Test Device JSON marshaling
func TestJsonDevice(t *testing.T) {
	device := core.NewDevice("dev-id", "dev-name", nil)
	device.Key = "dev-key"
	device.Status = "Online"
	testCheckJson(t, device, `{"id":"dev-id","name":"dev-name","key":"dev-key","status":"Online"}`)

	device.Data = "custom data"
	testCheckJson(t, device, `{"id":"dev-id","name":"dev-name","key":"dev-key","status":"Online","data":"custom data"}`)

	device.Network = core.NewNetwork("net-name", "net-key")
	testCheckJson(t, device, `{"id":"dev-id","name":"dev-name","key":"dev-key","status":"Online","data":"custom data","network":{"name":"net-name","key":"net-key"}}`)

	device.DeviceClass = core.NewDeviceClass("class-name", "3.4.5")
	testCheckJson(t, device, `{"id":"dev-id","name":"dev-name","key":"dev-key","status":"Online","data":"custom data","network":{"name":"net-name","key":"net-key"},"deviceClass":{"name":"class-name","version":"3.4.5"}}`)
}
Example #4
0
// NewNetwork creates a new network.
// Network Description is empty.
func NewNetwork(name, key string) *core.Network {
	return core.NewNetwork(name, key)
}