Skip to content

Commit

Permalink
Code-reuse and rename.
Browse files Browse the repository at this point in the history
  • Loading branch information
notbdu committed Feb 13, 2019
1 parent 5289bfd commit 59e8197
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 13 deletions.
24 changes: 14 additions & 10 deletions integration/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -53,11 +53,7 @@ func (c client) write(data []byte) error {
}

func (c client) queryRaw(data []byte) (rawQueryResults, error) {
req, err := http.NewRequest(http.MethodPost, c.queryURL, bytes.NewReader(data))
if err != nil {
return rawQueryResults{}, err
}
resp, err := c.do(req)
resp, err := c.doQuery(data)
if err != nil {
return rawQueryResults{}, err
}
Expand All @@ -70,11 +66,7 @@ func (c client) queryRaw(data []byte) (rawQueryResults, error) {
}

func (c client) queryGroupBy(data []byte) (groupByQueryResults, error) {
req, err := http.NewRequest(http.MethodPost, c.queryURL, bytes.NewReader(data))
if err != nil {
return groupByQueryResults{}, err
}
resp, err := c.do(req)
resp, err := c.doQuery(data)
if err != nil {
return groupByQueryResults{}, err
}
Expand All @@ -86,6 +78,18 @@ func (c client) queryGroupBy(data []byte) (groupByQueryResults, error) {
return results, nil
}

func (c client) doQuery(data []byte) ([]byte, error) {
req, err := http.NewRequest(http.MethodPost, c.queryURL, bytes.NewReader(data))
if err != nil {
return nil, err
}
resp, err := c.do(req)
if err != nil {
return nil, err
}
return resp, nil
}

func (c client) do(req *http.Request) ([]byte, error) {
req.Header.Set("Content-Type", "application/json")
resp, err := c.client.Do(req)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ import (
"github.com/stretchr/testify/require"
)

func TestGroupByQuery(t *testing.T) {
func TestGroupByQueryNoFilterNoOrder(t *testing.T) {
if testing.Short() {
t.SkipNow()
}
Expand All @@ -20,7 +20,7 @@ func TestGroupByQuery(t *testing.T) {
defer ts.close(t)

log := ts.dbOpts.InstrumentOptions().Logger()
log.Info("testing various groupby query")
log.Info("testing groupby query w/ no filter and no order")
require.NoError(t, ts.startServer())
log.Info("server is now up")

Expand Down Expand Up @@ -76,7 +76,6 @@ func TestGroupByQuery(t *testing.T) {
assert.NoError(t, err)
b, err := json.Marshal(resp)
assert.NoError(t, err)
log.Infof("FINAL RESP: %s", string(b))
assert.Equal(t, string(b), test.expectedResults)
}

Expand Down

0 comments on commit 59e8197

Please sign in to comment.