@@ -3,17 +3,18 @@ package relay
3
3
import (
4
4
"bytes"
5
5
"fmt"
6
- "github.com/stretchr/testify/assert"
7
- "github.com/vente-privee/influxdb-relay/config"
8
6
"log"
9
7
"net/http"
10
8
"net/http/httptest"
11
9
"os"
12
10
"testing"
11
+
12
+ "github.com/stretchr/testify/assert"
13
+ "github.com/vente-privee/influxdb-relay/config"
13
14
)
14
15
15
16
var (
16
- promBody = Body {}
17
+ promBody = Body {}
17
18
influxBody = Body {}
18
19
19
20
basicPingWriter = & ResponseWriter {
58
59
wrongMethodPromWriter = & ResponseWriter {
59
60
writeBuf : bytes .NewBuffer ([]byte ("\" " + http .StatusText (http .StatusMethodNotAllowed ) + "\" " )),
60
61
header : http.Header {
61
- "Allow" : []string {"POST" },
62
+ "Allow" : []string {"POST" },
62
63
"Content-Type" : []string {"application/json" },
63
64
"Content-Length" : []string {fmt .Sprintf ("%d" , len (http .StatusText (http .StatusMethodNotAllowed ))+ 2 )},
64
65
},
67
68
wrongBackendPromWriter = & ResponseWriter {
68
69
writeBuf : bytes .NewBuffer ([]byte ("\" unable to write points\" " )),
69
70
header : http.Header {
70
- "Allow" : []string {"POST" },
71
+ "Allow" : []string {"POST" },
71
72
"Content-Type" : []string {"application/json" },
72
73
"Content-Length" : []string {"24" },
73
74
},
@@ -76,16 +77,16 @@ var (
76
77
BackendDownPromWriter = & ResponseWriter {
77
78
writeBuf : bytes .NewBuffer ([]byte ("\" unable to write points\" " )),
78
79
header : http.Header {
79
- "Allow" : []string {"POST" },
80
+ "Allow" : []string {"POST" },
80
81
"Content-Type" : []string {"application/json" },
81
82
"Content-Length" : []string {"24" },
82
83
},
83
84
code : http .StatusServiceUnavailable ,
84
85
}
85
86
BackendUpPromWriter = & ResponseWriter {
86
87
writeBuf : & bytes.Buffer {},
87
- header : http.Header {},
88
- code : http .StatusNoContent ,
88
+ header : http.Header {},
89
+ code : http .StatusNoContent ,
89
90
}
90
91
BackendUpPromError400Writer = & ResponseWriter {
91
92
writeBuf : & bytes.Buffer {},
@@ -105,7 +106,7 @@ var (
105
106
wrongMethodInfluxWriter = & ResponseWriter {
106
107
writeBuf : bytes .NewBuffer ([]byte ("\" " + http .StatusText (http .StatusMethodNotAllowed ) + "\" " )),
107
108
header : http.Header {
108
- "Allow" : []string {"POST" },
109
+ "Allow" : []string {"POST" },
109
110
"Content-Type" : []string {"application/json" },
110
111
"Content-Length" : []string {fmt .Sprintf ("%d" , len (http .StatusText (http .StatusMethodNotAllowed ))+ 2 )},
111
112
},
@@ -114,7 +115,7 @@ var (
114
115
wrongBackendInfluxWriter = & ResponseWriter {
115
116
writeBuf : bytes .NewBuffer ([]byte ("\" unable to write points\" " )),
116
117
header : http.Header {
117
- "Allow" : []string {"POST" },
118
+ "Allow" : []string {"POST" },
118
119
"Content-Type" : []string {"application/json" },
119
120
"Content-Length" : []string {"24" },
120
121
},
@@ -123,16 +124,16 @@ var (
123
124
BackendDownInfluxWriter = & ResponseWriter {
124
125
writeBuf : bytes .NewBuffer ([]byte ("\" unable to write points\" " )),
125
126
header : http.Header {
126
- "Allow" : []string {"POST" },
127
+ "Allow" : []string {"POST" },
127
128
"Content-Type" : []string {"application/json" },
128
129
"Content-Length" : []string {"24" },
129
130
},
130
131
code : http .StatusServiceUnavailable ,
131
132
}
132
133
BackendUpInfluxWriter = & ResponseWriter {
133
134
writeBuf : & bytes.Buffer {},
134
- header : http.Header {},
135
- code : http .StatusNoContent ,
135
+ header : http.Header {},
136
+ code : http .StatusNoContent ,
136
137
}
137
138
BackendUpInfluxError400Writer = & ResponseWriter {
138
139
writeBuf : & bytes.Buffer {},
@@ -159,8 +160,8 @@ var (
159
160
}
160
161
InfluxParsePointWriter = & ResponseWriter {
161
162
writeBuf : & bytes.Buffer {},
162
- header : http.Header {},
163
- code : http .StatusNoContent ,
163
+ header : http.Header {},
164
+ code : http .StatusNoContent ,
164
165
}
165
166
)
166
167
@@ -216,7 +217,7 @@ func TestHandlePingWrongMethod(t *testing.T) {
216
217
217
218
func TestHandleStatusSimple (t * testing.T ) {
218
219
defer resetWriter ()
219
- cfgOut := config.HTTPOutputConfig {Name :"test" , InputType :"influxdb" }
220
+ cfgOut := config.HTTPOutputConfig {Name : "test" , InputType : "influxdb" }
220
221
h := createHTTP (t , config.HTTPConfig {}, false )
221
222
r , err := http .NewRequest ("GET" , "influxdb" , emptyBody )
222
223
if err != nil {
@@ -269,8 +270,8 @@ func TestHandlePromWrongBackend(t *testing.T) {
269
270
func TestHandlePromBackendDown (t * testing.T ) {
270
271
defer resetWriter ()
271
272
h := createHTTP (t , config.HTTPConfig {}, false )
272
- cfgOutProm := config.HTTPOutputConfig {Name :"test_prometheus" , InputType :"prometheus" }
273
- cfgOutInflux := config.HTTPOutputConfig {Name :"test_influx" , InputType :"influxdb" }
273
+ cfgOutProm := config.HTTPOutputConfig {Name : "test_prometheus" , InputType : "prometheus" }
274
+ cfgOutInflux := config.HTTPOutputConfig {Name : "test_influx" , InputType : "influxdb" }
274
275
promBody .buf = bytes .NewBuffer ([]byte {})
275
276
r , err := http .NewRequest ("OPTIONS" , "influxdb" , promBody )
276
277
if err != nil {
@@ -298,7 +299,7 @@ func TestHandlePromBackendUp(t *testing.T) {
298
299
}
299
300
}))
300
301
defer testServer .Close ()
301
- cfgOutProm := config.HTTPOutputConfig {Name :"test_prometheus" , InputType :"prometheus" , Location : testServer .URL + "/prom" }
302
+ cfgOutProm := config.HTTPOutputConfig {Name : "test_prometheus" , InputType : "prometheus" , Location : testServer .URL + "/prom" }
302
303
promBody .buf = bytes .NewBuffer ([]byte {})
303
304
r , err := http .NewRequest ("POST" , testServer .URL , promBody )
304
305
if err != nil {
@@ -318,7 +319,7 @@ func TestHandlePromBackendUpError400(t *testing.T) {
318
319
res .WriteHeader (http .StatusBadRequest )
319
320
}))
320
321
defer testServer .Close ()
321
- cfgOutProm := config.HTTPOutputConfig {Name :"test_prometheus" , InputType :"prometheus" , Location : testServer .URL + "/prom" }
322
+ cfgOutProm := config.HTTPOutputConfig {Name : "test_prometheus" , InputType : "prometheus" , Location : testServer .URL + "/prom" }
322
323
promBody .buf = bytes .NewBuffer ([]byte {})
323
324
r , err := http .NewRequest ("POST" , testServer .URL , promBody )
324
325
if err != nil {
@@ -338,7 +339,7 @@ func TestHandlePromBackendUpError500(t *testing.T) {
338
339
res .WriteHeader (http .StatusInternalServerError )
339
340
}))
340
341
defer testServer .Close ()
341
- cfgOutProm := config.HTTPOutputConfig {Name :"test_prometheus" , InputType :"prometheus" , Location : testServer .URL + "/prom" }
342
+ cfgOutProm := config.HTTPOutputConfig {Name : "test_prometheus" , InputType : "prometheus" , Location : testServer .URL + "/prom" }
342
343
promBody .buf = bytes .NewBuffer ([]byte {})
343
344
r , err := http .NewRequest ("POST" , testServer .URL , promBody )
344
345
if err != nil {
@@ -383,8 +384,8 @@ func TestHandleInfluxWrongBackend(t *testing.T) {
383
384
func TestHandleInfluxBackendDown (t * testing.T ) {
384
385
defer resetWriter ()
385
386
h := createHTTP (t , config.HTTPConfig {}, false )
386
- cfgOutProm := config.HTTPOutputConfig {Name :"test_prometheus" , InputType :"prometheus" }
387
- cfgOutInflux := config.HTTPOutputConfig {Name :"test_influx" , InputType :"influxdb" }
387
+ cfgOutProm := config.HTTPOutputConfig {Name : "test_prometheus" , InputType : "prometheus" }
388
+ cfgOutInflux := config.HTTPOutputConfig {Name : "test_influx" , InputType : "influxdb" }
388
389
influxBody .buf = bytes .NewBuffer ([]byte {})
389
390
r , err := http .NewRequest ("OPTIONS" , "influxdb" , influxBody )
390
391
if err != nil {
@@ -412,7 +413,7 @@ func TestHandleInfluxBackendUp(t *testing.T) {
412
413
}
413
414
}))
414
415
defer testServer .Close ()
415
- cfgOutProm := config.HTTPOutputConfig {Name :"test_influx" , InputType :"influxdb" , Location : testServer .URL + "/influxdb" }
416
+ cfgOutProm := config.HTTPOutputConfig {Name : "test_influx" , InputType : "influxdb" , Location : testServer .URL + "/influxdb" }
416
417
influxBody .buf = bytes .NewBuffer ([]byte {})
417
418
r , err := http .NewRequest ("POST" , testServer .URL , influxBody )
418
419
if err != nil {
@@ -432,7 +433,7 @@ func TestHandleInfluxBackendUpError400(t *testing.T) {
432
433
res .WriteHeader (http .StatusBadRequest )
433
434
}))
434
435
defer testServer .Close ()
435
- cfgOutProm := config.HTTPOutputConfig {Name :"test_influx" , InputType :"influxdb" , Location : testServer .URL + "/influxdb" }
436
+ cfgOutProm := config.HTTPOutputConfig {Name : "test_influx" , InputType : "influxdb" , Location : testServer .URL + "/influxdb" }
436
437
influxBody .buf = bytes .NewBuffer ([]byte {})
437
438
r , err := http .NewRequest ("POST" , testServer .URL , influxBody )
438
439
if err != nil {
@@ -452,7 +453,7 @@ func TestHandleInfluxBackendUpError500(t *testing.T) {
452
453
res .WriteHeader (http .StatusInternalServerError )
453
454
}))
454
455
defer testServer .Close ()
455
- cfgOutProm := config.HTTPOutputConfig {Name :"test_influx" , InputType :"influxdb" , Location : testServer .URL + "/influxdb" }
456
+ cfgOutProm := config.HTTPOutputConfig {Name : "test_influx" , InputType : "influxdb" , Location : testServer .URL + "/influxdb" }
456
457
influxBody .buf = bytes .NewBuffer ([]byte {})
457
458
r , err := http .NewRequest ("POST" , testServer .URL , influxBody )
458
459
if err != nil {
@@ -478,7 +479,7 @@ func TestHandleInfluxFailParsePoint(t *testing.T) {
478
479
}
479
480
}))
480
481
defer testServer .Close ()
481
- cfgOutProm := config.HTTPOutputConfig {Name :"test_influx" , InputType :"influxdb" , Location : testServer .URL + "/influxdb" }
482
+ cfgOutProm := config.HTTPOutputConfig {Name : "test_influx" , InputType : "influxdb" , Location : testServer .URL + "/influxdb" }
482
483
influxBody .buf = bytes .NewBuffer ([]byte ("Some Bug" ))
483
484
r , err := http .NewRequest ("POST" , testServer .URL , influxBody )
484
485
if err != nil {
@@ -500,7 +501,7 @@ func TestHandleInfluxParsePoint(t *testing.T) {
500
501
}
501
502
}))
502
503
defer testServer .Close ()
503
- cfgOutProm := config.HTTPOutputConfig {Name :"test_influx" , InputType :"influxdb" , Location : testServer .URL + "/influxdb" }
504
+ cfgOutProm := config.HTTPOutputConfig {Name : "test_influx" , InputType : "influxdb" , Location : testServer .URL + "/influxdb" }
504
505
influxBody .buf = bytes .NewBuffer ([]byte ("cpu_load_short,host=server01,region=us-west value=0.64 1434055562000000000" ))
505
506
r , err := http .NewRequest ("POST" , testServer .URL , influxBody )
506
507
if err != nil {
@@ -512,4 +513,3 @@ func TestHandleInfluxParsePoint(t *testing.T) {
512
513
WriterTest (t , InfluxParsePointWriter , w )
513
514
h .backends = h .backends [:0 ]
514
515
}
515
-
0 commit comments