github.com/smithx10/nomad@v0.9.1-rc1/client/fingerprint/nomad_test.go (about)

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