Assign contributing paths in simple cases for snapshots

This commit is contained in:
Lucien Greathouse
2019-10-03 17:34:33 -07:00
parent b2c515f2e6
commit ae0f3b0b02
7 changed files with 51 additions and 31 deletions

View File

@@ -6,7 +6,7 @@ use serde::Serialize;
use crate::{
imfs::{Imfs, ImfsEntry, ImfsFetcher},
snapshot::InstanceSnapshot,
snapshot::{InstanceMetadata, InstanceSnapshot},
};
use super::middleware::{SnapshotFileResult, SnapshotInstanceResult, SnapshotMiddleware};
@@ -39,7 +39,10 @@ impl SnapshotMiddleware for SnapshotCsv {
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("LocalizationTable"),
properties: hashmap! {
@@ -137,6 +140,7 @@ mod test {
use super::*;
use crate::imfs::{ImfsDebug, ImfsSnapshot, NoopFetcher};
use insta::assert_yaml_snapshot;
#[test]
fn csv_from_imfs() {
@@ -152,19 +156,6 @@ Ack,Ack!,,An exclamation of despair,¡Ay!"#,
let entry = imfs.get("/foo.csv").unwrap();
let instance_snapshot = SnapshotCsv::from_imfs(&mut imfs, &entry).unwrap().unwrap();
let expected_contents =
r#"[{"key":"Ack","example":"An exclamation of despair","source":"Ack!","values":{"es":"¡Ay!"}}]"#;
assert_eq!(instance_snapshot.name, "foo");
assert_eq!(instance_snapshot.class_name, "LocalizationTable");
assert_eq!(instance_snapshot.children, Vec::new());
assert_eq!(
instance_snapshot.properties,
hashmap! {
"Contents".to_owned() => RbxValue::String {
value: expected_contents.to_owned(),
},
}
);
assert_yaml_snapshot!(instance_snapshot);
}
}

View File

@@ -43,7 +43,7 @@ impl SnapshotMiddleware for SnapshotRbxlx {
let mut snapshot = InstanceSnapshot::from_tree(&temp_tree, root_id);
snapshot.name = Cow::Owned(instance_name);
// TODO: Assign snapshot.source
snapshot.metadata.contributing_paths = vec![entry.path().to_path_buf()];
Ok(Some(snapshot))
}

View File

@@ -49,7 +49,7 @@ impl SnapshotMiddleware for SnapshotRbxm {
if children.len() == 1 {
let mut snapshot = InstanceSnapshot::from_tree(&temp_tree, children[0]);
snapshot.name = Cow::Owned(instance_name);
// TODO: Assign snapshot.source
snapshot.metadata.contributing_paths = vec![entry.path().to_path_buf()];
Ok(Some(snapshot))
} else {

View File

@@ -45,7 +45,7 @@ impl SnapshotMiddleware for SnapshotRbxmx {
if children.len() == 1 {
let mut snapshot = InstanceSnapshot::from_tree(&temp_tree, children[0]);
snapshot.name = Cow::Owned(instance_name);
// TODO: Assign snapshot.source
snapshot.metadata.contributing_paths = vec![entry.path().to_path_buf()];
Ok(Some(snapshot))
} else {

View File

@@ -0,0 +1,17 @@
---
source: src/snapshot_middleware/csv.rs
expression: instance_snapshot
---
snapshot_id: ~
metadata:
ignore_unknown_instances: false
contributing_paths:
- /foo.csv
project_node: ~
name: foo
class_name: LocalizationTable
properties:
Contents:
Type: String
Value: "[{\"key\":\"Ack\",\"example\":\"An exclamation of despair\",\"source\":\"Ack!\",\"values\":{\"es\":\"¡Ay!\"}}]"
children: []

View File

@@ -0,0 +1,17 @@
---
source: src/snapshot_middleware/txt.rs
expression: instance_snapshot
---
snapshot_id: ~
metadata:
ignore_unknown_instances: false
contributing_paths:
- /foo.txt
project_node: ~
name: foo
class_name: StringValue
properties:
Value:
Type: String
Value: Hello there!
children: []

View File

@@ -5,7 +5,7 @@ use rbx_dom_weak::{RbxId, RbxTree, RbxValue};
use crate::{
imfs::{FileSnapshot, Imfs, ImfsEntry, ImfsFetcher, ImfsSnapshot},
snapshot::InstanceSnapshot,
snapshot::{InstanceMetadata, InstanceSnapshot},
};
use super::middleware::{SnapshotFileResult, SnapshotInstanceResult, SnapshotMiddleware};
@@ -51,7 +51,10 @@ impl SnapshotMiddleware for SnapshotTxt {
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("StringValue"),
properties,
@@ -91,6 +94,7 @@ impl SnapshotMiddleware for SnapshotTxt {
mod test {
use super::*;
use insta::assert_yaml_snapshot;
use maplit::hashmap;
use rbx_dom_weak::RbxInstanceProperties;
@@ -106,16 +110,7 @@ mod test {
let entry = imfs.get("/foo.txt").unwrap();
let instance_snapshot = SnapshotTxt::from_imfs(&mut imfs, &entry).unwrap().unwrap();
assert_eq!(instance_snapshot.name, "foo");
assert_eq!(instance_snapshot.class_name, "StringValue");
assert_eq!(
instance_snapshot.properties,
hashmap! {
"Value".to_owned() => RbxValue::String {
value: "Hello there!".to_owned(),
},
}
);
assert_yaml_snapshot!(instance_snapshot);
}
#[test]