github.com/anuvu/nomad@v0.8.7-atom1/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  	response := assertFingerprintOK(t, fp, node)
    17  
    18  	if !response.Detected {
    19  		t.Fatalf("expected response to be applicable")
    20  	}
    21  
    22  	assertNodeAttributeContains(t, response.Attributes, "unique.storage.volume")
    23  	assertNodeAttributeContains(t, response.Attributes, "unique.storage.bytestotal")
    24  	assertNodeAttributeContains(t, response.Attributes, "unique.storage.bytesfree")
    25  
    26  	total, err := strconv.ParseInt(response.Attributes["unique.storage.bytestotal"], 10, 64)
    27  	if err != nil {
    28  		t.Fatalf("Failed to parse unique.storage.bytestotal: %s", err)
    29  	}
    30  	free, err := strconv.ParseInt(response.Attributes["unique.storage.bytesfree"], 10, 64)
    31  	if err != nil {
    32  		t.Fatalf("Failed to parse unique.storage.bytesfree: %s", err)
    33  	}
    34  
    35  	if free > total {
    36  		t.Fatalf("unique.storage.bytesfree %d is larger than unique.storage.bytestotal %d", free, total)
    37  	}
    38  
    39  	if response.Resources == nil {
    40  		t.Fatalf("Node Resources was nil")
    41  	}
    42  	if response.Resources.DiskMB == 0 {
    43  		t.Errorf("Expected node.Resources.DiskMB to be non-zero")
    44  	}
    45  }