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