Exemple #1
0
func TestPageTabURL(t *testing.T) {
	t.Parallel()
	env, _ := fromValues(t, url.Values{})
	pageTabURL := env.PageTabURL("/")
	ensure.StringContains(t, pageTabURL,
		"http://www.facebook.com/pages/Rell-Page-for-Tabs/141929622497380")
	ensure.StringContains(t, pageTabURL, fmt.Sprintf("app_%d", defaultFacebookAppID))
	ensure.StringContains(t, pageTabURL, "app_data=Lw%3D%3D")
}
Exemple #2
0
func TestServerAbort(t *testing.T) {
	t.Parallel()
	for _, code := range []int{200, 500} {
		server := httptest.NewServer(
			http.HandlerFunc(
				func(w http.ResponseWriter, r *http.Request) {
					w.Header().Add("Content-Length", "4000")
					w.WriteHeader(code)
					w.Write(bytes.Repeat([]byte("a"), 3000))
				},
			),
		)

		u, err := url.Parse(server.URL)
		ensure.Nil(t, err)

		c := &fbapi.Client{
			Transport: defaultHTTPTransport,
			BaseURL:   u,
		}
		res := make(map[string]interface{})
		_, err = c.Do(&http.Request{Method: "GET"}, res)
		ensure.NotNil(t, err)
		ensure.StringContains(t, err.Error(), fmt.Sprintf(`GET %s`, server.URL))
		server.CloseClientConnections()
		server.Close()
	}
}
Exemple #3
0
func TestPageTabURLBeta(t *testing.T) {
	t.Parallel()
	env, _ := fromValues(t, url.Values{"server": []string{"beta"}})
	pageTabURL := env.PageTabURL("/")
	ensure.StringContains(t, pageTabURL,
		"http://www.beta.facebook.com/pages/Rell-Page-for-Tabs/141929622497380")
}
Exemple #4
0
func TestCanvasURL(t *testing.T) {
	t.Parallel()
	env, _ := fromValues(t, url.Values{})
	canvasURL := env.CanvasURL("/")
	ensure.StringContains(t, canvasURL,
		fmt.Sprintf("https://apps.facebook.com/%s/", defaultAppNS))
}
Exemple #5
0
func TestCanvasURLBeta(t *testing.T) {
	t.Parallel()
	env, _ := fromValues(t, url.Values{"server": []string{"beta"}})
	canvasURL := env.CanvasURL("/")
	ensure.StringContains(t, canvasURL,
		fmt.Sprintf("https://apps.beta.facebook.com/%s/?server=beta", defaultAppNS))
}
Exemple #6
0
func TestMultiLineStringContains(t *testing.T) {
	var c capture
	ensure.StringContains(&c, "foo\nbaz", "bar")
	c.Equal(t, `ensure_test.go:251: expected substring was not found:
EXPECTED SUBSTRING:
bar
ACTUAL:
foo
baz`)
}
Exemple #7
0
func TestComplex(t *testing.T) {
	t.Parallel()
	values := url.Values{}
	values.Add("status", "1")
	values.Add("server", "beta")
	values.Add("locale", "en_PI")
	expected := &rellenv.Env{
		Status: true,
		Env:    "beta",
	}
	env, _ := fromValues(t, values)
	ensure.Subset(t, env, expected)
	ensure.StringContains(t, env.SdkURL(), "en_PI")
}
Exemple #8
0
func TestStringContains(t *testing.T) {
	var c capture
	ensure.StringContains(&c, "foo", "bar")
	c.Equal(t, "ensure_test.go:143: expected substring \"bar\" was not found in \"foo\"")
}
Exemple #9
0
func TestErrorCases(t *testing.T) {
	cases := []struct {
		Request    *http.Request
		Body       interface{}
		Error      string
		StatusCode int
		Transport  http.RoundTripper
	}{
		{
			Request: &http.Request{
				Method: "GET",
				URL: &url.URL{
					Scheme: "https",
					Host:   "api.parse.com",
					Path:   "/1/classes/Foo/Bar",
				},
			},
			Error:      `parse: api error with code=101 and message="object not found for get"`,
			StatusCode: http.StatusNotFound,
			Transport: transportFunc(func(r *http.Request) (*http.Response, error) {
				j := jsonB(t, parse.Error{
					Code:    101,
					Message: "object not found for get",
				})
				return &http.Response{
					StatusCode: http.StatusNotFound,
					Status:     "404 Not Found",
					Body:       ioutil.NopCloser(bytes.NewReader(j)),
				}, nil
			}),
		},
		{
			Request: &http.Request{
				Method: "GET",
				URL: &url.URL{
					Scheme: "https",
					Host:   "api.parse.com",
					Path:   "/1/classes/Foo/Bar",
				},
			},
			Body:  map[int]int{},
			Error: "unsupported type: map[int]int",
			Transport: transportFunc(func(r *http.Request) (*http.Response, error) {
				panic("not reached")
			}),
		},
		{
			Request: &http.Request{
				Method: "GET",
				URL:    &url.URL{Path: "/"},
			},
			Error:      `error with status=404 and body="<html>`,
			StatusCode: 404,
			Transport: transportFunc(func(r *http.Request) (*http.Response, error) {
				return &http.Response{
					StatusCode: http.StatusNotFound,
					Status:     "404 Not Found",
					Body:       ioutil.NopCloser(strings.NewReader("<html>")),
				}, nil
			}),
		},
	}

	t.Parallel()
	for _, ec := range cases {
		c := &parse.Client{
			Credentials: defaultRestAPIKey,
		}
		if !realTransport {
			c.Transport = ec.Transport
		}
		res, err := c.Do(ec.Request, ec.Body, nil)
		ensure.NotNil(t, err)
		ensure.StringContains(t, err.Error(), ec.Error, ec)
		if ec.StatusCode != 0 {
			ensure.False(t, res == nil, ec)
			ensure.DeepEqual(t, res.StatusCode, ec.StatusCode, ec)
		}
	}
}
Exemple #10
0
func indirect(f ensure.Fataler) {
	ensure.StringContains(f, "foo", "bar")
}