Skip to content
This repository has been archived by the owner on Sep 28, 2022. It is now read-only.

Commit

Permalink
improve test coverage
Browse files Browse the repository at this point in the history
  • Loading branch information
jaffee committed Sep 20, 2017
1 parent 2a2d992 commit 24a5c90
Show file tree
Hide file tree
Showing 4 changed files with 27 additions and 24 deletions.
4 changes: 2 additions & 2 deletions client.go
Original file line number Diff line number Diff line change
Expand Up @@ -475,12 +475,12 @@ func (c *Client) patchFrameTimeQuantum(frame *Frame) error {
func (c *Client) status() (*Status, error) {
_, data, err := c.httpRequest("GET", "/status", nil, nil, errorCheckedResponse)
if err != nil {
return nil, err
return nil, errors.Wrap(err, "requesting /status")
}
root := &statusRoot{}
err = json.Unmarshal(data, root)
if err != nil {
return nil, err
return nil, errors.Wrap(err, "unmarshaling /status data")
}
return root.Status, nil
}
Expand Down
23 changes: 23 additions & 0 deletions client_internal_test.go
Original file line number Diff line number Diff line change
@@ -1,8 +1,12 @@
package pilosa

import (
"bytes"
"io/ioutil"
"net/http"
"reflect"
"testing"
"testing/iotest"
)

func TestNewClientFromAddresses(t *testing.T) {
Expand Down Expand Up @@ -53,3 +57,22 @@ func TestMakeRequestData(t *testing.T) {
t.Fatalf("expected err with too large query, but got %v", resp)
}
}

func TestAnyError(t *testing.T) {
err := anyError(
&http.Response{StatusCode: 400,
Body: ioutil.NopCloser(iotest.TimeoutReader(bytes.NewBuffer([]byte("asdf"))))},
nil)
if err == nil {
t.Fatalf("should have gotten an error")
}

err = anyError(
&http.Response{StatusCode: 400,
Body: ioutil.NopCloser(bytes.NewBuffer([]byte("index already exists\n")))},
nil)
if err != ErrorIndexExists {
t.Fatalf("should have gotten ErrorIndexExists, but got %v", err)
}

}
18 changes: 0 additions & 18 deletions client_it_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -1228,24 +1228,6 @@ func TestStatusToNodeSlicesForIndex(t *testing.T) {
}
}

func TestClientCache(t *testing.T) {
// even though this function isn't really an integration test,
// it needs to access getDirectClient which is not
// available to client_test.go
client := DefaultClient()
client2, err := client.getDirectClient("foo.bar:10101")
if err != nil {
t.Fatal(err)
}
client3, err := client.getDirectClient("foo.bar:10101")
if err != nil {
t.Fatal(err)
}
if client2 != client3 {
t.Fatal("Should return the same client for the same host")
}
}

func getClient() *Client {
uri, err := NewURIFromAddress(":10101")
if err != nil {
Expand Down
6 changes: 2 additions & 4 deletions uri_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -32,9 +32,7 @@

package pilosa

import (
"testing"
)
import "testing"

func TestDefaultURI(t *testing.T) {
uri := DefaultURI()
Expand Down Expand Up @@ -76,7 +74,7 @@ func TestURIFromAddress(t *testing.T) {
func TestInvalidAddress(t *testing.T) {
var uri *URI
var err error
addresses := []string{"foo:bar", "http://foo:", "foo:", ":bar"}
addresses := []string{"foo:bar", "http://foo:", "foo:", ":bar", "http://pilosa.com:129999999999999999999999993"}
for _, addr := range addresses {
uri, err = NewURIFromAddress(addr)
if uri != nil || err == nil {
Expand Down

0 comments on commit 24a5c90

Please sign in to comment.