Ensure that a database that is too small returns an error.
(t *testing.T)
| 428 | |
| 429 | // Ensure that a database that is too small returns an error. |
| 430 | func 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 |