MCPcopy Index your code
hub / github.com/dnote/dnote / TestRun_fresh

Function TestRun_fresh

pkg/cli/migrate/migrate_test.go:175–244  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

173}
174
175func TestRun_fresh(t *testing.T) {
176 testCases := []struct {
177 mode int
178 schemaKey string
179 }{
180 {
181 mode: LocalMode,
182 schemaKey: consts.SystemSchema,
183 },
184 {
185 mode: RemoteMode,
186 schemaKey: consts.SystemRemoteSchema,
187 },
188 }
189
190 for _, tc := range testCases {
191 func() {
192 // set up
193 db := initTestDBNoMigration(t)
194 ctx := context.InitTestCtxWithDB(t, db)
195
196 database.MustExec(t, "creating a temporary table for testing", db,
197 "CREATE TABLE migrate_run_test ( name string )")
198
199 sequence := []migration{
200 {
201 name: "v1",
202 run: func(ctx context.DnoteCtx, db *database.DB) error {
203 database.MustExec(t, "marking v1 completed", db, "INSERT INTO migrate_run_test (name) VALUES (?)", "v1")
204 return nil
205 },
206 },
207 {
208 name: "v2",
209 run: func(ctx context.DnoteCtx, db *database.DB) error {
210 database.MustExec(t, "marking v2 completed", db, "INSERT INTO migrate_run_test (name) VALUES (?)", "v2")
211 return nil
212 },
213 },
214 {
215 name: "v3",
216 run: func(ctx context.DnoteCtx, db *database.DB) error {
217 database.MustExec(t, "marking v3 completed", db, "INSERT INTO migrate_run_test (name) VALUES (?)", "v3")
218 return nil
219 },
220 },
221 }
222
223 // execute
224 err := Run(ctx, sequence, tc.mode)
225 if err != nil {
226 t.Fatal(errors.Wrap(err, "failed to run"))
227 }
228
229 // test
230 var schema int
231 database.MustScan(t, "getting schema", db.QueryRow("SELECT value FROM system WHERE key = ?", tc.schemaKey), &schema)
232 assert.Equal(t, schema, 3, "schema was not updated")

Callers

nothing calls this directly

Calls 7

InitTestCtxWithDBFunction · 0.92
MustExecFunction · 0.92
MustScanFunction · 0.92
EqualFunction · 0.92
initTestDBNoMigrationFunction · 0.85
RunFunction · 0.85
QueryRowMethod · 0.65

Tested by

no test coverage detected