本文整理匯總了Golang中github.com/eris-ltd/eris-db/Godeps/_workspace/src/github.com/stretchr/testify/assert.NoError函數的典型用法代碼示例。如果您正苦於以下問題:Golang NoError函數的具體用法?Golang NoError怎麽用?Golang NoError使用的例子?那麽, 這裏精選的函數代碼示例或許可以為您提供幫助。
在下文中一共展示了NoError函數的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Golang代碼示例。
示例1: TestWsFlooding
// Testing to ensure that websocket server does not crash, and that it
// cleans up after itself.
func TestWsFlooding(t *testing.T) {
// New websocket server.
wsServer := NewScumsocketServer(CONNS)
// Keep track of sessions.
sc := &SessionCounter{}
// Register the observer.
oChan := wsServer.SessionManager().SessionOpenEventChannel()
cChan := wsServer.SessionManager().SessionCloseEventChannel()
sc.Run(oChan, cChan)
serveProcess := NewServeScumSocket(wsServer)
errServe := serveProcess.Start()
assert.NoError(t, errServe, "ScumSocketed!")
t.Logf("Flooding...")
// Run. Blocks.
errRun := runWs()
stopC := serveProcess.StopEventChannel()
errStop := serveProcess.Stop(0)
<-stopC
assert.NoError(t, errRun, "ScumSocketed!")
assert.NoError(t, errStop, "ScumSocketed!")
o, c, a := sc.Report()
assert.Equal(t, o, CONNS, "Server registered '%d' opened conns out of '%d'", o, CONNS)
assert.Equal(t, c, CONNS, "Server registered '%d' closed conns out of '%d'", c, CONNS)
assert.Equal(t, a, 0, "Server registered '%d' conns still active after shutting down.", a)
}
示例2: TestHttpFlooding
// Send a burst of GET messages to the server.
func TestHttpFlooding(t *testing.T) {
serveProcess := NewServeScumbag()
errSS := serveProcess.Start()
assert.NoError(t, errSS, "Scumbag-ed!")
t.Logf("Flooding http requests.")
for i := 0; i < 3; i++ {
err := runHttp()
assert.NoError(t, err)
time.Sleep(200 * time.Millisecond)
}
stopC := serveProcess.StopEventChannel()
errStop := serveProcess.Stop(0)
<-stopC
assert.NoError(t, errStop, "Scumbag-ed!")
}
示例3: assertFilter
func assertFilter(t *testing.T, filter, field, op, val string) {
arr, err := _parseSearchQuery(filter)
assert.NoError(t, err)
assert.NotNil(t, arr)
assert.Len(t, arr, 1)
assert.Equal(t, arr[0], &ep.FilterData{field, op, val})
}
示例4: TestUnixSocket
func TestUnixSocket(t *testing.T) {
buffer := new(bytes.Buffer)
router := New()
go func() {
router.Use(LoggerWithWriter(buffer))
router.GET("/example", func(c *Context) { c.String(http.StatusOK, "it worked") })
router.RunUnix("/tmp/unix_unit_test")
}()
// have to wait for the goroutine to start and run the server
// otherwise the main thread will complete
time.Sleep(5 * time.Millisecond)
c, err := net.Dial("unix", "/tmp/unix_unit_test")
assert.NoError(t, err)
fmt.Fprintf(c, "GET /example HTTP/1.0\r\n\r\n")
scanner := bufio.NewScanner(c)
var response string
for scanner.Scan() {
response += scanner.Text()
}
assert.Contains(t, response, "HTTP/1.0 200", "should get a 200")
assert.Contains(t, response, "it worked", "resp body should match")
}
示例5: assertRangeFilter
func assertRangeFilter(t *testing.T, min, max, res0, res1 string) {
arr, err := _parseSearchQuery("test:" + min + ".." + max)
assert.NoError(t, err)
assert.NotNil(t, arr)
assert.Len(t, arr, 2)
assert.Equal(t, arr[0], &ep.FilterData{"test", ">=", res0})
assert.Equal(t, arr[1], &ep.FilterData{"test", "<=", res1})
}
示例6: TestEncodeOnlyData
func TestEncodeOnlyData(t *testing.T) {
w := new(bytes.Buffer)
err := Encode(w, Event{
Data: "junk\n\njk\nid:fake",
})
assert.NoError(t, err)
assert.Equal(t, w.String(), "data: junk\\n\\njk\\nid:fake\n\n")
}
示例7: TestEncodeWithRetry
func TestEncodeWithRetry(t *testing.T) {
w := new(bytes.Buffer)
err := Encode(w, Event{
Retry: 11,
Data: "junk\n\njk\nid:fake\n",
})
assert.NoError(t, err)
assert.Equal(t, w.String(), "retry: 11\ndata: junk\\n\\njk\\nid:fake\\n\n\n")
}
示例8: TestEncodeWithId
func TestEncodeWithId(t *testing.T) {
w := new(bytes.Buffer)
err := Encode(w, Event{
Id: "t\n:<>\r\test",
Data: "junk\n\njk\nid:fa\rke",
})
assert.NoError(t, err)
assert.Equal(t, w.String(), "id: t\\n:<>\\r\test\ndata: junk\\n\\njk\\nid:fa\\rke\n\n")
}
示例9: TestEncodeSlice
func TestEncodeSlice(t *testing.T) {
w := new(bytes.Buffer)
err := Encode(w, Event{
Event: "a slice",
Data: []interface{}{1, "text", map[string]interface{}{"foo": "bar"}},
})
assert.NoError(t, err)
assert.Equal(t, w.String(), "event: a slice\ndata: [1,\"text\",{\"foo\":\"bar\"}]\n\n")
}
示例10: TestEncodeFloat
func TestEncodeFloat(t *testing.T) {
w := new(bytes.Buffer)
err := Encode(w, Event{
Event: "Float",
Data: 1.5,
})
assert.NoError(t, err)
assert.Equal(t, w.String(), "event: Float\ndata: 1.5\n\n")
}
示例11: TestEncodeInteger
func TestEncodeInteger(t *testing.T) {
w := new(bytes.Buffer)
err := Encode(w, Event{
Event: "an integer",
Data: 1,
})
assert.NoError(t, err)
assert.Equal(t, w.String(), "event: an integer\ndata: 1\n\n")
}
示例12: TestValidationDisabled
func TestValidationDisabled(t *testing.T) {
backup := Validator
Validator = nil
defer func() { Validator = backup }()
var obj FooStruct
req := requestWithBody("POST", "/", `{"bar": "foo"}`)
err := JSON.Bind(req, &obj)
assert.NoError(t, err)
}
示例13: TestEncodeWithEverything
func TestEncodeWithEverything(t *testing.T) {
w := new(bytes.Buffer)
err := Encode(w, Event{
Event: "abc",
Id: "12345",
Retry: 10,
Data: "some data",
})
assert.NoError(t, err)
assert.Equal(t, w.String(), "id: 12345\nevent: abc\nretry: 10\ndata: some data\n\n")
}
示例14: TestResponseWriterWrite
func TestResponseWriterWrite(t *testing.T) {
testWritter := httptest.NewRecorder()
writer := &responseWriter{}
writer.reset(testWritter)
w := ResponseWriter(writer)
n, err := w.Write([]byte("hola"))
assert.Equal(t, n, 4)
assert.Equal(t, w.Size(), 4)
assert.Equal(t, w.Status(), 200)
assert.Equal(t, testWritter.Code, 200)
assert.Equal(t, testWritter.Body.String(), "hola")
assert.NoError(t, err)
n, err = w.Write([]byte(" adios"))
assert.Equal(t, n, 6)
assert.Equal(t, w.Size(), 10)
assert.Equal(t, testWritter.Body.String(), "hola adios")
assert.NoError(t, err)
}
示例15: TestRenderJSON
func TestRenderJSON(t *testing.T) {
w := httptest.NewRecorder()
data := map[string]interface{}{
"foo": "bar",
}
err := (JSON{data}).Render(w)
assert.NoError(t, err)
assert.Equal(t, w.Body.String(), "{\"foo\":\"bar\"}\n")
assert.Equal(t, w.Header().Get("Content-Type"), "application/json; charset=utf-8")
}