79 lines
No EOL
2.7 KiB
Rust
79 lines
No EOL
2.7 KiB
Rust
// Include the generated protobuf code
|
|
include!("databuild.rs");
|
|
|
|
#[cfg(test)]
|
|
mod tests {
|
|
use super::*;
|
|
use prost::Message;
|
|
|
|
#[test]
|
|
fn test_partition_ref_creation() {
|
|
let partition_ref = PartitionRef { str: "test-partition".to_string() };
|
|
assert_eq!(partition_ref.str, "test-partition");
|
|
}
|
|
|
|
#[test]
|
|
fn test_job_config_creation() {
|
|
let partition = PartitionRef { str: "output-partition".to_string() };
|
|
let mut job_config = JobConfig::default();
|
|
job_config.outputs.push(partition);
|
|
job_config.args.push("arg1".to_string());
|
|
|
|
assert_eq!(job_config.outputs.len(), 1);
|
|
assert_eq!(job_config.args.len(), 1);
|
|
assert_eq!(job_config.outputs[0].str, "output-partition");
|
|
assert_eq!(job_config.args[0], "arg1");
|
|
}
|
|
|
|
#[test]
|
|
fn test_prost_serialization() {
|
|
// Test that we can properly serialize and deserialize with prost
|
|
let partition_ref = PartitionRef { str: "test-partition".to_string() };
|
|
|
|
// Encode to bytes using prost
|
|
let mut buf = Vec::new();
|
|
partition_ref.encode(&mut buf).expect("Failed to encode");
|
|
|
|
// Decode from bytes using prost
|
|
let decoded_partition = PartitionRef::decode(&buf[..]).expect("Failed to decode");
|
|
|
|
assert_eq!(partition_ref.str, decoded_partition.str);
|
|
}
|
|
|
|
#[test]
|
|
fn test_serde_serialization() {
|
|
// Test that we can serialize to JSON using serde
|
|
let partition_ref = PartitionRef { str: "test-partition".to_string() };
|
|
|
|
// Serialize to JSON
|
|
let json = serde_json::to_string(&partition_ref).expect("Failed to serialize to JSON");
|
|
|
|
// Deserialize from JSON
|
|
let decoded_partition: PartitionRef = serde_json::from_str(&json).expect("Failed to deserialize from JSON");
|
|
|
|
assert_eq!(partition_ref.str, decoded_partition.str);
|
|
}
|
|
|
|
#[test]
|
|
fn test_job_graph_creation() {
|
|
let _job_label = JobLabel { label: "//my:job".to_string() };
|
|
let graph_label = GraphLabel { label: "//my:graph".to_string() };
|
|
|
|
let mut job_graph = JobGraph::default();
|
|
job_graph.label = Some(graph_label);
|
|
job_graph.outputs.push(PartitionRef { str: "output".to_string() });
|
|
|
|
assert!(job_graph.label.is_some());
|
|
assert_eq!(job_graph.label.unwrap().label, "//my:graph");
|
|
assert_eq!(job_graph.outputs.len(), 1);
|
|
}
|
|
|
|
#[test]
|
|
fn test_dep_type_enum() {
|
|
let query_dep = DepType::Query;
|
|
let materialize_dep = DepType::Materialize;
|
|
|
|
assert_eq!(query_dep as i32, 0);
|
|
assert_eq!(materialize_dep as i32, 1);
|
|
}
|
|
} |