github.com/anuvu/nomad@v0.8.7-atom1/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 cstructs "github.com/hashicorp/nomad/client/structs" 12 "github.com/hashicorp/nomad/nomad/structs" 13 ) 14 15 func testLogger() *log.Logger { 16 return log.New(os.Stderr, "", log.LstdFlags) 17 } 18 19 func assertFingerprintOK(t *testing.T, fp Fingerprint, node *structs.Node) *cstructs.FingerprintResponse { 20 request := &cstructs.FingerprintRequest{Config: new(config.Config), Node: node} 21 var response cstructs.FingerprintResponse 22 err := fp.Fingerprint(request, &response) 23 if err != nil { 24 t.Fatalf("Failed to fingerprint: %s", err) 25 } 26 27 if len(response.Attributes) == 0 { 28 t.Fatalf("Failed to apply node attributes") 29 } 30 31 return &response 32 } 33 34 func assertNodeAttributeContains(t *testing.T, nodeAttributes map[string]string, attribute string) { 35 if nodeAttributes == nil { 36 t.Errorf("expected an initialized map for node attributes") 37 return 38 } 39 40 actual, found := nodeAttributes[attribute] 41 if !found { 42 t.Errorf("Expected to find Attribute `%s`\n\n[DEBUG] %#v", attribute, nodeAttributes) 43 return 44 } 45 if actual == "" { 46 t.Errorf("Expected non-empty Attribute value for `%s`\n\n[DEBUG] %#v", attribute, nodeAttributes) 47 } 48 } 49 50 func assertNodeAttributeEquals(t *testing.T, nodeAttributes map[string]string, attribute string, expected string) { 51 if nodeAttributes == nil { 52 t.Errorf("expected an initialized map for node attributes") 53 return 54 } 55 actual, found := nodeAttributes[attribute] 56 if !found { 57 t.Errorf("Expected to find Attribute `%s`; unable to check value\n\n[DEBUG] %#v", attribute, nodeAttributes) 58 return 59 } 60 if expected != actual { 61 t.Errorf("Expected `%s` Attribute to be `%s`, found `%s`\n\n[DEBUG] %#v", attribute, expected, actual, nodeAttributes) 62 } 63 } 64 65 func assertNodeLinksContains(t *testing.T, nodeLinks map[string]string, link string) { 66 if nodeLinks == nil { 67 t.Errorf("expected an initialized map for node links") 68 return 69 } 70 actual, found := nodeLinks[link] 71 if !found { 72 t.Errorf("Expected to find Link `%s`\n\n[DEBUG]", link) 73 return 74 } 75 if actual == "" { 76 t.Errorf("Expected non-empty Link value for `%s`\n\n[DEBUG]", link) 77 } 78 }