github.com/anth0d/nomad@v0.0.0-20221214183521-ae3a0a2cad06/client/consul/identities_test.go (about)

     1  package consul
     2  
     3  import (
     4  	"errors"
     5  	"testing"
     6  
     7  	"github.com/hashicorp/nomad/ci"
     8  	"github.com/hashicorp/nomad/helper/testlog"
     9  	"github.com/hashicorp/nomad/nomad/structs"
    10  	"github.com/stretchr/testify/require"
    11  )
    12  
    13  func TestSI_DeriveTokens(t *testing.T) {
    14  	ci.Parallel(t)
    15  
    16  	logger := testlog.HCLogger(t)
    17  	dFunc := func(alloc *structs.Allocation, taskNames []string) (map[string]string, error) {
    18  		return map[string]string{"a": "b"}, nil
    19  	}
    20  	tc := NewIdentitiesClient(logger, dFunc)
    21  	tokens, err := tc.DeriveSITokens(nil, nil)
    22  	require.NoError(t, err)
    23  	require.Equal(t, map[string]string{"a": "b"}, tokens)
    24  }
    25  
    26  func TestSI_DeriveTokens_error(t *testing.T) {
    27  	ci.Parallel(t)
    28  
    29  	logger := testlog.HCLogger(t)
    30  	dFunc := func(alloc *structs.Allocation, taskNames []string) (map[string]string, error) {
    31  		return nil, errors.New("some failure")
    32  	}
    33  	tc := NewIdentitiesClient(logger, dFunc)
    34  	_, err := tc.DeriveSITokens(&structs.Allocation{ID: "a1"}, nil)
    35  	require.Error(t, err)
    36  }