|
5 | 5 | // http://opensource.org/licenses/MIT>, at your option. This file may not be
|
6 | 6 | // copied, modified, or distributed except according to those terms.
|
7 | 7 |
|
| 8 | +use foundationdb::directory::error::DirectoryError; |
8 | 9 | use foundationdb::directory::DirectoryLayer;
|
9 | 10 | use foundationdb::*;
|
10 | 11 |
|
11 | 12 | mod common;
|
12 | 13 |
|
| 14 | +#[test] |
| 15 | +fn test_directory() { |
| 16 | + let _guard = unsafe { foundationdb::boot() }; |
| 17 | + let db = futures::executor::block_on(common::database()).expect("cannot open fdb"); |
| 18 | + |
| 19 | + eprintln!("clearing all keys"); |
| 20 | + let trx = db.create_trx().expect("cannot create txn"); |
| 21 | + trx.clear_range(b"\x00", b"\xff"); |
| 22 | + futures::executor::block_on(trx.commit()).expect("could not clear keys"); |
| 23 | + |
| 24 | + eprintln!("creating directories"); |
| 25 | + let directory = DirectoryLayer::default(); |
| 26 | + |
| 27 | + futures::executor::block_on(test_create_or_open_async( |
| 28 | + &db, |
| 29 | + &directory, |
| 30 | + vec![String::from("a")], |
| 31 | + )) |
| 32 | + .expect("failed to run"); |
| 33 | + |
| 34 | + futures::executor::block_on(test_create_then_open_async( |
| 35 | + &db, |
| 36 | + &directory, |
| 37 | + vec![String::from("b"), String::from("a")], |
| 38 | + )) |
| 39 | + .expect("failed to run"); |
| 40 | + |
| 41 | + futures::executor::block_on(test_bad_layer(&db)).expect("failed to run"); |
| 42 | +} |
| 43 | + |
13 | 44 | async fn test_create_then_open_async(
|
14 | 45 | db: &Database,
|
15 | 46 | directory: &DirectoryLayer,
|
@@ -42,30 +73,29 @@ async fn test_create_or_open_async(
|
42 | 73 | Ok(())
|
43 | 74 | }
|
44 | 75 |
|
45 |
| -#[test] |
46 |
| -fn test_directory() { |
47 |
| - let _guard = unsafe { foundationdb::boot() }; |
48 |
| - let db = futures::executor::block_on(common::database()).expect("cannot open fdb"); |
| 76 | +async fn test_bad_layer(db: &Database) -> Result<(), DirectoryError> { |
| 77 | + let directory = DirectoryLayer { |
| 78 | + layer: vec![0u8], |
| 79 | + ..Default::default() |
| 80 | + }; |
| 81 | + let trx = db.create_trx()?; |
49 | 82 |
|
50 |
| - eprintln!("clearing all keys"); |
51 |
| - let trx = db.create_trx().expect("cannot create txn"); |
52 |
| - trx.clear_range(b"\x00", b"\xff"); |
53 |
| - futures::executor::block_on(trx.commit()).expect("could not clear keys"); |
| 83 | + directory |
| 84 | + .create_or_open(&trx, vec![String::from("bad_layer")]) |
| 85 | + .await?; |
54 | 86 |
|
55 |
| - eprintln!("creating directories"); |
56 |
| - let directory = DirectoryLayer::default(); |
| 87 | + let directory = DirectoryLayer { |
| 88 | + layer: vec![1u8], |
| 89 | + ..Default::default() |
| 90 | + }; |
57 | 91 |
|
58 |
| - futures::executor::block_on(test_create_or_open_async( |
59 |
| - &db, |
60 |
| - &directory, |
61 |
| - vec![String::from("a")], |
62 |
| - )) |
63 |
| - .expect("failed to run"); |
| 92 | + let result = directory |
| 93 | + .create_or_open(&trx, vec![String::from("bad_layer")]) |
| 94 | + .await; |
| 95 | + match result { |
| 96 | + Err(DirectoryError::IncompatibleLayer) => {} |
| 97 | + _ => panic!("should have been an IncompatibleLayer error"), |
| 98 | + } |
64 | 99 |
|
65 |
| - futures::executor::block_on(test_create_then_open_async( |
66 |
| - &db, |
67 |
| - &directory, |
68 |
| - vec![String::from("b"), String::from("a")], |
69 |
| - )) |
70 |
| - .expect("failed to run"); |
| 100 | + Ok(()) |
71 | 101 | }
|
0 commit comments