-
Notifications
You must be signed in to change notification settings - Fork 9
/
read_rows_test.rs
89 lines (77 loc) · 3.44 KB
/
read_rows_test.rs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
use bigtable_rs::bigtable::read_rows::decode_read_rows_response_to_vec;
use bigtable_rs::google::bigtable::v2::read_rows_response::cell_chunk::RowStatus;
use bigtable_rs::google::bigtable::v2::read_rows_response::CellChunk;
use bigtable_rs::google::cloud::conformace::bigtable::v2::{
read_rows_test, ReadRowsTest, TestFile,
};
use std::fs;
type ReadRowTestResult = read_rows_test::Result;
/// `read_row_test.json` is a straight copy from Google's
/// https://github.com/googleapis/conformance-tests/blob/master/bigtable/v2/readrows.json
/// And this test is basically a clone version of
/// https://github.com/googleapis/java-bigtable/blob/main/google-cloud-bigtable/src/test/java/com/google/cloud/bigtable/data/v2/stub/readrows/ReadRowsMergingAcceptanceTest.java
#[test]
fn tmp_test_1() {
let chunk = CellChunk {
row_key: vec![],
family_name: None,
qualifier: None,
timestamp_micros: 0,
labels: vec![],
value: vec![],
value_size: 0,
row_status: Some(RowStatus::CommitRow(true)),
};
println!("{}", serde_json::to_string_pretty(&chunk).unwrap());
}
#[test]
fn read_rows_test_from_json_can_all_pass() {
let file =
fs::File::open("tests/read_rows/read_rows_test.json").expect("file should open read only");
let jd = &mut serde_json::Deserializer::from_reader(file);
let result: Result<TestFile, _> = serde_path_to_error::deserialize(jd);
let test_file = match result {
Ok(test_file) => test_file,
Err(err) => {
panic!("Json parse error: {}", err);
}
};
for (test_id, mut rrt) in test_file.read_rows_tests.into_iter().enumerate() {
let decode_read_rows_results = decode_read_rows_response_to_vec(rrt.chunks);
rrt.chunks = vec![]; // fill in partial moved chunks, let borrow checker pass
println!("{} Testing: {}", test_id, rrt.description);
let actual_result_has_error = decode_read_rows_results.iter().any(|ar| {
println!("{:?}", ar);
ar.is_err()
});
let expect_result_has_error = expect_read_row_test_result_has_error(&rrt);
if expect_result_has_error != actual_result_has_error {
panic!(
"Expect having error: {} not match with actual having error: {}",
expect_result_has_error, actual_result_has_error
);
}
let expected_results: Vec<ReadRowTestResult> =
rrt.results.into_iter().filter(|r| !r.error).collect();
let actual_results: Vec<ReadRowTestResult> = decode_read_rows_results
.into_iter()
.filter(|r| r.is_ok())
.flat_map(|r| {
let (row_key, row_cells) = r.unwrap();
row_cells.into_iter().map(move |cell| ReadRowTestResult {
row_key: String::from_utf8(row_key.clone()).unwrap(),
family_name: cell.family_name,
qualifier: String::from_utf8(cell.qualifier).unwrap(),
timestamp_micros: cell.timestamp_micros,
value: String::from_utf8(cell.value).unwrap(),
label: cell.labels.first().unwrap_or(&"".to_owned()).clone(),
error: false,
})
})
.collect();
assert_eq!(expected_results, actual_results);
}
}
fn expect_read_row_test_result_has_error(rrt: &ReadRowsTest) -> bool {
rrt.results.last().map(|r| r.error).unwrap_or(false)
}