[BUGFIX] ref of primitiv datatypes did not work (but compile ^^)
This commit is contained in:
parent
e9c9968980
commit
3973e17b9b
|
@ -0,0 +1,36 @@
|
|||
package meshviewer
|
||||
|
||||
import (
|
||||
"testing"
|
||||
|
||||
"github.com/stretchr/testify/assert"
|
||||
|
||||
"github.com/FreifunkBremen/yanic/data"
|
||||
)
|
||||
|
||||
func TestNewMeshviewer(t *testing.T) {
|
||||
assert := assert.New(t)
|
||||
|
||||
stats := NewStatistics(&data.Statistics{
|
||||
Clients: &data.Clients{Total: 32},
|
||||
Memory: &data.Memory{
|
||||
Total: 2,
|
||||
Free: 1,
|
||||
},
|
||||
})
|
||||
assert.Equal(0.5, stats.MemoryUsage, "Wrong calculated memory")
|
||||
assert.Equal(uint32(32), stats.Clients, "Wrong client count with given total")
|
||||
|
||||
stats = NewStatistics(&data.Statistics{
|
||||
Clients: &data.Clients{
|
||||
Wifi24: 3,
|
||||
Wifi5: 4,
|
||||
},
|
||||
Memory: &data.Memory{
|
||||
Total: 0,
|
||||
Free: 1,
|
||||
},
|
||||
})
|
||||
assert.Equal(1.0, stats.MemoryUsage, "Wrong calculated memory during divide by zero")
|
||||
assert.Equal(uint32(7), stats.Clients, "Wrong client count without total and wifi from batman")
|
||||
}
|
|
@ -27,7 +27,7 @@ type Statistics struct {
|
|||
Clients uint32 `json:"clients"`
|
||||
RootFsUsage float64 `json:"rootfs_usage,omitempty"`
|
||||
LoadAverage float64 `json:"loadavg,omitempty"`
|
||||
MemoryUsage *float64 `json:"memory_usage,omitempty"`
|
||||
MemoryUsage float64 `json:"memory_usage,omitempty"`
|
||||
Uptime float64 `json:"uptime,omitempty"`
|
||||
Idletime float64 `json:"idletime,omitempty"`
|
||||
GatewayIPv4 string `json:"gateway,omitempty"`
|
||||
|
@ -61,7 +61,7 @@ func NewStatistics(stats *data.Statistics) *Statistics {
|
|||
* https://github.com/FreifunkBremen/yanic/issues/35)
|
||||
*/
|
||||
|
||||
meshviewerStats := &Statistics{
|
||||
result := &Statistics{
|
||||
NodeID: stats.NodeID,
|
||||
GatewayIPv4: stats.GatewayIPv4,
|
||||
GatewayIPv6: stats.GatewayIPv6,
|
||||
|
@ -73,9 +73,10 @@ func NewStatistics(stats *data.Statistics) *Statistics {
|
|||
MeshVPN: stats.MeshVPN,
|
||||
Traffic: stats.Traffic,
|
||||
Clients: total,
|
||||
MemoryUsage: 1,
|
||||
}
|
||||
if memory := stats.Memory; memory != nil && memory.Total > 0 {
|
||||
*meshviewerStats.MemoryUsage = 1 - (float64(memory.Free)+float64(memory.Buffers)+float64(memory.Cached))/float64(memory.Total)
|
||||
result.MemoryUsage = 1 - (float64(memory.Free)+float64(memory.Buffers)+float64(memory.Cached))/float64(memory.Total)
|
||||
}
|
||||
return meshviewerStats
|
||||
return result
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue