@@ -6,13 +6,14 @@ package influxdb2
6
6
7
7
import (
8
8
"context"
9
- http2 "github.com/influxdata/influxdb-client-go/internal/http"
10
- "github.com/stretchr/testify/assert"
11
- "github.com/stretchr/testify/require"
12
9
"net/http"
13
10
"net/http/httptest"
14
11
"testing"
15
12
"time"
13
+
14
+ http2 "github.com/influxdata/influxdb-client-go/internal/http"
15
+ "github.com/stretchr/testify/assert"
16
+ "github.com/stretchr/testify/require"
16
17
)
17
18
18
19
func TestUserAgent (t * testing.T ) {
@@ -72,3 +73,34 @@ func TestServerErrorNonJSON(t *testing.T) {
72
73
assert .Equal (t , "500 Internal Server Error" , perror .Code )
73
74
assert .Equal (t , "internal server error" , perror .Message )
74
75
}
76
+
77
+ func TestServerErrorInflux1_8 (t * testing.T ) {
78
+ server := httptest .NewServer (http .HandlerFunc (func (w http.ResponseWriter , r * http.Request ) {
79
+ w .Header ().Set ("X-Influxdb-Error" , "bruh moment" )
80
+ w .Header ().Set ("Content-Type" , "application/json" )
81
+ w .WriteHeader (404 )
82
+ w .Write ([]byte (`{"error": "bruh moment"}` ))
83
+ }))
84
+
85
+ defer server .Close ()
86
+ c := NewClient (server .URL , "x" )
87
+ err := c .WriteApiBlocking ("o" , "b" ).WriteRecord (context .Background (), "a,a=a a=1i" )
88
+ require .NotNil (t , err )
89
+ perror , ok := err .(* http2.Error )
90
+ require .True (t , ok )
91
+ require .NotNil (t , perror )
92
+ assert .Equal (t , "404 Not Found" , perror .Code )
93
+ assert .Equal (t , "bruh moment" , perror .Message )
94
+ }
95
+
96
+ func TestServerErrorEmptyBody (t * testing.T ) {
97
+ server := httptest .NewServer (http .HandlerFunc (func (w http.ResponseWriter , r * http.Request ) {
98
+ w .WriteHeader (404 )
99
+ }))
100
+
101
+ defer server .Close ()
102
+ c := NewClient (server .URL , "x" )
103
+ err := c .WriteApiBlocking ("o" , "b" ).WriteRecord (context .Background (), "a,a=a a=1i" )
104
+ require .NotNil (t , err )
105
+ assert .Equal (t , "Unexpected status code 404" , err .Error ())
106
+ }
0 commit comments