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

Function TestCreate

client/driver_test.go:119–171  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

117}
118
119func TestCreate(t *testing.T) {
120 Convey("test create", t, func() {
121 var stopTestService func()
122 var err error
123 var dsn string
124
125 _, dsn, err = Create(ResourceMeta{})
126 So(err, ShouldEqual, ErrNotInitialized)
127
128 // fake driver initialized
129 atomic.StoreUint32(&driverInitialized, 1)
130 _, dsn, err = Create(ResourceMeta{})
131 So(err, ShouldNotBeNil)
132 // reset driver not initialized
133 atomic.StoreUint32(&driverInitialized, 0)
134
135 stopTestService, _, err = startTestService()
136 So(err, ShouldBeNil)
137 defer stopTestService()
138 _, dsn, err = Create(ResourceMeta{})
139 So(err, ShouldBeNil)
140 dsnCfg, err := ParseDSN(dsn)
141 So(err, ShouldBeNil)
142
143 waitCtx, cancelWait := context.WithTimeout(context.Background(), time.Nanosecond)
144 defer cancelWait()
145 // should not use client.WaitDBCreation, sql.Open is not supported in this test case
146 err = WaitBPDatabaseCreation(waitCtx, proto.DatabaseID(dsnCfg.DatabaseID), nil, 3*time.Second)
147 So(err, ShouldResemble, context.DeadlineExceeded)
148
149 // Calculate database ID
150 var priv *asymmetric.PrivateKey
151 priv, err = kms.GetLocalPrivateKey()
152 So(err, ShouldBeNil)
153 var addr proto.AccountAddress
154 addr, err = crypto.PubKeyHash(priv.PubKey())
155 So(err, ShouldBeNil)
156 var dbID = string(proto.FromAccountAndNonce(addr, uint32(stubNextNonce)))
157
158 recoveredCfg, err := ParseDSN(dsn)
159 So(err, ShouldBeNil)
160 So(recoveredCfg, ShouldResemble, &Config{
161 DatabaseID: dbID,
162 UseLeader: true,
163 })
164
165 waitCtx2, cancelWait2 := context.WithTimeout(context.Background(), 5*time.Minute)
166 defer cancelWait2()
167 // should not use client.WaitDBCreation, sql.Open is not supported in this test case
168 err = WaitBPDatabaseCreation(waitCtx2, proto.DatabaseID(dsnCfg.DatabaseID), nil, 3*time.Second)
169 So(err, ShouldBeNil)
170 })
171}
172
173func TestDrop(t *testing.T) {
174 Convey("test drop", t, func() {

Callers

nothing calls this directly

Calls 9

PubKeyMethod · 0.95
DatabaseIDTypeAlias · 0.92
GetLocalPrivateKeyFunction · 0.92
PubKeyHashFunction · 0.92
FromAccountAndNonceFunction · 0.92
startTestServiceFunction · 0.85
ParseDSNFunction · 0.85
WaitBPDatabaseCreationFunction · 0.85
CreateFunction · 0.70

Tested by

no test coverage detected