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

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