github.com/hhrutter/nomad@v0.6.0-rc2.0.20170723054333-80c4b03f0705/client/fingerprint/storage_test.go (about)

     1  package fingerprint
     2  
     3  import (
     4  	"strconv"
     5  	"testing"
     6  
     7  	"github.com/hashicorp/nomad/nomad/structs"
     8  )
     9  
    10  func TestStorageFingerprint(t *testing.T) {
    11  	fp := NewStorageFingerprint(testLogger())
    12  	node := &structs.Node{
    13  		Attributes: make(map[string]string),
    14  	}
    15  
    16  	assertFingerprintOK(t, fp, node)
    17  
    18  	assertNodeAttributeContains(t, node, "unique.storage.volume")
    19  	assertNodeAttributeContains(t, node, "unique.storage.bytestotal")
    20  	assertNodeAttributeContains(t, node, "unique.storage.bytesfree")
    21  
    22  	total, err := strconv.ParseInt(node.Attributes["unique.storage.bytestotal"], 10, 64)
    23  	if err != nil {
    24  		t.Fatalf("Failed to parse unique.storage.bytestotal: %s", err)
    25  	}
    26  	free, err := strconv.ParseInt(node.Attributes["unique.storage.bytesfree"], 10, 64)
    27  	if err != nil {
    28  		t.Fatalf("Failed to parse unique.storage.bytesfree: %s", err)
    29  	}
    30  
    31  	if free > total {
    32  		t.Fatalf("unique.storage.bytesfree %d is larger than unique.storage.bytestotal %d", free, total)
    33  	}
    34  
    35  	if node.Resources == nil {
    36  		t.Fatalf("Node Resources was nil")
    37  	}
    38  	if node.Resources.DiskMB == 0 {
    39  		t.Errorf("Expected node.Resources.DiskMB to be non-zero")
    40  	}
    41  }