2015-08-26 21:27:44 +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"
|
2015-08-26 21:27:44 +00:00
|
|
|
"github.com/hashicorp/nomad/nomad/structs"
|
|
|
|
)
|
|
|
|
|
|
|
|
func TestHostFingerprint(t *testing.T) {
|
2018-09-16 00:48:59 +00:00
|
|
|
f := NewHostFingerprint(testlog.HCLogger(t))
|
2015-08-26 21:27:44 +00:00
|
|
|
node := &structs.Node{
|
|
|
|
Attributes: make(map[string]string),
|
|
|
|
}
|
2018-01-24 14:09:53 +00:00
|
|
|
|
2018-12-01 16:10:39 +00:00
|
|
|
request := &FingerprintRequest{Config: &config.Config{}, Node: node}
|
|
|
|
var response FingerprintResponse
|
2018-01-26 16:21:07 +00:00
|
|
|
err := f.Fingerprint(request, &response)
|
2015-08-26 21:27:44 +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 {
|
2018-01-24 14:09:53 +00:00
|
|
|
t.Fatalf("should generate a diff of node attributes")
|
2015-08-26 21:27:44 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// Host info
|
2016-06-23 15:28:17 +00:00
|
|
|
for _, key := range []string{"os.name", "os.version", "unique.hostname", "kernel.name"} {
|
2018-01-30 17:57:37 +00:00
|
|
|
assertNodeAttributeContains(t, response.Attributes, key)
|
2015-08-26 21:27:44 +00:00
|
|
|
}
|
|
|
|
}
|