open-nomad/client/fingerprint/nomad_test.go
James Rasell b9009c419c
Add 'nomad.advertise.address' to client meta via NomadFingerPrint
This change removes the addition of the advertise address to the
exported task env vars and instead moves this work into the
NomadFingerprint.Fingerprint which adds this value to the client
attrs. This can then be used within a Nomad job like
${attr.nomad.advertise.address}.
2018-06-08 09:44:10 +02:00

56 lines
1.1 KiB
Go

package fingerprint
import (
"testing"
"github.com/hashicorp/nomad/client/config"
cstructs "github.com/hashicorp/nomad/client/structs"
"github.com/hashicorp/nomad/nomad/structs"
"github.com/hashicorp/nomad/version"
)
func TestNomadFingerprint(t *testing.T) {
f := NewNomadFingerprint(testLogger())
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 := &cstructs.FingerprintRequest{Config: c, Node: node}
var response cstructs.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")
}
}