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

Function TestMigrate_invalidFilename

pkg/server/database/migrate_test.go:273–310  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

271}
272
273func TestMigrate_invalidFilename(t *testing.T) {
274 db, err := gorm.Open(sqlite.Open(":memory:"), &gorm.Config{})
275 if err != nil {
276 t.Fatalf("failed to open database: %v", err)
277 }
278
279 tests := []struct {
280 name string
281 filename string
282 wantErr bool
283 }{
284 {"valid format", "001-init.sql", false},
285 {"no leading zeros", "1-init.sql", true},
286 {"two digits", "01-init.sql", true},
287 {"no dash", "001init.sql", true},
288 {"no description", "001-.sql", true},
289 {"no extension", "001-init.", true},
290 {"wrong extension", "001-init.txt", true},
291 {"non-numeric version number", "0a1-init.sql", true},
292 {"underscore separator", "001_init.sql", true},
293 {"multiple dashes in description", "001-add-feature-v2.sql", false},
294 }
295
296 for _, tt := range tests {
297 t.Run(tt.name, func(t *testing.T) {
298 migrationsFs := fstest.MapFS{
299 tt.filename: &fstest.MapFile{
300 Data: []byte("SELECT 1;"),
301 },
302 }
303
304 err := migrate(db, migrationsFs)
305 if (err != nil) != tt.wantErr {
306 t.Errorf("error = %v, wantErr %v", err, tt.wantErr)
307 }
308 })
309 }
310}

Callers

nothing calls this directly

Calls 2

migrateFunction · 0.85
OpenMethod · 0.80

Tested by

no test coverage detected