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

Function TestConn

client/conn_test.go:30–169  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

28)
29
30func TestConn(t *testing.T) {
31 log.SetLevel(log.DebugLevel)
32 Convey("test connection", t, func() {
33 var (
34 stopTestService func()
35 ok bool
36 err error
37 )
38 stopTestService, _, err = startTestService()
39 So(err, ShouldBeNil)
40 defer stopTestService()
41
42 var db *sql.DB
43 db, err = sql.Open("covenantsql", "covenantsql://db?update_interval=400ms")
44 So(db, ShouldNotBeNil)
45 So(err, ShouldBeNil)
46
47 ctx := WithReceipt(context.Background())
48 rec, ok := GetReceipt(ctx)
49 So(ok, ShouldBeFalse)
50 So(rec, ShouldBeNil)
51
52 _, err = db.ExecContext(ctx, "create table test (test int)")
53 So(err, ShouldBeNil)
54 rec, ok = GetReceipt(ctx)
55 So(ok, ShouldBeTrue)
56 So(rec, ShouldNotBeNil)
57
58 _, err = db.ExecContext(ctx, "insert into test values (1)")
59 So(err, ShouldBeNil)
60 rec2, ok := GetReceipt(ctx)
61 So(ok, ShouldBeTrue)
62 So(rec2, ShouldNotBeNil)
63 So(rec, ShouldNotEqual, rec2) // receipt should be reset
64
65 // test with query
66 var rows *sql.Rows
67 var result int
68 rows, err = db.QueryContext(ctx, "select * from test")
69 So(err, ShouldBeNil)
70 So(rows, ShouldNotBeNil)
71 So(rows.Next(), ShouldBeTrue)
72 rec, ok = GetReceipt(ctx)
73 So(ok, ShouldBeTrue)
74 So(rec, ShouldNotBeNil)
75
76 err = rows.Scan(&result)
77 So(err, ShouldBeNil)
78 So(result, ShouldEqual, 1)
79 So(rows.Next(), ShouldBeFalse)
80 rows.Close()
81
82 testRowCount := func(expected int) {
83 var row *sql.Row
84 var err error
85 var result int
86 row = db.QueryRow("select count(1) as cnt from test")
87 So(row, ShouldNotBeNil)

Callers

nothing calls this directly

Calls 15

SetLevelFunction · 0.92
startTestServiceFunction · 0.85
WithReceiptFunction · 0.85
GetReceiptFunction · 0.85
QueryRowMethod · 0.80
NameMethod · 0.80
ExecContextMethod · 0.65
QueryContextMethod · 0.65
CloseMethod · 0.65
ExecMethod · 0.65
QueryMethod · 0.65
OpenMethod · 0.45

Tested by

no test coverage detected