本文整理汇总了Golang中github.com/daaku/rell/internal/github.com/facebookgo/ensure.Err函数的典型用法代码示例。如果您正苦于以下问题:Golang Err函数的具体用法?Golang Err怎么用?Golang Err使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了Err函数的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的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
示例16: TestExtras
func TestExtras(t *testing.T) {
var c capture
e := errors.New("foo")
ensure.Err(
&c,
e,
nil,
map[string]int{"answer": 42},
"baz",
43,
44.45,
typ{Answer: 46},
)
c.Equal(t, `ensure_test.go:51: unexpected error: foo
(map[string]int) (len=1) {
(string) (len=6) "answer": (int) 42
}
(string) (len=3) "baz"
(int) 43
(float64) 44.45
(ensure_test.typ) {
Answer: (int) 46
}`)
}
开发者ID:chrisp-fb,项目名称:rell,代码行数:24,代码来源:ensure_test.go
示例17: TestHTMLResponse
func TestHTMLResponse(t *testing.T) {
t.Parallel()
server := httptest.NewServer(
http.HandlerFunc(
func(w http.ResponseWriter, r *http.Request) {
w.WriteHeader(500)
w.Write([]byte("<html></html>"))
},
),
)
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.Err(t, err, regexp.MustCompile(`got 500 Internal Server Error`))
server.CloseClientConnections()
server.Close()
}
开发者ID:chrisp-fb,项目名称:rell,代码行数:24,代码来源:client_test.go
示例18: TestRestAPIKeyEmptyApplicationID
func TestRestAPIKeyEmptyApplicationID(t *testing.T) {
t.Parallel()
var mk parse.RestAPIKey
ensure.Err(t, mk.Modify(nil), regexp.MustCompile("empty ApplicationID"))
}
开发者ID:chrisp-fb,项目名称:rell,代码行数:5,代码来源:parse_test.go
示例19: TestMatchingError
func TestMatchingError(t *testing.T) {
var c capture
e := errors.New("foo")
ensure.Err(&c, e, regexp.MustCompile("bar"))
c.Equal(t, "ensure_test.go:22: expected error: \"bar\" but got \"foo\"")
}
开发者ID:chrisp-fb,项目名称:rell,代码行数:6,代码来源:ensure_test.go
示例20: TestExpectedNilErr
func TestExpectedNilErr(t *testing.T) {
var c capture
ensure.Err(&c, nil, nil)
c.Equal(t, "")
}
开发者ID:chrisp-fb,项目名称:rell,代码行数:5,代码来源:ensure_test.go
注:本文中的github.com/daaku/rell/internal/github.com/facebookgo/ensure.Err函数示例整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论