Port SnapshotDir tests to use insta snapshots

This commit is contained in:
Lucien Greathouse
2019-09-30 18:33:46 -07:00
parent 1c6788ea45
commit 95f06d56d8
5 changed files with 83 additions and 20 deletions

View File

@@ -4,7 +4,7 @@ use rbx_dom_weak::{RbxId, RbxTree};
use crate::{
imfs::{DirectorySnapshot, Imfs, ImfsEntry, ImfsFetcher, ImfsSnapshot},
snapshot::InstanceSnapshot,
snapshot::{InstanceMetadata, InstanceSnapshot},
};
use super::{
@@ -43,7 +43,10 @@ impl SnapshotMiddleware for SnapshotDir {
Ok(Some(InstanceSnapshot {
snapshot_id: None,
metadata: Default::default(), // TODO
metadata: InstanceMetadata {
contributing_paths: vec![entry.path().to_path_buf()],
..Default::default()
},
name: Cow::Owned(instance_name),
class_name: Cow::Borrowed("Folder"),
properties: HashMap::new(),
@@ -76,6 +79,7 @@ impl SnapshotMiddleware for SnapshotDir {
mod test {
use super::*;
use insta::assert_yaml_snapshot;
use maplit::hashmap;
use crate::imfs::{ImfsDebug, NoopFetcher};
@@ -90,10 +94,7 @@ mod test {
let entry = imfs.get("/foo").unwrap();
let instance_snapshot = SnapshotDir::from_imfs(&mut imfs, &entry).unwrap().unwrap();
assert_eq!(instance_snapshot.name, "foo");
assert_eq!(instance_snapshot.class_name, "Folder");
assert_eq!(instance_snapshot.properties, HashMap::new());
assert_eq!(instance_snapshot.children, Vec::new());
assert_yaml_snapshot!(instance_snapshot);
}
#[test]
@@ -108,15 +109,6 @@ mod test {
let entry = imfs.get("/foo").unwrap();
let instance_snapshot = SnapshotDir::from_imfs(&mut imfs, &entry).unwrap().unwrap();
assert_eq!(instance_snapshot.name, "foo");
assert_eq!(instance_snapshot.class_name, "Folder");
assert_eq!(instance_snapshot.properties, HashMap::new());
assert_eq!(instance_snapshot.children.len(), 1);
let child = &instance_snapshot.children[0];
assert_eq!(child.name, "Child");
assert_eq!(child.class_name, "Folder");
assert_eq!(child.properties, HashMap::new());
assert_eq!(child.children, Vec::new());
assert_yaml_snapshot!(instance_snapshot);
}
}

View File

@@ -0,0 +1,14 @@
---
source: src/snapshot_middleware/dir.rs
expression: instance_snapshot
---
snapshot_id: ~
metadata:
ignore_unknown_instances: false
contributing_paths:
- /foo
project_node: ~
name: foo
class_name: Folder
properties: {}
children: []

View File

@@ -0,0 +1,24 @@
---
source: src/snapshot_middleware/dir.rs
expression: instance_snapshot
---
snapshot_id: ~
metadata:
ignore_unknown_instances: false
contributing_paths:
- /foo
project_node: ~
name: foo
class_name: Folder
properties: {}
children:
- snapshot_id: ~
metadata:
ignore_unknown_instances: false
contributing_paths:
- /foo/Child
project_node: ~
name: Child
class_name: Folder
properties: {}
children: []