[BUGFIX] meshviewer-ffrgb export empty array

This commit is contained in:
Martin/Geno 2019-01-15 19:04:10 +01:00 committed by genofire
parent 6579d52bac
commit f5d0067eff
2 changed files with 19 additions and 1 deletions

View File

@ -78,15 +78,18 @@ func NewNode(nodes *runtime.Nodes, n *runtime.Node) *Node {
Lastseen: n.Lastseen,
IsOnline: n.Online,
IsGateway: n.IsGateway(),
Addresses: []string{},
}
if nodeinfo := n.Nodeinfo; nodeinfo != nil {
node.NodeID = nodeinfo.NodeID
node.MAC = nodeinfo.Network.Mac
node.Addresses = nodeinfo.Network.Addresses
node.SiteCode = nodeinfo.System.SiteCode
node.DomainCode = nodeinfo.System.DomainCode
node.Hostname = nodeinfo.Hostname
if addresses := nodeinfo.Network.Addresses; addresses != nil {
node.Addresses = nodeinfo.Network.Addresses
}
if owner := nodeinfo.Owner; owner != nil {
node.Owner = owner.Contact
}

View File

@ -12,6 +12,20 @@ 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",
@ -46,6 +60,7 @@ func TestRegister(t *testing.T) {
},
})
assert.NotNil(node)
assert.NotNil(node.Addresses)
assert.Equal("whoami", node.Owner)
assert.Equal("blub", node.MAC)
assert.Equal(13.3, node.Location.Longitude)