diff --git a/auth/token.go b/auth/token.go index d1cf72e..e0f8b04 100644 --- a/auth/token.go +++ b/auth/token.go @@ -3,12 +3,13 @@ package auth import ( "encoding/json" "fmt" - "github.com/cloudquery/cloudquery-api-go/config" "io" "net/http" "net/url" "os" "time" + + "github.com/cloudquery/cloudquery-api-go/config" ) const ( @@ -44,6 +45,10 @@ type Token struct { Value string } +func (t Token) String() string { + return t.Value +} + type TokenClient struct { url string apiKey string diff --git a/auth/token_test.go b/auth/token_test.go index 32879e0..799683d 100644 --- a/auth/token_test.go +++ b/auth/token_test.go @@ -3,12 +3,13 @@ package auth import ( "encoding/json" "fmt" - "github.com/stretchr/testify/require" "net/http" "net/http/httptest" "os" "testing" "time" + + "github.com/stretchr/testify/require" ) func TestRefreshToken_RoundTrip(t *testing.T) { @@ -39,6 +40,12 @@ func TestRefreshToken_Removal(t *testing.T) { require.Error(t, err) } +func TestToken_Stringer(t *testing.T) { + token := Token{Type: BearerToken, Value: "my_token"} + out := fmt.Sprintf("Bearer %s", token) + require.Equal(t, "Bearer my_token", out) +} + func TestTokenClient_EnvironmentVariable(t *testing.T) { reset := overrideEnvironmentVariable(t, EnvVarCloudQueryAPIKey, "my_token") defer reset()