open-nomad/client/fingerprint/nomad_test.go

49 lines
1,006 B
Go
Raw Normal View History

2016-03-23 00:12:30 +00:00
package fingerprint
import (
"testing"
"github.com/hashicorp/nomad/client/config"
cstructs "github.com/hashicorp/nomad/client/structs"
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) {
f := NewNomadFingerprint(testLogger())
node := &structs.Node{
Attributes: make(map[string]string),
}
v := "foo"
r := "123"
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
}
request := &cstructs.FingerprintRequest{Config: c, Node: node}
var response cstructs.FingerprintResponse
err := f.Fingerprint(request, &response)
2016-03-23 00:12:30 +00:00
if err != nil {
t.Fatalf("err: %v", err)
}
2018-01-31 22:03:55 +00:00
if !response.Detected {
t.Fatalf("expected response to be applicable")
}
if len(response.Attributes) == 0 {
2016-03-23 00:12:30 +00:00
t.Fatalf("should apply")
}
if response.Attributes["nomad.version"] != v {
2016-03-23 00:12:30 +00:00
t.Fatalf("incorrect version")
}
if response.Attributes["nomad.revision"] != r {
2016-03-23 00:12:30 +00:00
t.Fatalf("incorrect revision")
}
}