Files
threshold-plugin-gcp/internal/credential/options_test.go
T
Elim Tsiagbey be892acbd9 feat: GCP authentication (#5)
* feat: GCP authentication

Add authentication support for:
- authentication with service account key
- authentication with impersonating service account key
- authentication with application default credentials which are read from the environment

A HTTP client with a token set will be returned and used for authentication with all clients. for example
```
gcpClient, err := gcpConfig.GetClient(ctx)
if err != nil {
	log.Fatalf("Failed to get client: %v", err)
}

client, err := computeCloud.NewInstancesRESTClient(ctx, option.WithHTTPClient(gcpClient))
if err != nil {
	log.Fatalf("Failed to create client: %v", err)
}
```
2024-09-22 23:21:58 -04:00

36 lines
786 B
Go

// Copyright (c) HashiCorp, Inc.
// SPDX-License-Identifier: MPL-2.0
package credential
import (
"testing"
"time"
"github.com/stretchr/testify/require"
)
func Test_getOpts(t *testing.T) {
t.Parallel()
t.Run("WithCredentialsConfig", func(t *testing.T) {
c := &Config{
ProjectId: "test",
ClientEmail: "test",
}
opts, err := getOpts(WithCredentialsConfig(c))
require.NoError(t, err)
testOpts := getDefaultOptions()
testOpts.WithCredentialsConfig = c
require.Equal(t, opts, testOpts)
})
t.Run("WithCredsLastRotatedTime", func(t *testing.T) {
tm := time.Now()
opts, err := getOpts(WithCredsLastRotatedTime(tm))
require.NoError(t, err)
testOpts := getDefaultOptions()
testOpts.WithCredsLastRotatedTime = tm
require.Equal(t, opts, testOpts)
})
}