2023-04-10 15:36:59 +00:00
|
|
|
// Copyright (c) HashiCorp, Inc.
|
|
|
|
// SPDX-License-Identifier: MPL-2.0
|
|
|
|
|
2019-11-27 21:41:45 +00:00
|
|
|
package consul
|
|
|
|
|
|
|
|
import (
|
|
|
|
"errors"
|
|
|
|
"testing"
|
|
|
|
|
2022-03-15 12:42:43 +00:00
|
|
|
"github.com/hashicorp/nomad/ci"
|
2019-11-27 21:41:45 +00:00
|
|
|
"github.com/hashicorp/nomad/helper/testlog"
|
|
|
|
"github.com/hashicorp/nomad/nomad/structs"
|
|
|
|
"github.com/stretchr/testify/require"
|
|
|
|
)
|
|
|
|
|
2020-01-07 17:58:29 +00:00
|
|
|
func TestSI_DeriveTokens(t *testing.T) {
|
2022-03-15 12:42:43 +00:00
|
|
|
ci.Parallel(t)
|
|
|
|
|
2019-11-27 21:41:45 +00:00
|
|
|
logger := testlog.HCLogger(t)
|
|
|
|
dFunc := func(alloc *structs.Allocation, taskNames []string) (map[string]string, error) {
|
|
|
|
return map[string]string{"a": "b"}, nil
|
|
|
|
}
|
|
|
|
tc := NewIdentitiesClient(logger, dFunc)
|
|
|
|
tokens, err := tc.DeriveSITokens(nil, nil)
|
|
|
|
require.NoError(t, err)
|
|
|
|
require.Equal(t, map[string]string{"a": "b"}, tokens)
|
|
|
|
}
|
|
|
|
|
2020-01-07 17:58:29 +00:00
|
|
|
func TestSI_DeriveTokens_error(t *testing.T) {
|
2022-03-15 12:42:43 +00:00
|
|
|
ci.Parallel(t)
|
|
|
|
|
2019-11-27 21:41:45 +00:00
|
|
|
logger := testlog.HCLogger(t)
|
|
|
|
dFunc := func(alloc *structs.Allocation, taskNames []string) (map[string]string, error) {
|
|
|
|
return nil, errors.New("some failure")
|
|
|
|
}
|
|
|
|
tc := NewIdentitiesClient(logger, dFunc)
|
|
|
|
_, err := tc.DeriveSITokens(&structs.Allocation{ID: "a1"}, nil)
|
|
|
|
require.Error(t, err)
|
|
|
|
}
|