當前位置: 首頁>>代碼示例>>Golang>>正文


Golang ensure.Err函數代碼示例

本文整理匯總了Golang中github.com/daaku/rell/internal/github.com/facebookgo/ensure.Err函數的典型用法代碼示例。如果您正苦於以下問題:Golang Err函數的具體用法?Golang Err怎麽用?Golang Err使用的例子?那麽, 這裏精選的函數代碼示例或許可以為您提供幫助。


在下文中一共展示了Err函數的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Golang代碼示例。

示例1: TestEmptySessionTokenInSessionToken

func TestEmptySessionTokenInSessionToken(t *testing.T) {
	t.Parallel()
	st := parse.SessionToken{
		ApplicationID: defaultApplicationID,
		RestAPIKey:    "rk",
	}
	ensure.Err(t, st.Modify(nil), regexp.MustCompile("empty SessionToken"))
}
開發者ID:chrisp-fb,項目名稱:rell,代碼行數:8,代碼來源:parse_test.go

示例2: TestCredentiasModifyError

func TestCredentiasModifyError(t *testing.T) {
	t.Parallel()
	c := parse.Client{
		Credentials: parse.RestAPIKey{},
	}
	_, err := c.Do(&http.Request{}, nil, nil)
	ensure.Err(t, err, regexp.MustCompile("empty ApplicationID"))
}
開發者ID:chrisp-fb,項目名稱:rell,代碼行數:8,代碼來源:parse_test.go

示例3: TestMissingCredentials

func TestMissingCredentials(t *testing.T) {
	t.Parallel()
	var c parse.Client
	req := http.Request{Method: "GET", URL: &url.URL{Path: "classes/Foo/Bar"}}
	_, err := c.Do(&req, nil, nil)
	ensure.NotNil(t, err)
	ensure.Err(t, err, regexp.MustCompile(`parse: api error with message="unauthorized"`))
}
開發者ID:chrisp-fb,項目名稱:rell,代碼行數:8,代碼來源:integration_test.go

示例4: TestInvalidFlagValue

func TestInvalidFlagValue(t *testing.T) {
	const name = "TestInvalidFlagValue"
	s := flag.NewFlagSet(name, flag.PanicOnError)
	s.Int("bar", 0, "")
	os.Setenv(named(name, "bar"), "a")
	ensure.Err(t, flagenv.ParseSet(name, s),
		regexp.MustCompile(`failed to set flag "bar" with value "a"`))
}
開發者ID:chrisp-fb,項目名稱:rell,代碼行數:8,代碼來源:flagenv_test.go

示例5: TestNewRequestAfterStop

func TestNewRequestAfterStop(t *testing.T) {
	t.Parallel()
	const count = 10000
	hello := []byte("hello")
	finOkHandler := make(chan struct{})
	unblockOkHandler := make(chan struct{})
	okHandler := func(w http.ResponseWriter, r *http.Request) {
		defer close(finOkHandler)
		w.WriteHeader(200)
		const diff = 500
		for i := 0; i < count-diff; i++ {
			w.Write(hello)
		}
		<-unblockOkHandler
		for i := 0; i < diff; i++ {
			w.Write(hello)
		}
	}

	listener, err := net.Listen("tcp", "127.0.0.1:0")
	listener, onClose := NewOnCloseListener(listener)
	ensure.Nil(t, err)
	server := &http.Server{Handler: http.HandlerFunc(okHandler)}
	transport := &http.Transport{}
	client := &http.Client{Transport: transport}
	down := &httpdown.HTTP{}
	s := down.Serve(server, listener)
	res, err := client.Get(fmt.Sprintf("http://%s/", listener.Addr().String()))
	ensure.Nil(t, err)

	finStop := make(chan struct{})
	go func() {
		defer close(finStop)
		ensure.Nil(t, s.Stop())
	}()

	// Wait until the listener is closed.
	<-onClose

	// Now the next request should not be able to connect as the listener is
	// now closed.
	_, err = client.Get(fmt.Sprintf("http://%s/", listener.Addr().String()))

	// We should just get "connection refused" here, but sometimes, very rarely,
	// we get a "connection reset" instead. Unclear why this happens.
	ensure.Err(t, err, regexp.MustCompile("(connection refused|connection reset by peer)$"))

	// Unblock the handler and ensure we finish writing the rest of the body
	// successfully.
	close(unblockOkHandler)
	actualBody, err := ioutil.ReadAll(res.Body)
	ensure.Nil(t, err)
	ensure.DeepEqual(t, actualBody, bytes.Repeat(hello, count))
	ensure.Nil(t, res.Body.Close())
	<-finOkHandler
	<-finStop
}
開發者ID:chrisp-fb,項目名稱:rell,代碼行數:57,代碼來源:httpdown_test.go

