Skip to content

Commit

Permalink
fix: NewClient respects env var
Browse files Browse the repository at this point in the history
  • Loading branch information
cynicaljoy committed Nov 28, 2024
1 parent bd13d1d commit bfc3f4a
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 1 deletion.
7 changes: 6 additions & 1 deletion client.go
Original file line number Diff line number Diff line change
Expand Up @@ -167,11 +167,16 @@ func NewClient(secret string, timeouts Timeouts, configFns ...ClientConfigFn) *C
defaultHeaders[HeaderQueryTimeoutMs] = fmt.Sprintf("%v", timeouts.QueryTimeout.Milliseconds())
}

endpointURL, urlFound := os.LookupEnv(EnvFaunaEndpoint)
if !urlFound {
endpointURL = EndpointDefault
}

client := &Client{
ctx: context.TODO(),
secret: secret,
http: httpClient,
url: EndpointDefault,
url: endpointURL,
headers: defaultHeaders,
lastTxnTime: txnTime{},
typeCheckingEnabled: false,
Expand Down
7 changes: 7 additions & 0 deletions client_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -198,6 +198,13 @@ func TestNewClient(t *testing.T) {
assert.NoError(t, clientErr)
})

t.Run("new client respects env var", func(t *testing.T) {
t.Setenv(fauna.EnvFaunaEndpoint, fauna.EndpointLocal)
client := fauna.NewClient("secret", fauna.DefaultTimeouts())
assert.NotNil(t, client)
assert.Equal(t, client.String(), fauna.EndpointLocal)
})

t.Run("stringify", func(t *testing.T) {
client := fauna.NewClient("secret", fauna.DefaultTimeouts(), fauna.URL(fauna.EndpointLocal))
assert.Equal(t, client.String(), fauna.EndpointLocal, "client toString should be equal to the endpoint to ensure we don't expose secrets")
Expand Down

0 comments on commit bfc3f4a

Please sign in to comment.