Opens a badger db and runs a a test on it.
(t *testing.T, opts *Options, test func(t *testing.T, db *DB))
| 113 | |
| 114 | // Opens a badger db and runs a a test on it. |
| 115 | func runBadgerTest(t *testing.T, opts *Options, test func(t *testing.T, db *DB)) { |
| 116 | dir, err := ioutil.TempDir("", "badger-test") |
| 117 | require.NoError(t, err) |
| 118 | defer removeDir(dir) |
| 119 | if opts == nil { |
| 120 | opts = new(Options) |
| 121 | *opts = getTestOptions(dir) |
| 122 | } else { |
| 123 | opts.Dir = dir |
| 124 | opts.ValueDir = dir |
| 125 | } |
| 126 | |
| 127 | if opts.InMemory { |
| 128 | opts.Dir = "" |
| 129 | opts.ValueDir = "" |
| 130 | } |
| 131 | db, err := Open(*opts) |
| 132 | require.NoError(t, err) |
| 133 | defer func() { |
| 134 | require.NoError(t, db.Close()) |
| 135 | }() |
| 136 | test(t, db) |
| 137 | } |
| 138 | |
| 139 | func TestWrite(t *testing.T) { |
| 140 | runBadgerTest(t, nil, func(t *testing.T, db *DB) { |
no test coverage detected
searching dependent graphs…