Пример #1
0
func TestPostsAllUrls(t *testing.T) {
	httpmock.Activate()
	defer httpmock.DeactivateAndReset()

	for _, tt := range postsAllUrlTests {
		httpmock.Reset()
		httpmock.RegisterResponder("GET", tt.out_url,
			httpmock.NewStringResponder(200, readFixture("posts_all")))
		_, _, err := client.Posts.All(tt.in_tags, tt.in_start, tt.in_results, tt.in_fromdt, tt.in_todt)
		if err != nil {
			t.Error(err)
		}
	}
}
Пример #2
0
func TestPostsGetUrls(t *testing.T) {
	httpmock.Activate()
	defer httpmock.DeactivateAndReset()

	for _, tt := range postsGetUrlTests {
		httpmock.Reset()
		httpmock.RegisterResponder("GET", tt.out_url,
			httpmock.NewStringResponder(200, readFixture("posts_get")))
		_, _, err := client.Posts.Get(tt.in_tags, tt.in_creation, tt.in_urlstr)
		if err != nil {
			t.Error(err)
		}
	}
}
Пример #3
0
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)
		}
	}
}