| 51 | } |
| 52 | |
| 53 | func OpenDBWithOption(t testing.TB, f string, o *bolt.Options) (*DB, error) { |
| 54 | t.Logf("Opening bbolt DB at: %s", f) |
| 55 | if o == nil { |
| 56 | o = bolt.DefaultOptions |
| 57 | } |
| 58 | |
| 59 | freelistType := bolt.FreelistArrayType |
| 60 | if env := os.Getenv(TestFreelistType); env == string(bolt.FreelistMapType) { |
| 61 | freelistType = bolt.FreelistMapType |
| 62 | } |
| 63 | |
| 64 | o.FreelistType = freelistType |
| 65 | |
| 66 | db, err := bolt.Open(f, 0600, o) |
| 67 | if err != nil { |
| 68 | return nil, err |
| 69 | } |
| 70 | resDB := &DB{ |
| 71 | DB: db, |
| 72 | f: f, |
| 73 | o: o, |
| 74 | t: t, |
| 75 | } |
| 76 | resDB.strictModeEnabledDefault() |
| 77 | t.Cleanup(resDB.PostTestCleanup) |
| 78 | return resDB, nil |
| 79 | } |
| 80 | |
| 81 | func (db *DB) PostTestCleanup() { |
| 82 | // Check database consistency after every test. |