github.com/anth0d/nomad@v0.0.0-20221214183521-ae3a0a2cad06/client/fingerprint/storage_test.go (about)

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