Skip to content

Commit

Permalink
Merge pull request #2558 from vladlopes/fix-client-responsecheck
Browse files Browse the repository at this point in the history
Fix client response check after PR #2298
  • Loading branch information
toddboom committed May 13, 2015
2 parents e09cded + d8e3de6 commit b213388
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 8 deletions.
2 changes: 1 addition & 1 deletion client/influxdb.go
Original file line number Diff line number Diff line change
Expand Up @@ -140,7 +140,7 @@ func (c *Client) Write(bp BatchPoints) (*Response, error) {
return nil, err
}

if resp.StatusCode != http.StatusOK {
if resp.StatusCode != http.StatusNoContent {
return &response, response.Error()
}

Expand Down
7 changes: 5 additions & 2 deletions client/influxdb_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -100,7 +100,7 @@ func TestClient_BasicAuth(t *testing.T) {
func TestClient_Write(t *testing.T) {
ts := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
var data influxdb.Response
w.WriteHeader(http.StatusOK)
w.WriteHeader(http.StatusNoContent)
_ = json.NewEncoder(w).Encode(data)
}))
defer ts.Close()
Expand All @@ -113,10 +113,13 @@ func TestClient_Write(t *testing.T) {
}

bp := client.BatchPoints{}
_, err = c.Write(bp)
r, err := c.Write(bp)
if err != nil {
t.Fatalf("unexpected error. expected %v, actual %v", nil, err)
}
if r != nil {
t.Fatalf("unexpected response. expected %v, actual %v", nil, r)
}
}

func TestClient_UserAgent(t *testing.T) {
Expand Down
10 changes: 5 additions & 5 deletions cmd/influxd/server_integration_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -1692,7 +1692,7 @@ func TestClientLibrary(t *testing.T) {
name: "no points",
writes: []write{
{
expected: `{}`,
expected: `null`,
bp: client.BatchPoints{Database: "mydb"},
},
},
Expand All @@ -1707,7 +1707,7 @@ func TestClientLibrary(t *testing.T) {
{Name: "cpu", Fields: map[string]interface{}{"value": 1.1}, Time: now},
},
},
expected: `{}`,
expected: `null`,
},
},
queries: []query{
Expand All @@ -1720,9 +1720,9 @@ func TestClientLibrary(t *testing.T) {
{
name: "mulitple points, multiple values",
writes: []write{
{bp: client.BatchPoints{Database: "mydb", Points: []client.Point{{Name: "network", Fields: map[string]interface{}{"rx": 1.1, "tx": 2.1}, Time: now}}}, expected: `{}`},
{bp: client.BatchPoints{Database: "mydb", Points: []client.Point{{Name: "network", Fields: map[string]interface{}{"rx": 1.2, "tx": 2.2}, Time: now.Add(time.Nanosecond)}}}, expected: `{}`},
{bp: client.BatchPoints{Database: "mydb", Points: []client.Point{{Name: "network", Fields: map[string]interface{}{"rx": 1.3, "tx": 2.3}, Time: now.Add(2 * time.Nanosecond)}}}, expected: `{}`},
{bp: client.BatchPoints{Database: "mydb", Points: []client.Point{{Name: "network", Fields: map[string]interface{}{"rx": 1.1, "tx": 2.1}, Time: now}}}, expected: `null`},
{bp: client.BatchPoints{Database: "mydb", Points: []client.Point{{Name: "network", Fields: map[string]interface{}{"rx": 1.2, "tx": 2.2}, Time: now.Add(time.Nanosecond)}}}, expected: `null`},
{bp: client.BatchPoints{Database: "mydb", Points: []client.Point{{Name: "network", Fields: map[string]interface{}{"rx": 1.3, "tx": 2.3}, Time: now.Add(2 * time.Nanosecond)}}}, expected: `null`},
},
queries: []query{
{
Expand Down

0 comments on commit b213388

Please sign in to comment.