Skip to content

Commit 5dd3d64

Browse files
committed
refactor: move tests to correct folders
1. move stage file tests to user_proto_conv 2. add incompatible test 3. test load old stage file Signed-off-by: ClSlaid <cailue@bupt.edu.cn>
1 parent 3b78959 commit 5dd3d64

File tree

2 files changed

+70
-47
lines changed

2 files changed

+70
-47
lines changed

src/meta/proto-conv/tests/it/user_proto_conv.rs

Lines changed: 70 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -179,6 +179,16 @@ fn test_user_pb_from_to() -> anyhow::Result<()> {
179179
Ok(())
180180
}
181181

182+
#[test]
183+
fn test_stage_file_pb_from_to() -> anyhow::Result<()> {
184+
let test_stage_file = test_stage_file();
185+
let test_stage_file_pb = test_stage_file.to_pb()?;
186+
let got = mt::StageFile::from_pb(test_stage_file_pb)?;
187+
assert_eq!(got, test_stage_file);
188+
189+
Ok(())
190+
}
191+
182192
#[test]
183193
fn test_user_incompatible() -> anyhow::Result<()> {
184194
{
@@ -200,6 +210,25 @@ fn test_user_incompatible() -> anyhow::Result<()> {
200210
);
201211
}
202212

213+
{
214+
let stage_file = test_stage_file();
215+
let mut p = stage_file.to_pb()?;
216+
p.ver = VER + 1;
217+
p.min_compatible = VER + 1;
218+
219+
let res = mt::StageFile::from_pb(p);
220+
assert_eq!(
221+
Incompatible {
222+
reason: format!(
223+
"executable ver={} is smaller than the message min compatible ver: {}",
224+
VER,
225+
VER + 1
226+
)
227+
},
228+
res.unwrap_err()
229+
)
230+
}
231+
203232
{
204233
let fs_stage_info = test_fs_stage_info();
205234
let mut p = fs_stage_info.to_pb()?;
@@ -271,7 +300,7 @@ fn test_build_user_pb_buf() -> anyhow::Result<()> {
271300

272301
let mut buf = vec![];
273302
common_protos::prost::Message::encode(&p, &mut buf)?;
274-
println!("{:?}", buf);
303+
println!("user_info: {:?}", buf);
275304
}
276305

277306
// StageFile
@@ -280,7 +309,7 @@ fn test_build_user_pb_buf() -> anyhow::Result<()> {
280309
let p = stage_file.to_pb()?;
281310
let mut buf = vec![];
282311
common_protos::prost::Message::encode(&p, &mut buf)?;
283-
println!("{:?}", buf);
312+
println!("stage_file: {:?}", buf);
284313
}
285314

286315
// Stage on local file system
@@ -291,7 +320,7 @@ fn test_build_user_pb_buf() -> anyhow::Result<()> {
291320

292321
let mut buf = vec![];
293322
common_protos::prost::Message::encode(&p, &mut buf)?;
294-
println!("{:?}", buf);
323+
println!("fs_stage_info: {:?}", buf);
295324
}
296325

297326
// Stage on S3
@@ -302,7 +331,7 @@ fn test_build_user_pb_buf() -> anyhow::Result<()> {
302331

303332
let mut buf = vec![];
304333
common_protos::prost::Message::encode(&p, &mut buf)?;
305-
println!("{:?}", buf);
334+
println!("s3_stage_info: {:?}", buf);
306335
}
307336

308337
// Stage on GCS, supported in version >=4.
@@ -311,7 +340,7 @@ fn test_build_user_pb_buf() -> anyhow::Result<()> {
311340
let p = gcs_stage_info.to_pb()?;
312341
let mut buf = vec![];
313342
common_protos::prost::Message::encode(&p, &mut buf)?;
314-
println!("{:?}", buf);
343+
println!("gcs_stage_info: {:?}", buf);
315344
}
316345

317346
Ok(())
@@ -390,3 +419,39 @@ fn test_load_old_user() -> anyhow::Result<()> {
390419

391420
Ok(())
392421
}
422+
423+
#[test]
424+
fn test_old_stage_file() -> anyhow::Result<()> {
425+
// Encoded data of version 7 of StageFile:
426+
// Generated with `test_build_user_pb_buf`
427+
{
428+
let stage_file_v7 = vec![
429+
10, 14, 47, 112, 97, 116, 104, 47, 116, 111, 47, 115, 116, 97, 103, 101, 16, 233, 1,
430+
34, 23, 50, 48, 50, 50, 45, 48, 57, 45, 49, 54, 32, 48, 48, 58, 48, 49, 58, 48, 50, 32,
431+
85, 84, 67, 42, 37, 10, 12, 100, 97, 116, 97, 102, 117, 115, 101, 108, 97, 98, 115, 18,
432+
15, 100, 97, 116, 97, 102, 117, 115, 101, 108, 97, 98, 115, 46, 114, 115, 160, 6, 8,
433+
168, 6, 1, 160, 6, 8, 168, 6, 1,
434+
];
435+
let p: pb::StageFile =
436+
common_protos::prost::Message::decode(stage_file_v7.as_slice()).map_err(print_err)?;
437+
let got = mt::StageFile::from_pb(p).map_err(print_err)?;
438+
439+
let dt = NaiveDateTime::new(
440+
NaiveDate::from_ymd(2022, 9, 16),
441+
NaiveTime::from_hms(0, 1, 2),
442+
);
443+
let user_id = mt::UserIdentity::new("datafuselabs", "datafuselabs.rs");
444+
let want = mt::StageFile {
445+
path: "/path/to/stage".to_string(),
446+
size: 233,
447+
md5: None,
448+
last_modified: DateTime::from_utc(dt, Utc),
449+
creator: Some(user_id),
450+
..Default::default()
451+
};
452+
453+
assert_eq!(got, want);
454+
}
455+
456+
Ok(())
457+
}

src/meta/proto-conv/tests/it/user_stage.rs

Lines changed: 0 additions & 42 deletions
Original file line numberDiff line numberDiff line change
@@ -14,11 +14,6 @@
1414

1515
//! Test UserStageInfo
1616
17-
use common_datavalues::chrono::DateTime;
18-
use common_datavalues::chrono::NaiveDate;
19-
use common_datavalues::chrono::NaiveDateTime;
20-
use common_datavalues::chrono::NaiveTime;
21-
use common_datavalues::chrono::Utc;
2217
use common_meta_types as mt;
2318
use common_storage::StorageFsConfig;
2419
use common_storage::StorageGcsConfig;
@@ -29,13 +24,6 @@ use crate::common;
2924
use crate::user_proto_conv::test_fs_stage_info;
3025
use crate::user_proto_conv::test_gcs_stage_info;
3126
use crate::user_proto_conv::test_s3_stage_info;
32-
use crate::user_proto_conv::test_stage_file;
33-
34-
#[test]
35-
fn test_stage_file_latest() -> anyhow::Result<()> {
36-
common::test_pb_from_to("stage_file", test_stage_file())?;
37-
Ok(())
38-
}
3927

4028
#[test]
4129
fn test_user_stage_fs_latest() -> anyhow::Result<()> {
@@ -55,36 +43,6 @@ fn test_user_stage_gcs_latest() -> anyhow::Result<()> {
5543
Ok(())
5644
}
5745

58-
#[test]
59-
fn test_stage_file_v7() -> anyhow::Result<()> {
60-
// Encoded data of version 6 of StageFile:
61-
// Generated with common::test_pb_from_to.
62-
let stage_file_v7 = vec![
63-
10, 14, 47, 112, 97, 116, 104, 47, 116, 111, 47, 115, 116, 97, 103, 101, 16, 233, 1, 34,
64-
23, 50, 48, 50, 50, 45, 48, 57, 45, 49, 54, 32, 48, 48, 58, 48, 49, 58, 48, 50, 32, 85, 84,
65-
67, 42, 37, 10, 12, 100, 97, 116, 97, 102, 117, 115, 101, 108, 97, 98, 115, 18, 15, 100,
66-
97, 116, 97, 102, 117, 115, 101, 108, 97, 98, 115, 46, 114, 115, 160, 6, 8, 168, 6, 1, 160,
67-
6, 8, 168, 6, 1,
68-
];
69-
70-
let dt = NaiveDateTime::new(
71-
NaiveDate::from_ymd(2022, 9, 16),
72-
NaiveTime::from_hms(0, 1, 2),
73-
);
74-
let user_id = mt::UserIdentity::new("datafuselabs", "datafuselabs.rs");
75-
let want = mt::StageFile {
76-
path: "/path/to/stage".to_string(),
77-
size: 233,
78-
md5: None,
79-
last_modified: DateTime::from_utc(dt, Utc),
80-
creator: Some(user_id),
81-
..Default::default()
82-
};
83-
84-
common::test_load_old(func_name!(), stage_file_v7.as_slice(), want)?;
85-
Ok(())
86-
}
87-
8846
#[test]
8947
fn test_user_stage_fs_v6() -> anyhow::Result<()> {
9048
// Encoded data of version 6 of user_stage_fs:

0 commit comments

Comments
 (0)