Skip to content

Commit

Permalink
Add influx output tests for path prefixes
Browse files Browse the repository at this point in the history
  • Loading branch information
dimrozakis committed Sep 13, 2017
1 parent 5eec5c7 commit c0047e2
Showing 1 changed file with 36 additions and 0 deletions.
36 changes: 36 additions & 0 deletions plugins/outputs/influxdb/client/http_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -373,3 +373,39 @@ func TestGzipCompression(t *testing.T) {

assert.Equal(t, []byte(influxLine), uncompressed.Bytes())
}

func TestHTTPClient_PathPrefix(t *testing.T) {
prefix := "/some/random/prefix"
ts := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
switch r.URL.Path {
case prefix + "/write":
w.WriteHeader(http.StatusNoContent)
w.Header().Set("Content-Type", "application/json")
case prefix + "/query":
w.WriteHeader(http.StatusOK)
w.Header().Set("Content-Type", "application/json")
fmt.Fprintln(w, `{"results":[{}]}`)
default:
w.WriteHeader(http.StatusNotFound)
msg := fmt.Sprintf("Path not found: %s", r.URL.Path)
fmt.Fprintln(w, msg)
}
}))
defer ts.Close()

config := HTTPConfig{
URL: ts.URL + prefix,
}
wp := WriteParams{
Database: "test",
}
client, err := NewHTTP(config, wp)
defer client.Close()
assert.NoError(t, err)
err = client.Query("CREATE DATABASE test")
assert.NoError(t, err)
_, err = client.Write([]byte("cpu value=99\n"))
assert.NoError(t, err)
_, err = client.WriteStream(bytes.NewReader([]byte("cpu value=99\n")), 13)
assert.NoError(t, err)
}

0 comments on commit c0047e2

Please sign in to comment.