Fix compiling error on windows (#410)

* Fix compiling error on windows

* Fix JsonFileDatastore tests

* Update tempfile cargo, Refactor JsonFileDatastore tests
This commit is contained in:
Jun Jiang
2018-08-14 17:31:05 +08:00
committed by Pierre Krieger
parent b673209839
commit e5afab104a
3 changed files with 13 additions and 11 deletions

View File

@ -10,4 +10,4 @@ chashmap = { git = "https://github.com/redox-os/tfs" }
futures = "0.1"
serde = "1.0"
serde_json = "1.0"
tempfile = "2.2"
tempfile = "3"

View File

@ -140,7 +140,7 @@ where
.map(|(k, v)| (k, to_value(v).unwrap()))
.collect::<Map<_, _>>(),
)?;
temporary_file.sync_data()?;
temporary_file.as_file().sync_data()?;
// Note that `persist` will fail if we try to persist across filesystems. However that
// shouldn't happen since we created the temporary file in the same directory as the final
@ -275,31 +275,33 @@ mod tests {
#[test]
fn open_and_flush() {
let temp_file = NamedTempFile::new().unwrap();
let datastore = JsonFileDatastore::<Vec<u8>>::new(temp_file.path()).unwrap();
let path = NamedTempFile::new().unwrap().into_temp_path();
let datastore = JsonFileDatastore::<Vec<u8>>::new(&path).unwrap();
datastore.flush().unwrap();
}
#[test]
fn values_store_and_reload() {
let temp_file = NamedTempFile::new().unwrap();
let path = NamedTempFile::new().unwrap().into_temp_path();
let datastore = JsonFileDatastore::<Vec<u8>>::new(temp_file.path()).unwrap();
let datastore = JsonFileDatastore::<Vec<u8>>::new(&path).unwrap();
datastore.put("foo".into(), vec![1, 2, 3]);
datastore.put("bar".into(), vec![0, 255, 127]);
datastore.flush().unwrap();
drop(datastore);
let reload = JsonFileDatastore::<Vec<u8>>::new(temp_file.path()).unwrap();
let reload = JsonFileDatastore::<Vec<u8>>::new(&path).unwrap();
assert_eq!(reload.get("bar").unwrap(), &[0, 255, 127]);
assert_eq!(reload.get("foo").unwrap(), &[1, 2, 3]);
}
#[test]
fn query_basic() {
let temp_file = NamedTempFile::new().unwrap();
let path = NamedTempFile::new().unwrap().into_temp_path();
let datastore = JsonFileDatastore::<Vec<u8>>::new(temp_file.path()).unwrap();
let datastore = JsonFileDatastore::<Vec<u8>>::new(&path).unwrap();
datastore.put("foo1".into(), vec![6, 7, 8]);
datastore.put("foo2".into(), vec![6, 7, 8]);
datastore.put("foo3".into(), vec![7, 8, 9]);

View File

@ -12,7 +12,7 @@ libp2p-core = { path = "../core" }
log = "0.4.1"
protobuf = "2.0.2"
rand = "0.3.17"
ring = { version = "0.12.1", features = ["rsa_signing"] }
ring = { version = "0.13.2", features = ["rsa_signing"] }
aes-ctr = "0.1.0"
aesni = { version = "0.4.1", features = ["nocheck"], optional = true }
ctr = { version = "0.1", optional = true }
@ -20,7 +20,7 @@ lazy_static = { version = "0.2.11", optional = true }
rw-stream-sink = { path = "../rw-stream-sink" }
eth-secp256k1 = { git = "https://github.com/paritytech/rust-secp256k1", optional = true }
tokio-io = "0.1.0"
untrusted = "0.5.1"
untrusted = "0.6.2"
[features]
default = ["secp256k1"]