@@ -3,17 +3,18 @@ package relay
33import (
44 "bytes"
55 "fmt"
6- "github.com/stretchr/testify/assert"
7- "github.com/vente-privee/influxdb-relay/config"
86 "log"
97 "net/http"
108 "net/http/httptest"
119 "os"
1210 "testing"
11+
12+ "github.com/stretchr/testify/assert"
13+ "github.com/vente-privee/influxdb-relay/config"
1314)
1415
1516var (
16- promBody = Body {}
17+ promBody = Body {}
1718 influxBody = Body {}
1819
1920 basicPingWriter = & ResponseWriter {
5859 wrongMethodPromWriter = & ResponseWriter {
5960 writeBuf : bytes .NewBuffer ([]byte ("\" " + http .StatusText (http .StatusMethodNotAllowed ) + "\" " )),
6061 header : http.Header {
61- "Allow" : []string {"POST" },
62+ "Allow" : []string {"POST" },
6263 "Content-Type" : []string {"application/json" },
6364 "Content-Length" : []string {fmt .Sprintf ("%d" , len (http .StatusText (http .StatusMethodNotAllowed ))+ 2 )},
6465 },
6768 wrongBackendPromWriter = & ResponseWriter {
6869 writeBuf : bytes .NewBuffer ([]byte ("\" unable to write points\" " )),
6970 header : http.Header {
70- "Allow" : []string {"POST" },
71+ "Allow" : []string {"POST" },
7172 "Content-Type" : []string {"application/json" },
7273 "Content-Length" : []string {"24" },
7374 },
@@ -76,16 +77,16 @@ var (
7677 BackendDownPromWriter = & ResponseWriter {
7778 writeBuf : bytes .NewBuffer ([]byte ("\" unable to write points\" " )),
7879 header : http.Header {
79- "Allow" : []string {"POST" },
80+ "Allow" : []string {"POST" },
8081 "Content-Type" : []string {"application/json" },
8182 "Content-Length" : []string {"24" },
8283 },
8384 code : http .StatusServiceUnavailable ,
8485 }
8586 BackendUpPromWriter = & ResponseWriter {
8687 writeBuf : & bytes.Buffer {},
87- header : http.Header {},
88- code : http .StatusNoContent ,
88+ header : http.Header {},
89+ code : http .StatusNoContent ,
8990 }
9091 BackendUpPromError400Writer = & ResponseWriter {
9192 writeBuf : & bytes.Buffer {},
@@ -105,7 +106,7 @@ var (
105106 wrongMethodInfluxWriter = & ResponseWriter {
106107 writeBuf : bytes .NewBuffer ([]byte ("\" " + http .StatusText (http .StatusMethodNotAllowed ) + "\" " )),
107108 header : http.Header {
108- "Allow" : []string {"POST" },
109+ "Allow" : []string {"POST" },
109110 "Content-Type" : []string {"application/json" },
110111 "Content-Length" : []string {fmt .Sprintf ("%d" , len (http .StatusText (http .StatusMethodNotAllowed ))+ 2 )},
111112 },
@@ -114,7 +115,7 @@ var (
114115 wrongBackendInfluxWriter = & ResponseWriter {
115116 writeBuf : bytes .NewBuffer ([]byte ("\" unable to write points\" " )),
116117 header : http.Header {
117- "Allow" : []string {"POST" },
118+ "Allow" : []string {"POST" },
118119 "Content-Type" : []string {"application/json" },
119120 "Content-Length" : []string {"24" },
120121 },
@@ -123,16 +124,16 @@ var (
123124 BackendDownInfluxWriter = & ResponseWriter {
124125 writeBuf : bytes .NewBuffer ([]byte ("\" unable to write points\" " )),
125126 header : http.Header {
126- "Allow" : []string {"POST" },
127+ "Allow" : []string {"POST" },
127128 "Content-Type" : []string {"application/json" },
128129 "Content-Length" : []string {"24" },
129130 },
130131 code : http .StatusServiceUnavailable ,
131132 }
132133 BackendUpInfluxWriter = & ResponseWriter {
133134 writeBuf : & bytes.Buffer {},
134- header : http.Header {},
135- code : http .StatusNoContent ,
135+ header : http.Header {},
136+ code : http .StatusNoContent ,
136137 }
137138 BackendUpInfluxError400Writer = & ResponseWriter {
138139 writeBuf : & bytes.Buffer {},
@@ -159,8 +160,8 @@ var (
159160 }
160161 InfluxParsePointWriter = & ResponseWriter {
161162 writeBuf : & bytes.Buffer {},
162- header : http.Header {},
163- code : http .StatusNoContent ,
163+ header : http.Header {},
164+ code : http .StatusNoContent ,
164165 }
165166)
166167
@@ -216,7 +217,7 @@ func TestHandlePingWrongMethod(t *testing.T) {
216217
217218func TestHandleStatusSimple (t * testing.T ) {
218219 defer resetWriter ()
219- cfgOut := config.HTTPOutputConfig {Name :"test" , InputType :"influxdb" }
220+ cfgOut := config.HTTPOutputConfig {Name : "test" , InputType : "influxdb" }
220221 h := createHTTP (t , config.HTTPConfig {}, false )
221222 r , err := http .NewRequest ("GET" , "influxdb" , emptyBody )
222223 if err != nil {
@@ -269,8 +270,8 @@ func TestHandlePromWrongBackend(t *testing.T) {
269270func TestHandlePromBackendDown (t * testing.T ) {
270271 defer resetWriter ()
271272 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" }
274275 promBody .buf = bytes .NewBuffer ([]byte {})
275276 r , err := http .NewRequest ("OPTIONS" , "influxdb" , promBody )
276277 if err != nil {
@@ -298,7 +299,7 @@ func TestHandlePromBackendUp(t *testing.T) {
298299 }
299300 }))
300301 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" }
302303 promBody .buf = bytes .NewBuffer ([]byte {})
303304 r , err := http .NewRequest ("POST" , testServer .URL , promBody )
304305 if err != nil {
@@ -318,7 +319,7 @@ func TestHandlePromBackendUpError400(t *testing.T) {
318319 res .WriteHeader (http .StatusBadRequest )
319320 }))
320321 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" }
322323 promBody .buf = bytes .NewBuffer ([]byte {})
323324 r , err := http .NewRequest ("POST" , testServer .URL , promBody )
324325 if err != nil {
@@ -338,7 +339,7 @@ func TestHandlePromBackendUpError500(t *testing.T) {
338339 res .WriteHeader (http .StatusInternalServerError )
339340 }))
340341 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" }
342343 promBody .buf = bytes .NewBuffer ([]byte {})
343344 r , err := http .NewRequest ("POST" , testServer .URL , promBody )
344345 if err != nil {
@@ -383,8 +384,8 @@ func TestHandleInfluxWrongBackend(t *testing.T) {
383384func TestHandleInfluxBackendDown (t * testing.T ) {
384385 defer resetWriter ()
385386 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" }
388389 influxBody .buf = bytes .NewBuffer ([]byte {})
389390 r , err := http .NewRequest ("OPTIONS" , "influxdb" , influxBody )
390391 if err != nil {
@@ -412,7 +413,7 @@ func TestHandleInfluxBackendUp(t *testing.T) {
412413 }
413414 }))
414415 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" }
416417 influxBody .buf = bytes .NewBuffer ([]byte {})
417418 r , err := http .NewRequest ("POST" , testServer .URL , influxBody )
418419 if err != nil {
@@ -432,7 +433,7 @@ func TestHandleInfluxBackendUpError400(t *testing.T) {
432433 res .WriteHeader (http .StatusBadRequest )
433434 }))
434435 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" }
436437 influxBody .buf = bytes .NewBuffer ([]byte {})
437438 r , err := http .NewRequest ("POST" , testServer .URL , influxBody )
438439 if err != nil {
@@ -452,7 +453,7 @@ func TestHandleInfluxBackendUpError500(t *testing.T) {
452453 res .WriteHeader (http .StatusInternalServerError )
453454 }))
454455 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" }
456457 influxBody .buf = bytes .NewBuffer ([]byte {})
457458 r , err := http .NewRequest ("POST" , testServer .URL , influxBody )
458459 if err != nil {
@@ -478,7 +479,7 @@ func TestHandleInfluxFailParsePoint(t *testing.T) {
478479 }
479480 }))
480481 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" }
482483 influxBody .buf = bytes .NewBuffer ([]byte ("Some Bug" ))
483484 r , err := http .NewRequest ("POST" , testServer .URL , influxBody )
484485 if err != nil {
@@ -500,7 +501,7 @@ func TestHandleInfluxParsePoint(t *testing.T) {
500501 }
501502 }))
502503 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" }
504505 influxBody .buf = bytes .NewBuffer ([]byte ("cpu_load_short,host=server01,region=us-west value=0.64 1434055562000000000" ))
505506 r , err := http .NewRequest ("POST" , testServer .URL , influxBody )
506507 if err != nil {
@@ -512,4 +513,3 @@ func TestHandleInfluxParsePoint(t *testing.T) {
512513 WriterTest (t , InfluxParsePointWriter , w )
513514 h .backends = h .backends [:0 ]
514515}
515-
0 commit comments