示例6: TestTransportError

func TestTransportError(t *testing.T) {
	t.Parallel()
	c := &fbapi.Client{
		Transport: errorTransport{},
	}
	res := make(map[string]interface{})
	_, err := c.Do(&http.Request{Method: "GET"}, res)
	ensure.Err(t, err, regexp.MustCompile(`42`))
}
開發者ID:chrisp-fb,項目名稱:rell,代碼行數:9,代碼來源:client_test.go

示例7: TestReturnsFirstError

func TestReturnsFirstError(t *testing.T) {
	const name = "TestReturnsFirstError"
	s := flag.NewFlagSet(name, flag.PanicOnError)
	s.Int("bar1", 0, "")
	s.Int("bar2", 0, "")
	os.Setenv(named(name, "bar1"), "a")
	ensure.Err(t, flagenv.ParseSet(name, s),
		regexp.MustCompile(`failed to set flag "bar1" with value "a"`))
}
開發者ID:chrisp-fb,項目名稱:rell,代碼行數:9,代碼來源:flagenv_test.go

示例8: TestLoadFromBoxError

func TestLoadFromBoxError(t *testing.T) {
	const msg = "foo"
	h := Handler{
		Box: funcBox(func(name string) ([]byte, error) {
			return nil, errors.New(msg)
		}),
	}
	_, err := h.load("baz")
	ensure.Err(t, err, regexp.MustCompile(msg))
}
開發者ID:chrisp-fb,項目名稱:rell,代碼行數:10,代碼來源:static_test.go

示例9: TestCustomHTTPTransport

func TestCustomHTTPTransport(t *testing.T) {
	t.Parallel()
	const message = "hello world"
	c := &parse.Client{
		Transport: transportFunc(func(*http.Request) (*http.Response, error) {
			return nil, errors.New(message)
		}),
	}
	_, err := c.Do(&http.Request{}, nil, nil)
	ensure.Err(t, err, regexp.MustCompile(message))
}
開發者ID:chrisp-fb,項目名稱:rell,代碼行數:11,代碼來源:parse_test.go

示例10: TestCombinedURLBoxError

func TestCombinedURLBoxError(t *testing.T) {
	const msg = "foo"
	h := Handler{
		Box: funcBox(func(name string) ([]byte, error) {
			return nil, errors.New(msg)
		}),
	}
	v, err := h.URL("baz")
	ensure.DeepEqual(t, v, "")
	ensure.Err(t, err, regexp.MustCompile(msg))
}
開發者ID:chrisp-fb,項目名稱:rell,代碼行數:11,代碼來源:static_test.go

示例11: TestNilURLWithBaseURL

func TestNilURLWithBaseURL(t *testing.T) {
	t.Parallel()
	client := &fbapi.Client{
		BaseURL: &url.URL{
			Scheme: "https",
			Host:   "graph.facebook.com",
			Path:   "/20aa2519-4745-4522-92a9-4522b8edf6e9",
		},
	}
	res, err := client.Do(&http.Request{Method: "GET"}, nil)
	ensure.Err(t, err, regexp.MustCompile(`failed with code 803`))
	ensure.DeepEqual(t, res.StatusCode, 404)
}
開發者ID:chrisp-fb,項目名稱:rell,代碼行數:13,代碼來源:client_test.go

示例12: TestHTTPStopTimeoutMissed

