Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: Add stringer to Token #71

Merged
merged 1 commit into from
Nov 15, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 6 additions & 1 deletion auth/token.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 (
Expand Down Expand Up @@ -44,6 +45,10 @@ type Token struct {
Value string
}

func (t Token) String() string {
return t.Value
}

type TokenClient struct {
url string
apiKey string
Expand Down
9 changes: 8 additions & 1 deletion auth/token_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down Expand Up @@ -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()
Expand Down
Loading