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