func TestHTTPStopTimeoutMissed(t *testing.T) {
	t.Parallel()

	klock := clock.NewMock()

	const count = 10000
	hello := []byte("hello")
	finOkHandler := make(chan struct{})
	unblockOkHandler := make(chan struct{})
	okHandler := func(w http.ResponseWriter, r *http.Request) {
		defer close(finOkHandler)
		w.Header().Set("Content-Length", fmt.Sprint(len(hello)*count))
		w.WriteHeader(200)
		for i := 0; i < count/2; i++ {
			w.Write(hello)
		}
		<-unblockOkHandler
		for i := 0; i < count/2; i++ {
			w.Write(hello)
		}
	}

	listener, err := net.Listen("tcp", "127.0.0.1:0")
	ensure.Nil(t, err)
	server := &http.Server{Handler: http.HandlerFunc(okHandler)}
	transport := &http.Transport{}
	client := &http.Client{Transport: transport}
	down := &httpdown.HTTP{
		StopTimeout: time.Minute,
		Clock:       klock,
	}
	s := down.Serve(server, listener)
	res, err := client.Get(fmt.Sprintf("http://%s/", listener.Addr().String()))
	ensure.Nil(t, err)

	finStop := make(chan struct{})
	go func() {
		defer close(finStop)
		ensure.Nil(t, s.Stop())
	}()

	klock.Wait(clock.Calls{After: 1}) // wait for Stop to call After
	klock.Add(down.StopTimeout)

	_, err = ioutil.ReadAll(res.Body)
	ensure.Err(t, err, regexp.MustCompile("^unexpected EOF$"))
	ensure.Nil(t, res.Body.Close())
	close(unblockOkHandler)
	<-finOkHandler
	<-finStop
}
開發者ID:chrisp-fb,項目名稱:rell,代碼行數:51,代碼來源:httpdown_test.go

示例13: TestInvalidGet

func TestInvalidGet(t *testing.T) {
	t.Parallel()
	res, err := defaultFbClient.Do(
		&http.Request{
			Method: "GET",
			URL: &url.URL{
				Path: "20aa2519-4745-4522-92a9-4522b8edf6e9",
			},
		},
		nil,
	)
	ensure.Err(t, err, regexp.MustCompile(`failed with code 803`))
	ensure.DeepEqual(t, res.StatusCode, 404)
}
開發者ID:chrisp-fb,項目名稱:rell,代碼行數:14,代碼來源:client_test.go

示例14: TestHTTPSDefaultListenError

func TestHTTPSDefaultListenError(t *testing.T) {
	if os.Getuid() == 0 {
		t.Skip("cant run this test as root")
	}
	t.Parallel()

	cert, err := tls.X509KeyPair(localhostCert, localhostKey)
	if err != nil {
		t.Fatalf("error loading cert: %v", err)
	}

	down := &httpdown.HTTP{}
	_, err = down.ListenAndServe(&http.Server{
		TLSConfig: &tls.Config{
			NextProtos:   []string{"http/1.1"},
			Certificates: []tls.Certificate{cert},
		},
	})
	ensure.Err(t, err, regexp.MustCompile("listen tcp :443: bind: permission denied"))
}
開發者ID:chrisp-fb,項目名稱:rell,代碼行數:20,代碼來源:httpdown_test.go

示例15: TestHTTPDefaultListenError

func TestHTTPDefaultListenError(t *testing.T) {
	if os.Getuid() == 0 {
		t.Skip("cant run this test as root")
	}

	statsDone := make(chan struct{}, 1)
	hc := &stats.HookClient{
		BumpSumHook: func(key string, val float64) {
			if key == "listen.error" && val == 1 {
				statsDone <- struct{}{}
			}
		},
	}

	t.Parallel()
	down := &httpdown.HTTP{Stats: hc}
	_, err := down.ListenAndServe(&http.Server{})
	ensure.Err(t, err, regexp.MustCompile("listen tcp :80: bind: permission denied"))
	<-statsDone
}
開發者ID:chrisp-fb,項目名稱:rell,代碼行數:20,代碼來源:httpdown_test.go


注:本文中的github.com/daaku/rell/internal/github.com/facebookgo/ensure.Err函數示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。