github.com/zhizhiboom/nomad@v0.8.5-0.20180907175415-f28fd3a1a056/client/fingerprint/host_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  )
    11  
    12  func TestHostFingerprint(t *testing.T) {
    13  	f := NewHostFingerprint(testlog.Logger(t))
    14  	node := &structs.Node{
    15  		Attributes: make(map[string]string),
    16  	}
    17  
    18  	request := &cstructs.FingerprintRequest{Config: &config.Config{}, Node: node}
    19  	var response cstructs.FingerprintResponse
    20  	err := f.Fingerprint(request, &response)
    21  	if err != nil {
    22  		t.Fatalf("err: %v", err)
    23  	}
    24  
    25  	if !response.Detected {
    26  		t.Fatalf("expected response to be applicable")
    27  	}
    28  
    29  	if len(response.Attributes) == 0 {
    30  		t.Fatalf("should generate a diff of node attributes")
    31  	}
    32  
    33  	// Host info
    34  	for _, key := range []string{"os.name", "os.version", "unique.hostname", "kernel.name"} {
    35  		assertNodeAttributeContains(t, response.Attributes, key)
    36  	}
    37  }