diff --git a/client.go b/client.go index d1f1774..3e90ca8 100644 --- a/client.go +++ b/client.go @@ -183,24 +183,36 @@ func NewClient(secret string, timeouts Timeouts, configFns ...ClientConfigFn) *C return client } -func (c *Client) parseQueryURL() (url *url.URL, err error) { - if c.queryURL != nil { - url = c.queryURL - } else if url, err = url.Parse(c.url); err == nil { - url = url.JoinPath("query", "1") - c.queryURL = url +func (c *Client) parseQueryURL() (*url.URL, error) { + if c.queryURL == nil { + if queryURL, err := url.Parse(c.url); err != nil { + return nil, err + } else { + c.queryURL = queryURL.JoinPath("query", "1") + } } - return + + if c.queryURL == nil { + return nil, fmt.Errorf("query url is not set") + } + + return c.queryURL, nil } -func (c *Client) parseStreamURL() (url *url.URL, err error) { - if c.streamURL != nil { - url = c.streamURL - } else if url, err = url.Parse(c.url); err == nil { - url = url.JoinPath("stream", "1") - c.streamURL = url +func (c *Client) parseStreamURL() (*url.URL, error) { + if c.streamURL == nil { + if streamURL, err := url.Parse(c.url); err != nil { + return nil, err + } else { + c.streamURL = streamURL.JoinPath("stream", "1") + } } - return + + if c.streamURL == nil { + return nil, fmt.Errorf("stream url is not set") + } + + return c.streamURL, nil } func (c *Client) doWithRetry(req *http.Request) (attempts int, r *http.Response, err error) { @@ -316,7 +328,7 @@ func (c *Client) StreamFromQuery(fql *Query, streamOpts []StreamOptFn, opts ...Q return c.Stream(stream, streamOpts...) } - return nil, fmt.Errorf("expected query to return a fauna.StreamFromQuery but got %T", res.Data) + return nil, fmt.Errorf("query should return a fauna.EventSource but got %T", res.Data) } // Stream initiates a stream subscription for the given stream value. diff --git a/client_test.go b/client_test.go index 15a2da0..1ac567e 100644 --- a/client_test.go +++ b/client_test.go @@ -11,6 +11,7 @@ import ( "github.com/fauna/fauna-go/v2" "github.com/stretchr/testify/assert" + "github.com/stretchr/testify/require" ) func TestDefaultClient(t *testing.T) { @@ -29,9 +30,7 @@ func TestDefaultClient(t *testing.T) { query, _ := fauna.FQL(`${arg0}.length`, map[string]any{"arg0": s}) res, queryErr := client.Query(query) - if !assert.NoError(t, queryErr) { - return - } + require.NoError(t, queryErr) var i int marshalErr := res.Unmarshal(&i) @@ -258,7 +257,7 @@ func TestBasicCRUDRequests(t *testing.T) { } coll := fmt.Sprintf("Person_%v", randomString(12)) - collMod := &fauna.Module{coll} + collMod := &fauna.Module{Name: coll} t.Run("Create a collection", func(t *testing.T) { q, _ := fauna.FQL(`Collection.create({ name: ${name} })`, map[string]any{"name": coll}) diff --git a/stream_test.go b/stream_test.go index d9539b0..04a9d60 100644 --- a/stream_test.go +++ b/stream_test.go @@ -45,7 +45,7 @@ func TestStreaming(t *testing.T) { t.Run("Fails on non-streamable values", func(t *testing.T) { streamQ, _ := fauna.FQL(`"I'm a string"`, nil) events, err := client.StreamFromQuery(streamQ, nil) - require.ErrorContains(t, err, "expected query to return a fauna.StreamFromQuery but got string") + require.ErrorContains(t, err, "query should return a fauna.EventSource but got string") require.Nil(t, events) }) })