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