@@ -40,6 +40,7 @@ const (
40
40
// baseURLPath is a non-empty Client.BaseURL path to use during tests,
41
41
// to ensure relative URLs are used for all endpoints.
42
42
baseURLPath = "/api-v1"
43
+ requestPath = "foo"
43
44
)
44
45
45
46
// setup sets up a test HTTP server along with a opsmngr.Client that is
@@ -138,8 +139,6 @@ type testRequestBody struct {
138
139
func TestNewRequest_withUserData (t * testing.T ) {
139
140
c := NewClient (nil )
140
141
141
- requestPath := "foo"
142
-
143
142
inURL , outURL := requestPath , defaultBaseURL + requestPath
144
143
inBody , outBody := & testRequestBody {TestName : "l" , TestUserData : "u" },
145
144
`{"testName":"l","testCounter":0,` +
@@ -233,6 +232,62 @@ func TestNewRequest_errorForNoTrailingSlash(t *testing.T) {
233
232
}
234
233
}
235
234
235
+ func TestNewPlainRequest_emptyBody (t * testing.T ) {
236
+ c := NewClient (nil )
237
+ req , err := c .NewPlainRequest (ctx , http .MethodGet , "." )
238
+ if err != nil {
239
+ t .Fatalf ("NewPlainRequest returned unexpected error: %v" , err )
240
+ }
241
+ if req .Body != nil {
242
+ t .Fatalf ("constructed request contains a non-nil Body" )
243
+ }
244
+ }
245
+
246
+ func TestNewPlainRequest_withCustomUserAgent (t * testing.T ) {
247
+ c , err := New (nil , SetUserAgent (ua ))
248
+
249
+ if err != nil {
250
+ t .Fatalf ("New() unexpected error: %v" , err )
251
+ }
252
+
253
+ req , _ := c .NewPlainRequest (ctx , http .MethodGet , "/foo" )
254
+
255
+ expected := fmt .Sprintf ("%s %s" , ua , userAgent )
256
+ if got := req .Header .Get ("User-Agent" ); got != expected {
257
+ t .Errorf ("NewPlainRequest() UserAgent = %s; expected %s" , got , expected )
258
+ }
259
+ }
260
+
261
+ func TestNewPlainRequest_badURL (t * testing.T ) {
262
+ c := NewClient (nil )
263
+ _ , err := c .NewPlainRequest (ctx , http .MethodGet , ":" )
264
+ testURLParseError (t , err )
265
+ }
266
+
267
+ func TestNewPlainRequest (t * testing.T ) {
268
+ c := NewClient (nil )
269
+
270
+ inURL , outURL := requestPath , defaultBaseURL + requestPath
271
+ req , _ := c .NewPlainRequest (ctx , http .MethodGet , inURL )
272
+
273
+ // test relative URL was expanded
274
+ if req .URL .String () != outURL {
275
+ t .Errorf ("NewPlainRequest(%v) URL = %v, expected %v" , inURL , req .URL , outURL )
276
+ }
277
+
278
+ // test accept content type is correct
279
+ accept := req .Header .Get ("Accept" )
280
+ if plainMediaType != accept {
281
+ t .Errorf ("NewPlainRequest() Accept = %v, expected %v" , accept , gzipMediaType )
282
+ }
283
+
284
+ // test default user-agent is attached to the request
285
+ uA := req .Header .Get ("User-Agent" )
286
+ if c .UserAgent != uA {
287
+ t .Errorf ("NewPlainRequest() User-Agent = %v, expected %v" , uA , c .UserAgent )
288
+ }
289
+ }
290
+
236
291
const testResponse = `{"A":"a"}`
237
292
238
293
func TestClient_Do (t * testing.T ) {
0 commit comments