MCPcopy Index your code
hub / github.com/CovenantSQL/CovenantSQL / TestCryptoConn_RW

Function TestCryptoConn_RW

crypto/etls/conn_test.go:272–308  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

270}
271
272func TestCryptoConn_RW(t *testing.T) {
273 cipher := NewCipher([]byte(pass))
274 var nilCipherHandler CipherHandler = func(conn net.Conn) (cryptoConn *CryptoConn, err error) {
275 cryptoConn = NewConn(conn, cipher)
276 return
277 }
278
279 Convey("server client OK", t, func(c C) {
280 msg := "xxxxxxxxxxxxxxxx"
281 l, _ := NewCryptoListener("tcp", "127.0.0.1:0", nilCipherHandler)
282 wg := sync.WaitGroup{}
283 wg.Add(1)
284 go func() {
285 rBuf := make([]byte, len(msg))
286 conn, err := l.Accept()
287
288 if c, ok := conn.(*CryptoConn); ok {
289 conn, err = l.CHandler(c.Conn)
290 if err != nil {
291 err = errors.Wrap(err, "handle ETLS handler failed")
292 return
293 }
294 }
295
296 n, err := conn.Read(rBuf)
297 c.So(n, ShouldEqual, len(msg))
298 c.So(string(rBuf), ShouldResemble, msg)
299 c.So(err, ShouldBeNil)
300 wg.Done()
301 }()
302 conn, _ := Dial("tcp", l.Addr().String(), cipher)
303 n, err := conn.Write([]byte(msg))
304 So(n, ShouldEqual, len(msg))
305 So(err, ShouldBeNil)
306 wg.Wait()
307 })
308}
309
310func TestDialTimeout(t *testing.T) {
311 Convey("Test dial timeout", t, func(c C) {

Callers

nothing calls this directly

Calls 11

AcceptMethod · 0.95
AddrMethod · 0.95
NewCipherFunction · 0.85
NewConnFunction · 0.85
NewCryptoListenerFunction · 0.85
WaitMethod · 0.80
DialFunction · 0.70
ReadMethod · 0.65
WriteMethod · 0.65
AddMethod · 0.45
StringMethod · 0.45

Tested by

no test coverage detected