/
pin_test.go
43 lines (34 loc) · 1003 Bytes
/
pin_test.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
package pin
import (
"net/http"
"testing"
"errors"
"fmt"
"github.com/jarcoal/httpmock"
)
var clientRequestCodes = []struct {
in_code int
out_err error
}{
{http.StatusOK, nil},
{http.StatusTooManyRequests, errors.New(http.StatusText(http.StatusTooManyRequests))},
{http.StatusUnauthorized, errors.New(http.StatusText(http.StatusUnauthorized))},
}
func TestClientRateLimit(t *testing.T) {
httpmock.Activate()
defer httpmock.DeactivateAndReset()
for _, tt := range clientRequestCodes {
httpmock.Reset()
httpmock.RegisterResponder("GET", "https://api.pinboard.in/v1/endpoint?auth_token=user%3Atoken",
httpmock.NewStringResponder(tt.in_code, readFixture("posts_err")))
req, err := client.NewRequest("endpoint", nil)
if err != nil {
t.Error(err)
}
_, err = client.Do(req, nil)
//t.Error(err)
if fmt.Sprintf("%v", err) != fmt.Sprintf("%v", tt.out_err) {
t.Errorf("Missing HTTP handling for status %d got '%v' expected '%v'", tt.in_code, err, tt.out_err)
}
}
}