yanic/output/meshviewer-ffrgb/struct_test.go

86 lines
1.8 KiB
Go
Raw Permalink Normal View History

package meshviewerFFRGB
import (
"testing"
"github.com/FreifunkBremen/yanic/data"
"github.com/FreifunkBremen/yanic/runtime"
"github.com/stretchr/testify/assert"
)
func TestRegister(t *testing.T) {
assert := assert.New(t)
nodes := runtime.NewNodes(&runtime.NodesConfig{})
node := NewNode(nodes, &runtime.Node{
Nodeinfo: &data.Nodeinfo{
Owner: &data.Owner{
Contact: "whoami",
},
Network: data.Network{
Mac: "blub",
Addresses: []string{"fe80::1"},
},
},
})
assert.NotNil(node)
assert.Len(node.Addresses, 1)
node = NewNode(nodes, &runtime.Node{
Nodeinfo: &data.Nodeinfo{
Owner: &data.Owner{
Contact: "whoami",
},
Network: data.Network{
Mac: "blub",
},
Location: &data.Location{
2017-11-23 13:01:39 +01:00
Longitude: 13.3,
Latitude: 8.7,
},
2021-02-17 23:35:12 +01:00
Software: data.Software{
Autoupdater: &struct {
Enabled bool `json:"enabled,omitempty"`
Branch string `json:"branch,omitempty"`
}{},
Firmware: &struct {
Base string `json:"base,omitempty"`
Release string `json:"release,omitempty"`
}{},
},
},
Statistics: &data.Statistics{
Memory: data.Memory{
Free: 13,
Total: 50,
},
Wireless: []*data.WirelessAirtime{
2018-01-13 16:40:23 +01:00
{
ChanUtil: 0.3,
Frequency: 2512,
},
2018-01-13 16:40:23 +01:00
{
ChanUtil: 0.4,
Frequency: 2612,
},
2018-01-13 16:40:23 +01:00
{
ChanUtil: 0.5,
Frequency: 5200,
},
},
},
CustomFields: map[string]interface{}{
"custom_fields": "are_custom",
"custom_int": 3,
},
})
assert.NotNil(node)
assert.NotNil(node.Addresses)
assert.Equal("whoami", node.Owner)
assert.Equal("blub", node.MAC)
2017-11-23 13:01:39 +01:00
assert.Equal(13.3, node.Location.Longitude)
assert.Equal(8.7, node.Location.Latitude)
assert.Equal(0.74, *node.MemoryUsage)
assert.Equal("are_custom", node.CustomFields["custom_fields"])
assert.Equal(3, node.CustomFields["custom_int"])
}