open-nomad/client/fingerprint/storage_test.go

52 lines
1.5 KiB
Go
Raw Normal View History

package fingerprint
import (
"strconv"
"testing"
2018-06-13 22:33:25 +00:00
"github.com/hashicorp/nomad/helper/testlog"
"github.com/hashicorp/nomad/nomad/structs"
)
func TestStorageFingerprint(t *testing.T) {
fp := NewStorageFingerprint(testlog.HCLogger(t))
node := &structs.Node{
Attributes: make(map[string]string),
}
response := assertFingerprintOK(t, fp, node)
2018-01-31 22:03:55 +00:00
if !response.Detected {
t.Fatalf("expected response to be applicable")
}
assertNodeAttributeContains(t, response.Attributes, "unique.storage.volume")
assertNodeAttributeContains(t, response.Attributes, "unique.storage.bytestotal")
assertNodeAttributeContains(t, response.Attributes, "unique.storage.bytesfree")
total, err := strconv.ParseInt(response.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)
}
free, err := strconv.ParseInt(response.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)
}
2018-09-30 00:23:41 +00:00
// COMPAT(0.10): Remove in 0.10
if response.Resources == nil {
2015-11-07 14:14:25 +00:00
t.Fatalf("Node Resources was nil")
}
if response.Resources.DiskMB == 0 {
t.Errorf("Expected node.Resources.DiskMB to be non-zero")
}
2018-09-30 00:23:41 +00:00
if response.NodeResources == nil || response.NodeResources.Disk.DiskMB == 0 {
t.Errorf("Expected node.Resources.DiskMB to be non-zero")
}
}