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