Ejemplo n.º 1
0
func TestContextClient(t *testing.T) {
	rc := &http.Client{}
	RegisterContextClientFunc(func(context.Context) (*http.Client, error) {
		return rc, nil
	})

	c := &http.Client{}
	ctx := context.WithValue(nil, HTTPClient, c)

	hc, err := ContextClient(ctx)
	if err != nil {
		t.Fatalf("want valid client; got err = %v", err)
	}
	if hc != c {
		t.Fatalf("want context client = %p; got = %p", c, hc)
	}

	hc, err = ContextClient(context.TODO())
	if err != nil {
		t.Fatalf("want valid client; got err = %v", err)
	}
	if hc != rc {
		t.Fatalf("want registered client = %p; got = %p", c, hc)
	}
}
Ejemplo n.º 2
0
func TestExchangeRequest_NonBasicAuth(t *testing.T) {
	tr := &mockTransport{
		rt: func(r *http.Request) (w *http.Response, err error) {
			headerAuth := r.Header.Get("Authorization")
			if headerAuth != "" {
				t.Errorf("Unexpected authorization header, %v is found.", headerAuth)
			}
			return nil, errors.New("no response")
		},
	}
	c := &http.Client{Transport: tr}
	conf := &Config{
		ClientID: "CLIENT_ID",
		Endpoint: Endpoint{
			AuthURL:  "https://accounts.google.com/auth",
			TokenURL: "https://accounts.google.com/token",
		},
	}

	ctx := context.WithValue(context.Background(), HTTPClient, c)
	conf.Exchange(ctx, "code")
}