Skip to content

Commit e1d2ac3

Browse files
committed
godoc update and test
1 parent 3dcd106 commit e1d2ac3

14 files changed

+54
-29
lines changed

client.go

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -28,25 +28,25 @@ import (
2828
)
2929

3030
const (
31-
// HTTP method GET
31+
// GET HTTP method
3232
GET = "GET"
3333

34-
// HTTP method POST
34+
// POST HTTP method
3535
POST = "POST"
3636

37-
// HTTP method PUT
37+
// PUT HTTP method
3838
PUT = "PUT"
3939

40-
// HTTP method DELETE
40+
// DELETE HTTP method
4141
DELETE = "DELETE"
4242

43-
// HTTP method PATCH
43+
// PATCH HTTP method
4444
PATCH = "PATCH"
4545

46-
// HTTP method HEAD
46+
// HEAD HTTP method
4747
HEAD = "HEAD"
4848

49-
// HTTP method OPTIONS
49+
// OPTIONS HTTP method
5050
OPTIONS = "OPTIONS"
5151
)
5252

@@ -95,7 +95,7 @@ type User struct {
9595
Username, Password string
9696
}
9797

98-
// SetHostUrl method is to set Host URL in the client instance. It will be used with request
98+
// SetHostURL method is to set Host URL in the client instance. It will be used with request
9999
// raised from this client with relative URL
100100
func (c *Client) SetHostURL(url string) *Client {
101101
c.HostURL = strings.TrimRight(url, "/")

resty_test.go

Lines changed: 46 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -23,11 +23,11 @@ import (
2323
)
2424

2525
type AuthSuccess struct {
26-
Id, Message string
26+
ID, Message string
2727
}
2828

2929
type AuthError struct {
30-
Id, Message string
30+
ID, Message string
3131
}
3232

3333
func TestGet(t *testing.T) {
@@ -460,6 +460,7 @@ func TestFormData(t *testing.T) {
460460

461461
resp, err := c.R().
462462
SetFormData(map[string]string{"first_name": "Jeevanandam", "last_name": "M", "zip_code": "00001"}).
463+
SetBasicAuth("myuser", "mypass").
463464
Post(ts.URL + "/profile")
464465

465466
assertError(t, err)
@@ -551,7 +552,7 @@ func TestGetWithCookies(t *testing.T) {
551552
ts := createGetServer(t)
552553
defer ts.Close()
553554

554-
cookies := make([]*http.Cookie, 0)
555+
var cookies []*http.Cookie
555556

556557
cookies = append(cookies, &http.Cookie{
557558
Name: "go-resty-1",
@@ -730,6 +731,37 @@ func TestClientTimeout(t *testing.T) {
730731
assertEqual(t, true, strings.Contains(err.Error(), "i/o timeout"))
731732
}
732733

734+
func TestHeadMethod(t *testing.T) {
735+
ts := createGetServer(t)
736+
defer ts.Close()
737+
738+
resp, err := dclr().Head(ts.URL + "/")
739+
740+
assertError(t, err)
741+
assertEqual(t, http.StatusOK, resp.StatusCode())
742+
}
743+
744+
func TestOptionsMethod(t *testing.T) {
745+
ts := createGenServer(t)
746+
defer ts.Close()
747+
748+
resp, err := dclr().Options(ts.URL + "/options")
749+
750+
assertError(t, err)
751+
assertEqual(t, http.StatusOK, resp.StatusCode())
752+
assertEqual(t, resp.Header().Get("Access-Control-Expose-Headers"), "x-go-resty-id")
753+
}
754+
755+
func TestPatchMethod(t *testing.T) {
756+
ts := createGenServer(t)
757+
defer ts.Close()
758+
759+
resp, err := dclr().Patch(ts.URL + "/patch")
760+
761+
assertError(t, err)
762+
assertEqual(t, http.StatusOK, resp.StatusCode())
763+
}
764+
733765
func TestClientOptions(t *testing.T) {
734766
c := dc()
735767

@@ -958,6 +990,17 @@ func createGenServer(t *testing.T) *httptest.Server {
958990
w.Write([]byte(`<?xml version="1.0" encoding="UTF-8"?><Response>XML response</Response>`))
959991
}
960992
}
993+
994+
if r.Method == OPTIONS && r.URL.Path == "/options" {
995+
w.Header().Set("Access-Control-Allow-Origin", "localhost")
996+
w.Header().Set("Access-Control-Allow-Methods", "PUT, PATCH")
997+
w.Header().Set("Access-Control-Expose-Headers", "x-go-resty-id")
998+
w.WriteHeader(http.StatusOK)
999+
}
1000+
1001+
if r.Method == PATCH && r.URL.Path == "/patch" {
1002+
w.WriteHeader(http.StatusOK)
1003+
}
9611004
})
9621005

9631006
return ts
-2.46 MB
Binary file not shown.
-2.46 MB
Binary file not shown.
-2.46 MB
Binary file not shown.
-2.46 MB
Binary file not shown.
-2.46 MB
Binary file not shown.
-2.46 MB
Binary file not shown.

test-data/upload/text-file-1442298233.txt

Lines changed: 0 additions & 3 deletions
This file was deleted.

test-data/upload/text-file-1442299321.txt

Lines changed: 0 additions & 3 deletions
This file was deleted.

0 commit comments

Comments
 (0)