@@ -84,7 +84,7 @@ func (t *testHttpService) PostRequest(_ context.Context, url string, body io.Rea
84
84
body , _ = gzip .NewReader (body )
85
85
t .wasGzip = true
86
86
}
87
- assert .Equal (t .t , url , fmt .Sprintf ("%s/api/v2/write ?bucket=my-bucket&org=my-org&precision=ns" , t .serverUrl ))
87
+ assert .Equal (t .t , fmt .Sprintf ("%swrite ?bucket=my-bucket&org=my-org&precision=ns" , t .serverUrl ), url )
88
88
89
89
if t .ReplyError () != nil {
90
90
return t .ReplyError ()
@@ -121,6 +121,18 @@ func (t *testHttpService) Lines() []string {
121
121
return t .lines
122
122
}
123
123
124
+ func newTestClient () * client {
125
+ return & client {serverUrl : "http://locahost:4444" , options : DefaultOptions ()}
126
+ }
127
+
128
+ func newTestService (t * testing.T , client InfluxDBClient ) * testHttpService {
129
+ return & testHttpService {
130
+ t : t ,
131
+ options : client .Options (),
132
+ serverUrl : client .ServerUrl () + "/api/v2/" ,
133
+ }
134
+ }
135
+
124
136
func genPoints (num int ) []* Point {
125
137
points := make ([]* Point , num )
126
138
rand .Seed (321 )
@@ -165,12 +177,8 @@ func genRecords(num int) []string {
165
177
}
166
178
167
179
func TestWriteApiImpl_Write (t * testing.T ) {
168
- client := & client {serverUrl : "http://locahost:4444" , options : DefaultOptions ()}
169
- service := & testHttpService {
170
- t : t ,
171
- options : client .Options (),
172
- serverUrl : client .ServerUrl (),
173
- }
180
+ client := newTestClient ()
181
+ service := newTestService (t , client )
174
182
client .options .SetBatchSize (5 )
175
183
writeApi := newWriteApiImpl ("my-org" , "my-bucket" , service , client )
176
184
points := genPoints (10 )
@@ -188,12 +196,8 @@ func TestWriteApiImpl_Write(t *testing.T) {
188
196
}
189
197
190
198
func TestGzipWithFlushing (t * testing.T ) {
191
- client := & client {serverUrl : "http://locahost:4444" , options : DefaultOptions ()}
192
- service := & testHttpService {
193
- t : t ,
194
- options : client .Options (),
195
- serverUrl : client .ServerUrl (),
196
- }
199
+ client := newTestClient ()
200
+ service := newTestService (t , client )
197
201
client .options .SetBatchSize (5 ).SetUseGZip (true )
198
202
writeApi := newWriteApiImpl ("my-org" , "my-bucket" , service , client )
199
203
points := genPoints (5 )
@@ -216,12 +220,8 @@ func TestGzipWithFlushing(t *testing.T) {
216
220
writeApi .Close ()
217
221
}
218
222
func TestFlushInterval (t * testing.T ) {
219
- client := & client {serverUrl : "http://locahost:4444" , options : DefaultOptions ()}
220
- service := & testHttpService {
221
- t : t ,
222
- options : client .Options (),
223
- serverUrl : client .ServerUrl (),
224
- }
223
+ client := newTestClient ()
224
+ service := newTestService (t , client )
225
225
client .options .SetBatchSize (10 ).SetFlushInterval (500 )
226
226
writeApi := newWriteApiImpl ("my-org" , "my-bucket" , service , client )
227
227
points := genPoints (5 )
@@ -247,12 +247,8 @@ func TestFlushInterval(t *testing.T) {
247
247
}
248
248
249
249
func TestRetry (t * testing.T ) {
250
- client := & client {serverUrl : "http://locahost:4444" , options : DefaultOptions ()}
251
- service := & testHttpService {
252
- t : t ,
253
- options : client .Options (),
254
- serverUrl : client .ServerUrl (),
255
- }
250
+ client := newTestClient ()
251
+ service := newTestService (t , client )
256
252
client .options .SetLogLevel (3 ).
257
253
SetBatchSize (5 ).
258
254
SetRetryInterval (10000 )
@@ -291,12 +287,8 @@ func TestRetry(t *testing.T) {
291
287
}
292
288
293
289
func TestWriteError (t * testing.T ) {
294
- client := & client {serverUrl : "http://locahost:4444" , options : DefaultOptions ()}
295
- service := & testHttpService {
296
- t : t ,
297
- options : client .Options (),
298
- serverUrl : client .ServerUrl (),
299
- }
290
+ client := newTestClient ()
291
+ service := newTestService (t , client )
300
292
client .options .SetLogLevel (3 ).SetBatchSize (5 )
301
293
service .replyError = & ihttp.Error {
302
294
StatusCode : 400 ,
0 commit comments