github.com/zoomfoo/nomad@v0.8.5-0.20180907175415-f28fd3a1a056/client/fingerprint/vault_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/testutil"
    11  )
    12  
    13  func TestVaultFingerprint(t *testing.T) {
    14  	tv := testutil.NewTestVault(t)
    15  	defer tv.Stop()
    16  
    17  	fp := NewVaultFingerprint(testlog.Logger(t))
    18  	node := &structs.Node{
    19  		Attributes: make(map[string]string),
    20  	}
    21  
    22  	conf := config.DefaultConfig()
    23  	conf.VaultConfig = tv.Config
    24  
    25  	request := &cstructs.FingerprintRequest{Config: conf, Node: node}
    26  	var response cstructs.FingerprintResponse
    27  	err := fp.Fingerprint(request, &response)
    28  	if err != nil {
    29  		t.Fatalf("Failed to fingerprint: %s", err)
    30  	}
    31  
    32  	if !response.Detected {
    33  		t.Fatalf("expected response to be applicable")
    34  	}
    35  
    36  	assertNodeAttributeContains(t, response.Attributes, "vault.accessible")
    37  	assertNodeAttributeContains(t, response.Attributes, "vault.version")
    38  	assertNodeAttributeContains(t, response.Attributes, "vault.cluster_id")
    39  	assertNodeAttributeContains(t, response.Attributes, "vault.cluster_name")
    40  }