github.com/anth0d/nomad@v0.0.0-20221214183521-ae3a0a2cad06/client/fingerprint/nomad_test.go (about) 1 package fingerprint 2 3 import ( 4 "testing" 5 6 "github.com/hashicorp/nomad/ci" 7 "github.com/hashicorp/nomad/client/config" 8 "github.com/hashicorp/nomad/helper/testlog" 9 "github.com/hashicorp/nomad/nomad/structs" 10 "github.com/hashicorp/nomad/version" 11 "github.com/stretchr/testify/require" 12 ) 13 14 func TestNomadFingerprint(t *testing.T) { 15 ci.Parallel(t) 16 17 f := NewNomadFingerprint(testlog.HCLogger(t)) 18 19 v := "foo" 20 r := "123" 21 h := "8.8.8.8:4646" 22 c := &config.Config{ 23 Version: &version.VersionInfo{ 24 Revision: r, 25 Version: v, 26 }, 27 NomadServiceDiscovery: true, 28 } 29 node := &structs.Node{ 30 Attributes: make(map[string]string), 31 HTTPAddr: h, 32 } 33 34 request := &FingerprintRequest{Config: c, Node: node} 35 var response FingerprintResponse 36 err := f.Fingerprint(request, &response) 37 if err != nil { 38 t.Fatalf("err: %v", err) 39 } 40 41 if !response.Detected { 42 t.Fatalf("expected response to be applicable") 43 } 44 45 if len(response.Attributes) == 0 { 46 t.Fatalf("should apply") 47 } 48 49 if response.Attributes["nomad.version"] != v { 50 t.Fatalf("incorrect version") 51 } 52 53 if response.Attributes["nomad.revision"] != r { 54 t.Fatalf("incorrect revision") 55 } 56 57 if response.Attributes["nomad.advertise.address"] != h { 58 t.Fatalf("incorrect advertise address") 59 } 60 61 serviceDisco := response.Attributes["nomad.service_discovery"] 62 require.Equal(t, "true", serviceDisco, "service_discovery attr incorrect") 63 }