@@ -12,7 +12,6 @@ import (
12
12
"testing"
13
13
"time"
14
14
15
- http3 "github.com/influxdata/influxdb-client-go/v2/api/http"
16
15
http2 "github.com/influxdata/influxdb-client-go/v2/internal/http"
17
16
iwrite "github.com/influxdata/influxdb-client-go/v2/internal/write"
18
17
"github.com/stretchr/testify/assert"
@@ -39,8 +38,7 @@ func TestUrls(t *testing.T) {
39
38
assert .Equal (t , url .serverURL , ci .serverURL )
40
39
assert .Equal (t , url .serverAPIURL , ci .httpService .ServerAPIURL ())
41
40
ws := iwrite .NewService ("org" , "bucket" , ci .httpService , c .Options ().WriteOptions ())
42
- wu , err := ws .WriteURL ()
43
- require .Nil (t , err )
41
+ wu := ws .WriteURL ()
44
42
assert .Equal (t , url .writeURLPrefix + "?bucket=bucket&org=org&precision=ns" , wu )
45
43
})
46
44
}
@@ -94,7 +92,7 @@ func TestUserAgent(t *testing.T) {
94
92
assert .Nil (t , err )
95
93
96
94
err = c .WriteAPIBlocking ("o" , "b" ).WriteRecord (context .Background (), "a,a=a a=1i" )
97
- assert .Nil (t , err )
95
+ assert .NoError (t , err )
98
96
}
99
97
100
98
func TestServerError429 (t * testing.T ) {
@@ -109,12 +107,8 @@ func TestServerError429(t *testing.T) {
109
107
defer server .Close ()
110
108
c := NewClient (server .URL , "x" )
111
109
err := c .WriteAPIBlocking ("o" , "b" ).WriteRecord (context .Background (), "a,a=a a=1i" )
112
- require .NotNil (t , err )
113
- perror , ok := err .(* http3.Error )
114
- require .True (t , ok )
115
- require .NotNil (t , perror )
116
- assert .Equal (t , "too many requests" , perror .Code )
117
- assert .Equal (t , "exceeded rate limit" , perror .Message )
110
+ require .Error (t , err )
111
+ assert .Equal (t , "too many requests: exceeded rate limit" , err .Error ())
118
112
}
119
113
120
114
func TestServerOnPath (t * testing.T ) {
@@ -130,7 +124,7 @@ func TestServerOnPath(t *testing.T) {
130
124
defer server .Close ()
131
125
c := NewClient (server .URL + "/proxy/0:0/influx/" , "x" )
132
126
err := c .WriteAPIBlocking ("o" , "b" ).WriteRecord (context .Background (), "a,a=a a=1i" )
133
- require .Nil (t , err )
127
+ require .NoError (t , err )
134
128
}
135
129
136
130
func TestServerErrorNonJSON (t * testing.T ) {
@@ -143,12 +137,8 @@ func TestServerErrorNonJSON(t *testing.T) {
143
137
defer server .Close ()
144
138
c := NewClient (server .URL , "x" )
145
139
err := c .WriteAPIBlocking ("o" , "b" ).WriteRecord (context .Background (), "a,a=a a=1i" )
146
- require .NotNil (t , err )
147
- perror , ok := err .(* http3.Error )
148
- require .True (t , ok )
149
- require .NotNil (t , perror )
150
- assert .Equal (t , "500 Internal Server Error" , perror .Code )
151
- assert .Equal (t , "internal server error" , perror .Message )
140
+ require .Error (t , err )
141
+ assert .Equal (t , "500 Internal Server Error: internal server error" , err .Error ())
152
142
}
153
143
154
144
func TestServerErrorInflux1_8 (t * testing.T ) {
@@ -162,12 +152,8 @@ func TestServerErrorInflux1_8(t *testing.T) {
162
152
defer server .Close ()
163
153
c := NewClient (server .URL , "x" )
164
154
err := c .WriteAPIBlocking ("o" , "b" ).WriteRecord (context .Background (), "a,a=a a=1i" )
165
- require .NotNil (t , err )
166
- perror , ok := err .(* http3.Error )
167
- require .True (t , ok )
168
- require .NotNil (t , perror )
169
- assert .Equal (t , "404 Not Found" , perror .Code )
170
- assert .Equal (t , "bruh moment" , perror .Message )
155
+ require .Error (t , err )
156
+ assert .Equal (t , "404 Not Found: bruh moment" , err .Error ())
171
157
}
172
158
173
159
func TestServerErrorEmptyBody (t * testing.T ) {
@@ -178,6 +164,6 @@ func TestServerErrorEmptyBody(t *testing.T) {
178
164
defer server .Close ()
179
165
c := NewClient (server .URL , "x" )
180
166
err := c .WriteAPIBlocking ("o" , "b" ).WriteRecord (context .Background (), "a,a=a a=1i" )
181
- require .NotNil (t , err )
167
+ require .Error (t , err )
182
168
assert .Equal (t , "Unexpected status code 404" , err .Error ())
183
169
}
0 commit comments