github.com/anuvu/nomad@v0.8.7-atom1/client/fingerprint/nomad_test.go (about)

     1  package fingerprint
     2  
     3  import (
     4  	"testing"
     5  
     6  	"github.com/hashicorp/nomad/client/config"
     7  	cstructs "github.com/hashicorp/nomad/client/structs"
     8  	"github.com/hashicorp/nomad/nomad/structs"
     9  	"github.com/hashicorp/nomad/version"
    10  )
    11  
    12  func TestNomadFingerprint(t *testing.T) {
    13  	f := NewNomadFingerprint(testLogger())
    14  	node := &structs.Node{
    15  		Attributes: make(map[string]string),
    16  	}
    17  	v := "foo"
    18  	r := "123"
    19  	c := &config.Config{
    20  		Version: &version.VersionInfo{
    21  			Revision: r,
    22  			Version:  v,
    23  		},
    24  	}
    25  
    26  	request := &cstructs.FingerprintRequest{Config: c, Node: node}
    27  	var response cstructs.FingerprintResponse
    28  	err := f.Fingerprint(request, &response)
    29  	if err != nil {
    30  		t.Fatalf("err: %v", err)
    31  	}
    32  
    33  	if !response.Detected {
    34  		t.Fatalf("expected response to be applicable")
    35  	}
    36  
    37  	if len(response.Attributes) == 0 {
    38  		t.Fatalf("should apply")
    39  	}
    40  
    41  	if response.Attributes["nomad.version"] != v {
    42  		t.Fatalf("incorrect version")
    43  	}
    44  
    45  	if response.Attributes["nomad.revision"] != r {
    46  		t.Fatalf("incorrect revision")
    47  	}
    48  }