open-nomad/client/fingerprint/nomad_test.go
Danielle Tomlinson 66c521ca17 client: Move fingerprint structs to pkg
This removes a cyclical dependency when importing client/structs from
dependencies of the plugin_loader, specifically, drivers. Due to
client/config also depending on the plugin_loader.

It also better reflects the ownership of fingerprint structs, as they
are fairly internal to the fingerprint manager.
2018-12-01 17:10:39 +01:00

56 lines
1.1 KiB
Go

package fingerprint
import (
"testing"
"github.com/hashicorp/nomad/client/config"
"github.com/hashicorp/nomad/helper/testlog"
"github.com/hashicorp/nomad/nomad/structs"
"github.com/hashicorp/nomad/version"
)
func TestNomadFingerprint(t *testing.T) {
f := NewNomadFingerprint(testlog.HCLogger(t))
v := "foo"
r := "123"
h := "8.8.8.8:4646"
c := &config.Config{
Version: &version.VersionInfo{
Revision: r,
Version: v,
},
}
node := &structs.Node{
Attributes: make(map[string]string),
HTTPAddr: h,
}
request := &FingerprintRequest{Config: c, Node: node}
var response FingerprintResponse
err := f.Fingerprint(request, &response)
if err != nil {
t.Fatalf("err: %v", err)
}
if !response.Detected {
t.Fatalf("expected response to be applicable")
}
if len(response.Attributes) == 0 {
t.Fatalf("should apply")
}
if response.Attributes["nomad.version"] != v {
t.Fatalf("incorrect version")
}
if response.Attributes["nomad.revision"] != r {
t.Fatalf("incorrect revision")
}
if response.Attributes["nomad.advertise.address"] != h {
t.Fatalf("incorrect advertise address")
}
}