-
Notifications
You must be signed in to change notification settings - Fork 3.6k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Support chunked queries in the Go InfluxDB client #6166
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -169,6 +169,30 @@ func TestClient_Query(t *testing.T) { | |
} | ||
} | ||
|
||
func TestClient_ChunkedQuery(t *testing.T) { | ||
ts := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) { | ||
var data client.Response | ||
w.WriteHeader(http.StatusOK) | ||
enc := json.NewEncoder(w) | ||
_ = enc.Encode(data) | ||
_ = enc.Encode(data) | ||
})) | ||
defer ts.Close() | ||
|
||
u, _ := url.Parse(ts.URL) | ||
config := client.Config{URL: *u} | ||
c, err := client.NewClient(config) | ||
if err != nil { | ||
t.Fatalf("unexpected error. expected %v, actual %v", nil, err) | ||
} | ||
|
||
query := client.Query{Chunked: true} | ||
_, err = c.Query(query) | ||
if err != nil { | ||
t.Fatalf("unexpected error. expected %v, actual %v", nil, err) | ||
} | ||
} | ||
|
||
func TestClient_BasicAuth(t *testing.T) { | ||
ts := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) { | ||
u, p, ok := r.BasicAuth() | ||
|
@@ -741,3 +765,28 @@ war3JNM1mGB3o2iAtuOJlFIKLpI1x+1e8pI= | |
} | ||
} | ||
} | ||
|
||
func TestChunkedResponse(t *testing.T) { | ||
s := `{"results":[{},{}]}{"results":[{}]}` | ||
r := client.NewChunkedResponse(strings.NewReader(s)) | ||
resp, err := r.NextResponse() | ||
if err != nil { | ||
t.Fatalf("unexpected error. expected %v, actual %v", nil, err) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. You know what I'm going to say about the order of There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Same response I always give :) the rest of the file is one way and I'm going to follow whatever the rest of the file does. I think the double space is weird, but keeping an individual file consistent is more important than my OCD. |
||
} else if actual := len(resp.Results); actual != 2 { | ||
t.Fatalf("unexpected number of results. expected %v, actual %v", 2, actual) | ||
} | ||
|
||
resp, err = r.NextResponse() | ||
if err != nil { | ||
t.Fatalf("unexpected error. expected %v, actual %v", nil, err) | ||
} else if actual := len(resp.Results); actual != 1 { | ||
t.Fatalf("unexpected number of results. expected %v, actual %v", 1, actual) | ||
} | ||
|
||
resp, err = r.NextResponse() | ||
if err != nil { | ||
t.Fatalf("unexpected error. expected %v, actual %v", nil, err) | ||
} else if resp != nil { | ||
t.Fatalf("unexpected response. expected %v, actual %v", nil, resp) | ||
} | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Do we need
Chunked
? Could we useChunkSize > 0
to indicateChunked = true
?There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
If you just send chunked, it will use the default. If you require the chunk size to be set, you can never use the default and have to set the value. I guess the question is if we care about that or we want the client to have a default value that it uses that is separate from the server's.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ah ok. Makes sense.