()
| 5372 | |
| 5373 | #[test] |
| 5374 | fn test_context_serialize() { |
| 5375 | let generators = context_generators(); |
| 5376 | let contexts: Vec<Context> = generators.iter().map(|generator| generator()).collect(); |
| 5377 | let serialized_contexts: Vec<String> = contexts |
| 5378 | .iter() |
| 5379 | .map(|context| serde_json::to_string(context).unwrap()) |
| 5380 | .collect(); |
| 5381 | let deserialized_contexts: Vec<Context> = serialized_contexts |
| 5382 | .iter() |
| 5383 | .map(|serialized_context| serde_json::from_str(serialized_context).unwrap()) |
| 5384 | .collect(); |
| 5385 | assert_eq!(contexts.len(), deserialized_contexts.len()); |
| 5386 | for i in 0..contexts.len() { |
| 5387 | assert!(contexts[i] != deserialized_contexts[i]); |
| 5388 | assert!(contexts_deep_equal( |
| 5389 | contexts[i].clone(), |
| 5390 | deserialized_contexts[i].clone() |
| 5391 | )); |
| 5392 | assert_eq!( |
| 5393 | serialized_contexts[i], |
| 5394 | serde_json::to_string(&deserialized_contexts[i]).unwrap() |
| 5395 | ) |
| 5396 | } |
| 5397 | |
| 5398 | //Read test cases from golden file |
| 5399 | let test_case = lines_from_file("./src/test_data/version_testcase.txt"); |
| 5400 | assert_eq!(serde_json::to_string(&contexts[0]).unwrap(), test_case[0]); |
| 5401 | |
| 5402 | //Following test case expect an error message "Non-existent main graph" which is caused by the field "\"main_graph\":918276318" |
| 5403 | deserialize_error_lenient(&test_case[1], "Non-existent main graph"); |
| 5404 | assert_eq!(serde_json::to_string(&contexts[9]).unwrap(), test_case[2]); |
| 5405 | //Following test case expect an error message "Non-existent node dependency" which is caused by the field "\"node_dependencies\":[918723]" |
| 5406 | deserialize_error_lenient(&test_case[3], "Non-existent node dependency"); |
| 5407 | //Following test case expect an error message "Non-existent graph dependency" which is caused by the field "\"graph_dependencies\":[918723]" |
| 5408 | deserialize_error_lenient(&test_case[4], "Non-existent graph dependency"); |
| 5409 | assert_eq!(serde_json::to_string(&contexts[13]).unwrap(), test_case[5]); |
| 5410 | //Following test case expect an error message "Non-existent output node" which is caused by the field "\"output_node\":9817273" |
| 5411 | deserialize_error_lenient(&test_case[6], "Non-existent output node"); |
| 5412 | //Following test case expect an error message "graphs_names contain an invalid ID" which is caused by the field "\"graphs_names\":[[8079123,\"main\"]]" |
| 5413 | deserialize_error_lenient(&test_case[7], "graphs_names contain an invalid ID"); |
| 5414 | //Following test case expect an error message "nodes_names contain an invalid graph ID" which is caused by the field "\"nodes_names\":[[[8079123,0],\"input\"]]" |
| 5415 | deserialize_error_lenient(&test_case[8], "nodes_names contain an invalid graph ID"); |
| 5416 | //Following test case expect an error message "nodes_names contain an invalid graph ID" which is caused by the field "\"nodes_names\":[[[0,8079123],\"input\"]]" |
| 5417 | deserialize_error_lenient(&test_case[9], "nodes_names contain an invalid node ID"); |
| 5418 | //Following test case expect an error message "Context version doesn't match the requirement" which is caused by its old version number |
| 5419 | deserialize_error_lenient( |
| 5420 | &test_case[10], |
| 5421 | "Context version doesn't match the requirement", |
| 5422 | ); |
| 5423 | //Following test case expect an error message "Context version doesn't match the requirement" which is caused by its old version number. Although its payload is unsupported, this should not cause any error before passing the version check. |
| 5424 | deserialize_error_lenient( |
| 5425 | &test_case[11], |
| 5426 | "Context version doesn't match the requirement", |
| 5427 | ); |
| 5428 | } |
| 5429 | |
| 5430 | use crate::data_types::INT32; |
| 5431 | use crate::data_values::Value; |
nothing calls this directly
no test coverage detected