open-nomad/client/fingerprint/storage_test.go

42 lines
1.1 KiB
Go
Raw Normal View History

package fingerprint
import (
"strconv"
"testing"
"github.com/hashicorp/nomad/nomad/structs"
)
func TestStorageFingerprint(t *testing.T) {
fp := NewStorageFingerprint(testLogger())
node := &structs.Node{
Attributes: make(map[string]string),
}
assertFingerprintOK(t, fp, node)
2016-01-23 02:12:16 +00:00
assertNodeAttributeContains(t, node, "unique.storage.volume")
assertNodeAttributeContains(t, node, "unique.storage.bytestotal")
assertNodeAttributeContains(t, node, "unique.storage.bytesfree")
2016-01-23 02:12:16 +00:00
total, err := strconv.ParseInt(node.Attributes["unique.storage.bytestotal"], 10, 64)
if err != nil {
2016-01-23 02:12:16 +00:00
t.Fatalf("Failed to parse unique.storage.bytestotal: %s", err)
}
2016-01-23 02:12:16 +00:00
free, err := strconv.ParseInt(node.Attributes["unique.storage.bytesfree"], 10, 64)
if err != nil {
2016-01-23 02:12:16 +00:00
t.Fatalf("Failed to parse unique.storage.bytesfree: %s", err)
}
if free > total {
2016-01-23 02:12:16 +00:00
t.Fatalf("unique.storage.bytesfree %d is larger than unique.storage.bytestotal %d", free, total)
}
2015-11-07 14:14:25 +00:00
if node.Resources == nil {
t.Fatalf("Node Resources was nil")
}
if node.Resources.DiskMB == 0 {
t.Errorf("Expected node.Resources.DiskMB to be non-zero")
}
}