Skip to content

Commit 9cf4f69

Browse files
committed
Move TestStore logic to _internal methods
.. to be easier reusable by different trait implementations.
1 parent 867f084 commit 9cf4f69

File tree

1 file changed

+30
-6
lines changed

1 file changed

+30
-6
lines changed

lightning/src/util/test_utils.rs

Lines changed: 30 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -863,10 +863,8 @@ impl TestStore {
863863
let persisted_bytes = Mutex::new(new_hash_map());
864864
Self { persisted_bytes, read_only }
865865
}
866-
}
867866

868-
impl KVStoreSync for TestStore {
869-
fn read(
867+
fn read_internal(
870868
&self, primary_namespace: &str, secondary_namespace: &str, key: &str,
871869
) -> io::Result<Vec<u8>> {
872870
let persisted_lock = self.persisted_bytes.lock().unwrap();
@@ -888,7 +886,7 @@ impl KVStoreSync for TestStore {
888886
}
889887
}
890888

891-
fn write(
889+
fn write_internal(
892890
&self, primary_namespace: &str, secondary_namespace: &str, key: &str, buf: Vec<u8>,
893891
) -> io::Result<()> {
894892
if self.read_only {
@@ -911,7 +909,7 @@ impl KVStoreSync for TestStore {
911909
Ok(())
912910
}
913911

914-
fn remove(
912+
fn remove_internal(
915913
&self, primary_namespace: &str, secondary_namespace: &str, key: &str, _lazy: bool,
916914
) -> io::Result<()> {
917915
if self.read_only {
@@ -935,7 +933,9 @@ impl KVStoreSync for TestStore {
935933
Ok(())
936934
}
937935

938-
fn list(&self, primary_namespace: &str, secondary_namespace: &str) -> io::Result<Vec<String>> {
936+
fn list_internal(
937+
&self, primary_namespace: &str, secondary_namespace: &str,
938+
) -> io::Result<Vec<String>> {
939939
let mut persisted_lock = self.persisted_bytes.lock().unwrap();
940940

941941
let prefixed = if secondary_namespace.is_empty() {
@@ -950,6 +950,30 @@ impl KVStoreSync for TestStore {
950950
}
951951
}
952952

953+
impl KVStoreSync for TestStore {
954+
fn read(
955+
&self, primary_namespace: &str, secondary_namespace: &str, key: &str,
956+
) -> io::Result<Vec<u8>> {
957+
self.read_internal(primary_namespace, secondary_namespace, key)
958+
}
959+
960+
fn write(
961+
&self, primary_namespace: &str, secondary_namespace: &str, key: &str, buf: Vec<u8>,
962+
) -> io::Result<()> {
963+
self.write_internal(primary_namespace, secondary_namespace, key, buf)
964+
}
965+
966+
fn remove(
967+
&self, primary_namespace: &str, secondary_namespace: &str, key: &str, lazy: bool,
968+
) -> io::Result<()> {
969+
self.remove_internal(primary_namespace, secondary_namespace, key, lazy)
970+
}
971+
972+
fn list(&self, primary_namespace: &str, secondary_namespace: &str) -> io::Result<Vec<String>> {
973+
self.list_internal(primary_namespace, secondary_namespace)
974+
}
975+
}
976+
953977
unsafe impl Sync for TestStore {}
954978
unsafe impl Send for TestStore {}
955979

0 commit comments

Comments
 (0)