本文整理匯總了Golang中github.com/funny/unitest.NotError函數的典型用法代碼示例。如果您正苦於以下問題:Golang NotError函數的具體用法?Golang NotError怎麽用?Golang NotError使用的例子?那麽, 這裏精選的函數代碼示例或許可以為您提供幫助。
在下文中一共展示了NotError函數的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Golang代碼示例。
示例1: SessionTest
func SessionTest(t *testing.T, protocol ClientProtocol, codec CodecType, test func(*testing.T, *Session)) {
server, err := Serve("tcp://0.0.0.0:0", Stream(), nil)
unitest.NotError(t, err)
addr := server.listener.Addr().String()
serverWait := new(sync.WaitGroup)
go server.Loop(func(session *Session) {
serverWait.Add(1)
Echo(session)
serverWait.Done()
})
clientWait := new(sync.WaitGroup)
for i := 0; i < 60; i++ {
clientWait.Add(1)
go func() {
session, err := Connect("tcp://"+addr, protocol, codec)
unitest.NotError(t, err)
test(t, session)
session.Close()
clientWait.Done()
}()
}
clientWait.Wait()
server.Stop()
serverWait.Wait()
MakeSureSessionGoroutineExit(t)
}
示例2: Test_Execute
func Test_Execute(t *testing.T) {
param := TestConnParam
param.DbName = "mysql"
conn, err := Connect(param)
unitest.NotError(t, err)
defer conn.Close()
_, err = conn.Execute("CREATE DATABASE " + TestConnParam.DbName)
unitest.NotError(t, err)
_, err = conn.Execute("USE " + TestConnParam.DbName)
unitest.NotError(t, err)
_, err = conn.Execute(`CREATE TABLE test (
id INT PRIMARY KEY,
value VARCHAR(10)
)`)
unitest.NotError(t, err)
for i := 0; i < 10; i++ {
res, err := conn.Execute("INSERT INTO test VALUES(" + strconv.Itoa(i) + ",'" + strconv.Itoa(i) + "')")
unitest.NotError(t, err)
unitest.Pass(t, res.RowsAffected() == 1)
}
}
示例3: Test_Simple
func Test_Simple(t *testing.T) {
backend, err := StartEchoBackend()
unitest.NotError(t, err)
gateway := StartTestGateway(t, backend.Listener().Addr().String())
gatewayAddr := gateway.server.Listener().Addr().String()
client, err := link.Connect("tcp://"+gatewayAddr, link.Packet(link.Uint16BE), link.Bytes())
unitest.NotError(t, err)
for i := 0; i < 10000; i++ {
msg1 := RandBytes(1024)
err1 := client.Send(msg1)
unitest.NotError(t, err1)
var msg2 []byte
err2 := client.Receive(&msg2)
unitest.NotError(t, err2)
if bytes.Equal(msg1, msg2) == false {
t.Log(i, msg1, msg2)
t.Fail()
}
unitest.Pass(t, bytes.Equal(msg1, msg2))
}
client.Close()
gateway.Stop()
backend.Stop()
time.Sleep(time.Second * 2)
MakeSureSessionGoroutineExit(t)
}
示例4: StreamTest
func StreamTest(t *testing.T, callback func(*link.Session)) {
protocol := New(1024, 1024, 1024)
server, err := link.Serve("tcp", "0.0.0.0:0", protocol)
unitest.NotError(t, err)
addr := server.Listener().Addr().String()
go server.Serve(func(session *link.Session) {
for {
var msg TestMessage
if err := session.Receive(&msg); err != nil {
break
}
if err := session.Send(msg); err != nil {
break
}
}
})
session, err := link.Connect("tcp", addr, protocol)
unitest.NotError(t, err)
callback(session)
session.Close()
server.Stop()
MakeSureSessionGoroutineExit(t)
}
示例5: PacketTest
func PacketTest(t *testing.T, callback func(*link.Session)) {
protocol := New(binary.SplitByUvarint, 1024, 1024, 1024)
server, err := link.Serve("tcp", "0.0.0.0:0", protocol)
unitest.NotError(t, err)
go server.Serve(func(session *link.Session) {
for {
var msg RAW
if err := session.Receive(&msg); err != nil {
break
}
if err := session.Send(msg); err != nil {
break
}
}
})
session, err := link.Connect("tcp", server.Listener().Addr().String(), protocol)
unitest.NotError(t, err)
callback(session)
session.Close()
server.Stop()
MakeSureSessionGoroutineExit(t)
}
示例6: Test_Execute
func Test_Execute(t *testing.T) {
param := TestConnEnv
param.DbName = "mysql"
name, _ := json.Marshal(param)
conn, err := sql.Open("mysql", string(name))
unitest.NotError(t, err)
defer conn.Close()
_, err = conn.Exec("CREATE DATABASE " + TestConnEnv.DbName)
unitest.NotError(t, err)
_, err = conn.Exec("USE " + TestConnEnv.DbName)
unitest.NotError(t, err)
_, err = conn.Exec(`CREATE TABLE test (
id INT PRIMARY KEY,
value VARCHAR(10)
)`)
unitest.NotError(t, err)
for i := 0; i < 10; i++ {
res, err := conn.Exec("INSERT INTO test VALUES(" + strconv.Itoa(i) + ",'" + strconv.Itoa(i) + "')")
unitest.NotError(t, err)
num, _ := res.RowsAffected()
unitest.Pass(t, num == 1)
}
}
示例7: Test_QueryReader
func Test_QueryReader(t *testing.T) {
conn, err := Connect(TestConnParam)
unitest.NotError(t, err)
defer conn.Close()
var res DataReader
res, err = conn.QueryReader("SELECT * FROM test ORDER BY id ASC")
unitest.NotError(t, err)
defer res.Close()
i := 0
for {
row, err1 := res.FetchNext()
unitest.NotError(t, err1)
if row == nil {
break
}
unitest.Pass(t, row[0].Int64() == int64(i))
unitest.Pass(t, row[1].String() == strconv.Itoa(i))
i++
}
unitest.Pass(t, i == 10)
}
示例8: Test_Connect
func Test_Connect(t *testing.T) {
conn, err := sql.Open("mysql", TestConnParam)
unitest.NotError(t, err)
err = conn.Close()
unitest.NotError(t, err)
}
示例9: Test_Query
func Test_Query(t *testing.T) {
conn, err := sql.Open("mysql", TestConnParam)
unitest.NotError(t, err)
defer conn.Close()
var res *sql.Rows
res, err = conn.Query("SELECT * FROM test ORDER BY id ASC")
unitest.NotError(t, err)
defer res.Close()
i := 0
for res.Next() {
var (
id int64
value string
)
err := res.Scan(&id, &value)
unitest.NotError(t, err)
unitest.Pass(t, id == int64(i))
unitest.Pass(t, value == strconv.Itoa(i))
i++
}
unitest.Pass(t, i == 10)
}
示例10: Test_Clean
func Test_Clean(t *testing.T) {
conn, err := sql.Open("mysql", TestConnParam)
unitest.NotError(t, err)
defer conn.Close()
_, err = conn.Exec("DROP DATABASE " + TestConnEnv.DbName)
unitest.NotError(t, err)
}
示例11: Test_Clean
func Test_Clean(t *testing.T) {
conn, err := Connect(TestConnParam)
unitest.NotError(t, err)
defer conn.Close()
_, err = conn.Execute("DROP DATABASE " + TestConnParam.DbName)
unitest.NotError(t, err)
}
示例12: Test_Uint32BE
func Test_Uint32BE(t *testing.T) {
ReadWriteTest(t, 10000, func(r *Reader, w *Writer) {
v1 := uint32(rand.Intn(0xFFFFFFFF))
w.WriteUint32BE(v1)
w.Flush()
unitest.NotError(t, w.Error())
v2 := r.ReadUint32BE()
unitest.NotError(t, r.Error())
unitest.Pass(t, v1 == v2)
})
}
示例13: Test_Float64LE
func Test_Float64LE(t *testing.T) {
ReadWriteTest(t, 10000, func(r *Reader, w *Writer) {
v1 := rand.NormFloat64()
w.WriteFloat64LE(v1)
w.Flush()
unitest.NotError(t, w.Error())
v2 := r.ReadFloat64LE()
unitest.NotError(t, r.Error())
unitest.Pass(t, v1 == v2)
})
}
示例14: Test_Varint
func Test_Varint(t *testing.T) {
ReadWriteTest(t, 10000, func(r *Reader, w *Writer) {
v1 := int64(rand.Int63n(0x7FFFFFFFFFFFFFFF))
w.WriteVarint(v1)
w.Flush()
unitest.NotError(t, w.Error())
v2 := r.ReadVarint()
unitest.NotError(t, r.Error())
unitest.Pass(t, v1 == v2)
})
}
示例15: StringTest
func StringTest(t *testing.T, session *Session) {
for i := 0; i < 2000; i++ {
msg1 := string(RandBytes(512))
err := session.Send(msg1)
unitest.NotError(t, err)
var msg2 string
err = session.Receive(&msg2)
unitest.NotError(t, err)
unitest.Pass(t, msg1 == msg2)
}
}