本文整理汇总了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"))
}
示例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"))
}
示例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"`))
}
示例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"`))
}
示例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
}
示例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`))
}
示例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"`))
}
示例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))
}
示例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))
}
示例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))
}
示例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)
}
示例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
}
示例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)
}
示例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"))
}
示例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
}