MCPcopy
hub / github.com/etcd-io/bbolt / TestOpen_FileTooSmall

Function TestOpen_FileTooSmall

db_test.go:430–452  ·  view source on GitHub ↗

Ensure that a database that is too small returns an error.

(t *testing.T)

Source from the content-addressed store, hash-verified

428
429// Ensure that a database that is too small returns an error.
430func TestOpen_FileTooSmall(t *testing.T) {
431 path := tempfile()
432 defer os.RemoveAll(path)
433
434 db, err := bolt.Open(path, 0600, nil)
435 if err != nil {
436 t.Fatal(err)
437 }
438 pageSize := int64(db.Info().PageSize)
439 if err = db.Close(); err != nil {
440 t.Fatal(err)
441 }
442
443 // corrupt the database
444 if err = os.Truncate(path, pageSize); err != nil {
445 t.Fatal(err)
446 }
447
448 _, err = bolt.Open(path, 0600, nil)
449 if err == nil || !strings.Contains(err.Error(), "file size too small") {
450 t.Fatalf("unexpected error: %s", err)
451 }
452}
453
454// TestDB_Open_InitialMmapSize tests if having InitialMmapSize large enough
455// to hold data from concurrent write transaction resolves the issue that

Callers

nothing calls this directly

Calls 6

tempfileFunction · 0.85
FatalMethod · 0.65
InfoMethod · 0.65
ErrorMethod · 0.65
FatalfMethod · 0.65
CloseMethod · 0.45

Tested by

no test coverage detected