本文整理汇总了Golang中github.com/daaku/rell/internal/github.com/facebookgo/ensure.DeepEqual函数的典型用法代码示例。如果您正苦于以下问题:Golang DeepEqual函数的具体用法?Golang DeepEqual怎么用?Golang DeepEqual使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了DeepEqual函数的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Golang代码示例。
示例1: TestMuxContextMakerError
func TestMuxContextMakerError(t *testing.T) {
givenErr := errors.New("")
var actualErr error
mux, err := ctxmux.New(
ctxmux.MuxContextMaker(func(r *http.Request) (context.Context, error) {
return nil, givenErr
}),
ctxmux.MuxErrorHandler(
func(ctx context.Context, w http.ResponseWriter, r *http.Request, err error) {
ensure.DeepEqual(t, ctx, context.Background())
actualErr = err
}),
)
ensure.Nil(t, err)
hw := httptest.NewRecorder()
hr := &http.Request{
Method: "GET",
URL: &url.URL{
Path: "/",
},
}
mux.GET(hr.URL.Path, func(context.Context, http.ResponseWriter, *http.Request) error {
panic("not reached")
})
mux.ServeHTTP(hw, hr)
ensure.DeepEqual(t, actualErr, givenErr)
}
开发者ID:chrisp-fb,项目名称:rell,代码行数:27,代码来源:ctxmux_test.go
示例2: TestServeCombinedURLWithExt
func TestServeCombinedURLWithExt(t *testing.T) {
contents := [][]byte{
[]byte("foo"),
[]byte("bar"),
}
var count int
h := Handler{
Path: "/",
Box: funcBox(func(name string) ([]byte, error) {
defer func() { count++ }()
return contents[count], nil
}),
}
v, err := h.URL("n1.js", "n2")
ensure.Nil(t, err)
ensure.DeepEqual(t, v, "/W1sibjEuanMiLCJhY2JkMThkYiJdLFsibjIiLCIzN2I1MWQxOSJdXQ.js")
w := httptest.NewRecorder()
r := &http.Request{
URL: &url.URL{
Path: v,
},
}
h.ServeHTTP(w, r)
ensure.DeepEqual(t, w.Code, http.StatusOK)
ensure.DeepEqual(t, w.Body.String(), "foobar")
ensure.DeepEqual(t, w.Header(), http.Header{
"Content-Length": []string{"6"},
"Cache-Control": []string{cacheControl},
"Content-Type": []string{"application/javascript"},
})
}
开发者ID:chrisp-fb,项目名称:rell,代码行数:31,代码来源:static_test.go
示例3: TestWrapExistingMultiStackError
func TestWrapExistingMultiStackError(t *testing.T) {
err := &multiStackError{
multiStack: new(stack.Multi),
}
we := Wrap(context.Background(), err)
ensure.DeepEqual(t, we, err)
ensure.DeepEqual(t, len(err.multiStack.Stacks()), 1)
}
开发者ID:chrisp-fb,项目名称:rell,代码行数:8,代码来源:ctxerr_test.go
示例4: TestWrapNewSingleFrame
func TestWrapNewSingleFrame(t *testing.T) {
err := errors.New("")
config := Config{StackMode: StackModeSingleFrame}
ctx := WithConfig(context.Background(), config)
we := Wrap(ctx, err).(*singleFrameError)
ensure.DeepEqual(t, we.config, config)
ensure.DeepEqual(t, we.underlying, err)
ensure.DeepEqual(t, we.frame.Name, "TestWrapNewSingleFrame")
}
开发者ID:chrisp-fb,项目名称:rell,代码行数:9,代码来源:ctxerr_test.go
示例5: TestWrapNewMultiStackError
func TestWrapNewMultiStackError(t *testing.T) {
err := errors.New("")
config := Config{StackMode: StackModeMultiStack}
ctx := WithConfig(context.Background(), config)
we := Wrap(ctx, err).(*multiStackError)
ensure.DeepEqual(t, we.config, config)
ensure.DeepEqual(t, we.underlying, err)
ensure.DeepEqual(t, we.multiStack.Stacks()[0][0].Name, "TestWrapNewMultiStackError")
}
开发者ID:chrisp-fb,项目名称:rell,代码行数:9,代码来源:ctxerr_test.go
示例6: TestSimple
func TestSimple(t *testing.T) {
t.Parallel()
var out bytes.Buffer
w := htmlwriter.New(&out)
const original = "hello & world"
n, err := w.Write([]byte(original))
ensure.Nil(t, err)
ensure.DeepEqual(t, n, 17)
ensure.DeepEqual(t, out.String(), html.EscapeString(original))
}
开发者ID:chrisp-fb,项目名称:rell,代码行数:10,代码来源:htmlwriter_test.go
示例7: TestPrefixClient
func TestPrefixClient(t *testing.T) {
const (
prefix1 = "prefix1"
prefix2 = "prefix2"
avgKey = "avg"
avgVal = float64(1)
sumKey = "sum"
sumVal = float64(2)
histogramKey = "histogram"
histogramVal = float64(3)
timeKey = "time"
)
var keys []string
hc := &stats.HookClient{
BumpAvgHook: func(key string, val float64) {
keys = append(keys, key)
ensure.DeepEqual(t, val, avgVal)
},
BumpSumHook: func(key string, val float64) {
keys = append(keys, key)
ensure.DeepEqual(t, val, sumVal)
},
BumpHistogramHook: func(key string, val float64) {
keys = append(keys, key)
ensure.DeepEqual(t, val, histogramVal)
},
BumpTimeHook: func(key string) interface {
End()
} {
return multiEnderTest{
EndHook: func() {
keys = append(keys, key)
},
}
},
}
pc := stats.PrefixClient([]string{prefix1, prefix2}, hc)
pc.BumpAvg(avgKey, avgVal)
pc.BumpSum(sumKey, sumVal)
pc.BumpHistogram(histogramKey, histogramVal)
pc.BumpTime(timeKey).End()
ensure.SameElements(t, keys, []string{
prefix1 + avgKey,
prefix1 + sumKey,
prefix1 + histogramKey,
prefix1 + timeKey,
prefix2 + avgKey,
prefix2 + sumKey,
prefix2 + histogramKey,
prefix2 + timeKey,
})
}
开发者ID:chrisp-fb,项目名称:rell,代码行数:55,代码来源:stats_test.go
示例8: TestRestAPIKeyModify
func TestRestAPIKeyModify(t *testing.T) {
t.Parallel()
var req http.Request
k := parse.RestAPIKey{
ApplicationID: defaultApplicationID,
RestAPIKey: "42",
}
ensure.Nil(t, k.Modify(&req))
ensure.DeepEqual(t, req.Header.Get("X-Parse-Application-ID"), k.ApplicationID)
ensure.DeepEqual(t, req.Header.Get("X-Parse-REST-API-Key"), k.RestAPIKey)
}
开发者ID:chrisp-fb,项目名称:rell,代码行数:11,代码来源:parse_test.go
示例9: TestHTTPHandlerFunc
func TestHTTPHandlerFunc(t *testing.T) {
w := httptest.NewRecorder()
r := &http.Request{}
var actualW http.ResponseWriter
var actualR *http.Request
h := ctxmux.HTTPHandlerFunc(func(w http.ResponseWriter, r *http.Request) {
actualW = w
actualR = r
})
ensure.Nil(t, h(nil, w, r))
ensure.DeepEqual(t, actualW, w)
ensure.DeepEqual(t, actualR, r)
}
开发者ID:chrisp-fb,项目名称:rell,代码行数:13,代码来源:ctxmux_test.go
示例10: TestSessionTokenModify
func TestSessionTokenModify(t *testing.T) {
t.Parallel()
st := parse.SessionToken{
ApplicationID: defaultApplicationID,
RestAPIKey: "42",
SessionToken: "43",
}
var req http.Request
ensure.Nil(t, st.Modify(&req))
ensure.DeepEqual(t, req.Header.Get("X-Parse-Application-ID"), st.ApplicationID)
ensure.DeepEqual(t, req.Header.Get("X-Parse-REST-API-Key"), st.RestAPIKey)
ensure.DeepEqual(t, req.Header.Get("X-Parse-Session-Token"), st.SessionToken)
}
开发者ID:chrisp-fb,项目名称:rell,代码行数:13,代码来源:parse_test.go
示例11: TestServeInvalidData
func TestServeInvalidData(t *testing.T) {
h := Handler{Path: "/"}
w := httptest.NewRecorder()
r := &http.Request{
URL: &url.URL{
Path: "/bar",
},
}
h.ServeHTTP(w, r)
ensure.DeepEqual(t, w.Code, http.StatusBadRequest)
ensureDisableCaching(t, w.Header())
ensure.DeepEqual(t, w.Body.String(), http.StatusText(http.StatusBadRequest))
}
开发者ID:chrisp-fb,项目名称:rell,代码行数:13,代码来源:static_test.go
示例12: TestAFewFlags
func TestAFewFlags(t *testing.T) {
const name = "TestAFewFlags"
s := flag.NewFlagSet(name, flag.PanicOnError)
const foo = "42"
const bar = int(43)
fooActual := s.String("foo", "", "")
barActual := s.Int("bar", 0, "")
os.Setenv(named(name, "foo"), foo)
os.Setenv(named(name, "bar"), fmt.Sprint(bar))
ensure.Nil(t, flagenv.ParseSet(name, s))
ensure.DeepEqual(t, *fooActual, foo)
ensure.DeepEqual(t, *barActual, bar)
}
开发者ID:chrisp-fb,项目名称:rell,代码行数:13,代码来源:flagenv_test.go
示例13: TestHTTPStopWithFinishedRequest
func TestHTTPStopWithFinishedRequest(t *testing.T) {
t.Parallel()
hello := []byte("hello")
fin := make(chan struct{})
okHandler := func(w http.ResponseWriter, r *http.Request) {
defer close(fin)
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{}
s := down.Serve(server, listener)
res, err := client.Get(fmt.Sprintf("http://%s/", listener.Addr().String()))
ensure.Nil(t, err)
actualBody, err := ioutil.ReadAll(res.Body)
ensure.Nil(t, err)
ensure.DeepEqual(t, actualBody, hello)
ensure.Nil(t, res.Body.Close())
// At this point the request is finished, and the connection should be alive
// but idle (because we have keep alive enabled by default in our Transport).
ensure.Nil(t, s.Stop())
<-fin
ensure.Nil(t, s.Wait())
}
开发者ID:chrisp-fb,项目名称:rell,代码行数:30,代码来源:httpdown_test.go
示例14: TestLoadFromBox
func TestLoadFromBox(t *testing.T) {
const magic = "foo"
h := Handler{
Box: funcBox(func(name string) ([]byte, error) {
ensure.DeepEqual(t, name, magic)
return []byte(magic), nil
}),
}
f, err := h.load(magic)
ensure.Nil(t, err)
ensure.DeepEqual(t, f, file{
Name: magic,
Content: []byte(magic),
Hash: "acbd18db",
})
}
开发者ID:chrisp-fb,项目名称:rell,代码行数:16,代码来源:static_test.go
示例15: TestMultiStackSingleStack
func TestMultiStackSingleStack(t *testing.T) {
frame := stack.Frame{Name: "42"}
s := stack.Stack{frame}
var multi stack.Multi
multi.Add(s)
ensure.DeepEqual(t, MultiStack(&singleStackError{stack: s}), &multi)
}
开发者ID:chrisp-fb,项目名称:rell,代码行数:7,代码来源:ctxerr_test.go
示例16: TestStackMultiStack
func TestStackMultiStack(t *testing.T) {
frame := stack.Frame{Name: "42"}
s := stack.Stack{frame}
var multi stack.Multi
multi.Add(s)
ensure.DeepEqual(t, Stack(&multiStackError{multiStack: &multi}), s)
}
开发者ID:chrisp-fb,项目名称:rell,代码行数:7,代码来源:ctxerr_test.go
示例17: TestCustomAppID
func TestCustomAppID(t *testing.T) {
t.Parallel()
values := url.Values{}
values.Add("appid", "123")
_, ctx := fromValues(t, values)
ensure.DeepEqual(t, rellenv.FbApp(ctx).ID(), uint64(123))
}
开发者ID:chrisp-fb,项目名称:rell,代码行数:7,代码来源:context_test.go
示例18: TestExistingConnState
func TestExistingConnState(t *testing.T) {
t.Parallel()
hello := []byte("hello")
fin := make(chan struct{})
okHandler := func(w http.ResponseWriter, r *http.Request) {
defer close(fin)
w.Write(hello)
}
var called int32
listener, err := net.Listen("tcp", "127.0.0.1:0")
ensure.Nil(t, err)
server := &http.Server{
Handler: http.HandlerFunc(okHandler),
ConnState: func(c net.Conn, s http.ConnState) {
atomic.AddInt32(&called, 1)
},
}
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)
actualBody, err := ioutil.ReadAll(res.Body)
ensure.Nil(t, err)
ensure.DeepEqual(t, actualBody, hello)
ensure.Nil(t, res.Body.Close())
ensure.Nil(t, s.Stop())
<-fin
ensure.True(t, atomic.LoadInt32(&called) > 0)
}
开发者ID:chrisp-fb,项目名称:rell,代码行数:34,代码来源:httpdown_test.go
示例19: TestHTTPWithinStopTimeout
func TestHTTPWithinStopTimeout(t *testing.T) {
t.Parallel()
hello := []byte("hello")
finOkHandler := make(chan struct{})
okHandler := func(w http.ResponseWriter, r *http.Request) {
defer close(finOkHandler)
w.WriteHeader(200)
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}
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())
}()
actualBody, err := ioutil.ReadAll(res.Body)
ensure.Nil(t, err)
ensure.DeepEqual(t, actualBody, hello)
ensure.Nil(t, res.Body.Close())
<-finOkHandler
<-finStop
}
开发者ID:chrisp-fb,项目名称:rell,代码行数:33,代码来源:httpdown_test.go
示例20: TestDecodeMultiple
func TestDecodeMultiple(t *testing.T) {
value, err := decode("W1siZm9vMSIsImJhcjEiXSxbImZvbzIiLCJiYXIyIl1d")
ensure.Nil(t, err)
ensure.DeepEqual(t, value, []file{
{Name: "foo1", Hash: "bar1"},
{Name: "foo2", Hash: "bar2"},
})
}
开发者ID:chrisp-fb,项目名称:rell,代码行数:8,代码来源:static_test.go
注:本文中的github.com/daaku/rell/internal/github.com/facebookgo/ensure.DeepEqual函数示例整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论