-
Notifications
You must be signed in to change notification settings - Fork 3.6k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Set the CSV output to an empty string for null values
- Loading branch information
1 parent
9bd7fce
commit 7707263
Showing
3 changed files
with
69 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,61 @@ | ||
package httpd_test | ||
|
||
import ( | ||
"net/http" | ||
"net/http/httptest" | ||
"net/url" | ||
"testing" | ||
"time" | ||
|
||
"github.com/influxdata/influxdb/influxql" | ||
"github.com/influxdata/influxdb/models" | ||
"github.com/influxdata/influxdb/services/httpd" | ||
) | ||
|
||
func TestResponseWriter_CSV(t *testing.T) { | ||
header := make(http.Header) | ||
header.Set("Accept", "text/csv") | ||
r := &http.Request{ | ||
Header: header, | ||
URL: &url.URL{}, | ||
} | ||
w := httptest.NewRecorder() | ||
|
||
writer := httpd.NewResponseWriter(w, r) | ||
writer.WriteResponse(httpd.Response{ | ||
Results: []*influxql.Result{ | ||
{ | ||
StatementID: 0, | ||
Series: []*models.Row{ | ||
{ | ||
Name: "cpu", | ||
Tags: map[string]string{ | ||
"host": "server01", | ||
"region": "uswest", | ||
}, | ||
Columns: []string{"time", "value"}, | ||
Values: [][]interface{}{ | ||
{time.Unix(0, 10), float64(2.5)}, | ||
{time.Unix(0, 20), int64(5)}, | ||
{time.Unix(0, 30), nil}, | ||
{time.Unix(0, 40), "foobar"}, | ||
{time.Unix(0, 50), true}, | ||
{time.Unix(0, 60), false}, | ||
}, | ||
}, | ||
}, | ||
}, | ||
}, | ||
}) | ||
|
||
if got, want := w.Body.String(), `name,tags,time,value | ||
cpu,"host=server01,region=uswest",10,2.5 | ||
cpu,"host=server01,region=uswest",20,5 | ||
cpu,"host=server01,region=uswest",30, | ||
cpu,"host=server01,region=uswest",40,foobar | ||
cpu,"host=server01,region=uswest",50,true | ||
cpu,"host=server01,region=uswest",60,false | ||
`; got != want { | ||
t.Errorf("unexpected output:\n\ngot=%v\nwant=%s", got, want) | ||
} | ||
} |