2016-03-23 00:12:30 +00:00
|
|
|
package fingerprint
|
|
|
|
|
|
|
|
import (
|
|
|
|
"testing"
|
|
|
|
|
|
|
|
"github.com/hashicorp/nomad/client/config"
|
2018-06-13 22:33:25 +00:00
|
|
|
"github.com/hashicorp/nomad/helper/testlog"
|
2016-03-23 00:12:30 +00:00
|
|
|
"github.com/hashicorp/nomad/nomad/structs"
|
2017-08-16 23:14:59 +00:00
|
|
|
"github.com/hashicorp/nomad/version"
|
2016-03-23 00:12:30 +00:00
|
|
|
)
|
|
|
|
|
|
|
|
func TestNomadFingerprint(t *testing.T) {
|
2018-09-16 00:48:59 +00:00
|
|
|
f := NewNomadFingerprint(testlog.HCLogger(t))
|
2018-06-08 07:44:10 +00:00
|
|
|
|
2016-03-23 00:12:30 +00:00
|
|
|
v := "foo"
|
|
|
|
r := "123"
|
2018-06-08 07:44:10 +00:00
|
|
|
h := "8.8.8.8:4646"
|
2016-03-23 00:12:30 +00:00
|
|
|
c := &config.Config{
|
2017-08-16 23:14:59 +00:00
|
|
|
Version: &version.VersionInfo{
|
|
|
|
Revision: r,
|
|
|
|
Version: v,
|
|
|
|
},
|
2016-03-23 00:12:30 +00:00
|
|
|
}
|
2018-06-08 07:44:10 +00:00
|
|
|
node := &structs.Node{
|
|
|
|
Attributes: make(map[string]string),
|
|
|
|
HTTPAddr: h,
|
|
|
|
}
|
2018-01-24 14:09:53 +00:00
|
|
|
|
2018-12-01 16:10:39 +00:00
|
|
|
request := &FingerprintRequest{Config: c, Node: node}
|
|
|
|
var response FingerprintResponse
|
2018-01-26 16:21:07 +00:00
|
|
|
err := f.Fingerprint(request, &response)
|
2016-03-23 00:12:30 +00:00
|
|
|
if err != nil {
|
|
|
|
t.Fatalf("err: %v", err)
|
|
|
|
}
|
2018-01-24 14:09:53 +00:00
|
|
|
|
2018-01-31 22:03:55 +00:00
|
|
|
if !response.Detected {
|
2018-01-30 17:57:37 +00:00
|
|
|
t.Fatalf("expected response to be applicable")
|
|
|
|
}
|
|
|
|
|
|
|
|
if len(response.Attributes) == 0 {
|
2016-03-23 00:12:30 +00:00
|
|
|
t.Fatalf("should apply")
|
|
|
|
}
|
2018-01-24 14:09:53 +00:00
|
|
|
|
2018-01-30 17:57:37 +00:00
|
|
|
if response.Attributes["nomad.version"] != v {
|
2016-03-23 00:12:30 +00:00
|
|
|
t.Fatalf("incorrect version")
|
|
|
|
}
|
2018-01-24 14:09:53 +00:00
|
|
|
|
2018-01-30 17:57:37 +00:00
|
|
|
if response.Attributes["nomad.revision"] != r {
|
2016-03-23 00:12:30 +00:00
|
|
|
t.Fatalf("incorrect revision")
|
|
|
|
}
|
2018-06-08 07:44:10 +00:00
|
|
|
|
|
|
|
if response.Attributes["nomad.advertise.address"] != h {
|
|
|
|
t.Fatalf("incorrect advertise address")
|
|
|
|
}
|
2016-03-23 00:12:30 +00:00
|
|
|
}
|