github.com/smithx10/nomad@v0.9.1-rc1/client/fingerprint/fingerprint_test.go (about)

     1  package fingerprint
     2  
     3  // This file contains helper methods for testing fingerprinters
     4  
     5  import (
     6  	"testing"
     7  
     8  	"github.com/hashicorp/nomad/client/config"
     9  	"github.com/hashicorp/nomad/nomad/structs"
    10  )
    11  
    12  func assertFingerprintOK(t *testing.T, fp Fingerprint, node *structs.Node) *FingerprintResponse {
    13  	request := &FingerprintRequest{Config: new(config.Config), Node: node}
    14  	var response FingerprintResponse
    15  	err := fp.Fingerprint(request, &response)
    16  	if err != nil {
    17  		t.Fatalf("Failed to fingerprint: %s", err)
    18  	}
    19  
    20  	if len(response.Attributes) == 0 {
    21  		t.Fatalf("Failed to apply node attributes")
    22  	}
    23  
    24  	return &response
    25  }
    26  
    27  func assertNodeAttributeContains(t *testing.T, nodeAttributes map[string]string, attribute string) {
    28  	if nodeAttributes == nil {
    29  		t.Errorf("expected an initialized map for node attributes")
    30  		return
    31  	}
    32  
    33  	actual, found := nodeAttributes[attribute]
    34  	if !found {
    35  		t.Errorf("Expected to find Attribute `%s`\n\n[DEBUG] %#v", attribute, nodeAttributes)
    36  		return
    37  	}
    38  	if actual == "" {
    39  		t.Errorf("Expected non-empty Attribute value for `%s`\n\n[DEBUG] %#v", attribute, nodeAttributes)
    40  	}
    41  }
    42  
    43  func assertNodeAttributeEquals(t *testing.T, nodeAttributes map[string]string, attribute string, expected string) {
    44  	if nodeAttributes == nil {
    45  		t.Errorf("expected an initialized map for node attributes")
    46  		return
    47  	}
    48  	actual, found := nodeAttributes[attribute]
    49  	if !found {
    50  		t.Errorf("Expected to find Attribute `%s`; unable to check value\n\n[DEBUG] %#v", attribute, nodeAttributes)
    51  		return
    52  	}
    53  	if expected != actual {
    54  		t.Errorf("Expected `%s` Attribute to be `%s`, found `%s`\n\n[DEBUG] %#v", attribute, expected, actual, nodeAttributes)
    55  	}
    56  }
    57  
    58  func assertNodeLinksContains(t *testing.T, nodeLinks map[string]string, link string) {
    59  	if nodeLinks == nil {
    60  		t.Errorf("expected an initialized map for node links")
    61  		return
    62  	}
    63  	actual, found := nodeLinks[link]
    64  	if !found {
    65  		t.Errorf("Expected to find Link `%s`\n\n[DEBUG]", link)
    66  		return
    67  	}
    68  	if actual == "" {
    69  		t.Errorf("Expected non-empty Link value for `%s`\n\n[DEBUG]", link)
    70  	}
    71  }