github.com/smithx10/nomad@v0.9.1-rc1/client/fingerprint/storage_test.go (about) 1 package fingerprint 2 3 import ( 4 "strconv" 5 "testing" 6 7 "github.com/hashicorp/nomad/helper/testlog" 8 "github.com/hashicorp/nomad/nomad/structs" 9 ) 10 11 func TestStorageFingerprint(t *testing.T) { 12 fp := NewStorageFingerprint(testlog.HCLogger(t)) 13 node := &structs.Node{ 14 Attributes: make(map[string]string), 15 } 16 17 response := assertFingerprintOK(t, fp, node) 18 19 if !response.Detected { 20 t.Fatalf("expected response to be applicable") 21 } 22 23 assertNodeAttributeContains(t, response.Attributes, "unique.storage.volume") 24 assertNodeAttributeContains(t, response.Attributes, "unique.storage.bytestotal") 25 assertNodeAttributeContains(t, response.Attributes, "unique.storage.bytesfree") 26 27 total, err := strconv.ParseInt(response.Attributes["unique.storage.bytestotal"], 10, 64) 28 if err != nil { 29 t.Fatalf("Failed to parse unique.storage.bytestotal: %s", err) 30 } 31 free, err := strconv.ParseInt(response.Attributes["unique.storage.bytesfree"], 10, 64) 32 if err != nil { 33 t.Fatalf("Failed to parse unique.storage.bytesfree: %s", err) 34 } 35 36 if free > total { 37 t.Fatalf("unique.storage.bytesfree %d is larger than unique.storage.bytestotal %d", free, total) 38 } 39 40 // COMPAT(0.10): Remove in 0.10 41 if response.Resources == nil { 42 t.Fatalf("Node Resources was nil") 43 } 44 if response.Resources.DiskMB == 0 { 45 t.Errorf("Expected node.Resources.DiskMB to be non-zero") 46 } 47 48 if response.NodeResources == nil || response.NodeResources.Disk.DiskMB == 0 { 49 t.Errorf("Expected node.Resources.DiskMB to be non-zero") 50 } 51 }