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

Function TestAcceptFunc

rpc/accept_test.go:29–103  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

27)
28
29func TestAcceptFunc(t *testing.T) {
30 Convey("Setup a single server with raw conn accept func", t, func(c C) {
31 nodes, stop, err := setupEnvironment(1, AcceptRawConn)
32 So(err, ShouldBeNil)
33 defer stop()
34
35 conn, err := net.Dial("tcp", nodes[0].Addr)
36 So(err, ShouldBeNil)
37 cli := NewClient(conn)
38 defer func() { _ = cli.Close() }()
39 err = cli.Call("Count.Add", &AddReq{Delta: 1}, &AddResp{})
40 So(err, ShouldBeNil)
41 })
42 Convey("Setup a single server with crypto conn accept func", t, func(c C) {
43 secret := `6?$X7$<OmTFR{<!O}`
44 f := func(conn net.Conn) (*etls.CryptoConn, error) {
45 return etls.NewConn(conn, etls.NewCipher([]byte(secret))), nil
46 }
47
48 nodes, stop, err := setupEnvironment(1, NewAcceptCryptoConnFunc(f))
49 So(err, ShouldBeNil)
50 defer stop()
51
52 conn, err := etls.Dial("tcp", nodes[0].Addr, etls.NewCipher([]byte(secret)))
53 So(err, ShouldBeNil)
54 cli := NewClient(conn)
55 defer func() { _ = cli.Close() }()
56 err = cli.Call("Count.Add", &AddReq{Delta: 1}, &AddResp{})
57 So(err, ShouldBeNil)
58
59 // Call crypto server with raw TCP conn
60 rawconn, err := net.Dial("tcp", nodes[0].Addr)
61 So(err, ShouldBeNil)
62 rawcli := NewClient(rawconn)
63 defer func() { _ = rawcli.Close() }()
64 err = NewClient(rawconn).Call("Count.Add", &AddReq{Delta: 1}, &AddResp{})
65 So(err, ShouldNotBeNil)
66 })
67 Convey("Setup a single server with bad crypto conn accept func", t, func(c C) {
68 f := func(net.Conn) (*etls.CryptoConn, error) {
69 return nil, errors.New("won't accept")
70 }
71
72 nodes, stop, err := setupEnvironment(1, NewAcceptCryptoConnFunc(f))
73 So(err, ShouldBeNil)
74 defer stop()
75
76 conn, err := etls.Dial("tcp", nodes[0].Addr, etls.NewCipher([]byte{}))
77 So(err, ShouldBeNil)
78 cli := NewClient(conn)
79 defer func() { _ = cli.Close() }()
80 err = cli.Call("Count.Add", &AddReq{Delta: 1}, &AddResp{})
81 So(err, ShouldNotBeNil)
82 })
83 Convey("Setup a single server with naconn accept func", t, func(c C) {
84 nodes, stop, err := setupEnvironment(1, AcceptNAConn)
85 So(err, ShouldBeNil)
86 defer stop()

Callers

nothing calls this directly

Calls 10

CloseMethod · 0.95
CallMethod · 0.95
NewConnFunction · 0.92
NewCipherFunction · 0.92
DialFunction · 0.92
setupEnvironmentFunction · 0.85
NewClientFunction · 0.85
NewAcceptCryptoConnFuncFunction · 0.85
NewMethod · 0.65
DialFunction · 0.50

Tested by

no test coverage detected