2015-08-27 00:07:31 +00:00
|
|
|
package fingerprint
|
|
|
|
|
|
|
|
// This file contains helper methods for testing fingerprinters
|
|
|
|
|
|
|
|
import (
|
|
|
|
"log"
|
|
|
|
"os"
|
|
|
|
"testing"
|
|
|
|
|
|
|
|
"github.com/hashicorp/nomad/client/config"
|
|
|
|
"github.com/hashicorp/nomad/nomad/structs"
|
|
|
|
)
|
|
|
|
|
|
|
|
func testLogger() *log.Logger {
|
|
|
|
return log.New(os.Stderr, "", log.LstdFlags)
|
|
|
|
}
|
|
|
|
|
|
|
|
func assertFingerprintOK(t *testing.T, fp Fingerprint, node *structs.Node) {
|
|
|
|
ok, err := fp.Fingerprint(new(config.Config), node)
|
|
|
|
if err != nil {
|
2015-08-27 00:16:34 +00:00
|
|
|
t.Fatalf("Failed to fingerprint: %s", err)
|
2015-08-27 00:07:31 +00:00
|
|
|
}
|
|
|
|
if !ok {
|
2015-08-27 00:16:34 +00:00
|
|
|
t.Fatalf("Failed to apply node attributes")
|
2015-08-27 00:07:31 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
func assertNodeAttributeContains(t *testing.T, node *structs.Node, attribute string) {
|
|
|
|
actual, found := node.Attributes[attribute]
|
|
|
|
if !found {
|
2015-08-31 19:18:40 +00:00
|
|
|
t.Errorf("Expected to find Attribute `%s`\n\n[DEBUG] %#v", attribute, node)
|
2015-08-27 00:07:31 +00:00
|
|
|
return
|
|
|
|
}
|
|
|
|
if actual == "" {
|
2015-08-31 19:18:40 +00:00
|
|
|
t.Errorf("Expected non-empty Attribute value for `%s`\n\n[DEBUG] %#v", attribute, node)
|
2015-08-27 00:07:31 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
func assertNodeAttributeEquals(t *testing.T, node *structs.Node, attribute string, expected string) {
|
|
|
|
actual, found := node.Attributes[attribute]
|
|
|
|
if !found {
|
2015-08-31 19:18:40 +00:00
|
|
|
t.Errorf("Expected to find Attribute `%s`; unable to check value\n\n[DEBUG] %#v", attribute, node)
|
2015-08-27 00:07:31 +00:00
|
|
|
return
|
|
|
|
}
|
|
|
|
if expected != actual {
|
2015-08-31 19:18:40 +00:00
|
|
|
t.Errorf("Expected `%s` Attribute to be `%s`, found `%s`\n\n[DEBUG] %#v", attribute, expected, actual, node)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
func assertNodeLinksContains(t *testing.T, node *structs.Node, link string) {
|
|
|
|
actual, found := node.Links[link]
|
|
|
|
if !found {
|
|
|
|
t.Errorf("Expected to find Link `%s`\n\n[DEBUG] %#v", link, node)
|
|
|
|
return
|
|
|
|
}
|
|
|
|
if actual == "" {
|
|
|
|
t.Errorf("Expected non-empty Link value for `%s`\n\n[DEBUG] %#v", link, node)
|
2015-08-27 00:07:31 +00:00
|
|
|
}
|
|
|
|
}
|