Skip to content

Commit 01e9fbc

Browse files
committed
chore(git): merge from master
2 parents 4f4cc68 + f4fd338 commit 01e9fbc

File tree

3 files changed

+98
-99
lines changed

3 files changed

+98
-99
lines changed

src/app/hdd.rs

Lines changed: 1 addition & 98 deletions
Original file line numberDiff line numberDiff line change
@@ -52,101 +52,4 @@ fn path_is_in_hdd<Api: self::Api>(path: &Path, disks: &[Api::Disk]) -> bool {
5252
}
5353

5454
#[cfg(test)]
55-
mod tests {
56-
use super::{any_path_is_in_hdd, path_is_in_hdd, Api};
57-
use pipe_trait::Pipe;
58-
use pretty_assertions::assert_eq;
59-
use std::path::{Path, PathBuf};
60-
use sysinfo::DiskKind;
61-
62-
/// Fake disk for [`Api`].
63-
struct Disk {
64-
kind: DiskKind,
65-
mount_point: &'static str,
66-
}
67-
68-
impl Disk {
69-
fn new(kind: DiskKind, mount_point: &'static str) -> Self {
70-
Self { kind, mount_point }
71-
}
72-
}
73-
74-
/// Mocked implementation of [`Api`] for testing purposes.
75-
struct MockedApi;
76-
impl Api for MockedApi {
77-
type Disk = Disk;
78-
79-
fn get_disk_kind(disk: &Self::Disk) -> DiskKind {
80-
disk.kind
81-
}
82-
83-
fn get_mount_point(disk: &Self::Disk) -> &Path {
84-
Path::new(disk.mount_point)
85-
}
86-
87-
fn canonicalize(path: &Path) -> std::io::Result<PathBuf> {
88-
path.to_path_buf().pipe(Ok)
89-
}
90-
}
91-
92-
#[test]
93-
fn test_any_path_in_hdd() {
94-
let disks = &[
95-
Disk::new(DiskKind::SSD, "/"),
96-
Disk::new(DiskKind::HDD, "/home"),
97-
Disk::new(DiskKind::HDD, "/mnt/hdd-data"),
98-
Disk::new(DiskKind::SSD, "/mnt/ssd-data"),
99-
Disk::new(DiskKind::HDD, "/mnt/hdd-data/repo"),
100-
];
101-
102-
let cases: &[(&[&str], bool)] = &[
103-
(&[], false),
104-
(&["/"], false),
105-
(&["/home"], true),
106-
(&["/mnt"], false),
107-
(&["/mnt/ssd-data"], false),
108-
(&["/mnt/hdd-data"], true),
109-
(&["/mnt/hdd-data/repo"], true),
110-
(&["/etc/fstab"], false),
111-
(&["/home/usr/file"], true),
112-
(&["/home/data/repo/test"], true),
113-
(&["/usr/share"], false),
114-
(&["/mnt/ssd-data/test"], false),
115-
(&["/etc/fstab", "/home/user/file"], true),
116-
(&["/mnt/hdd-data/file", "/mnt/hdd-data/repo/test"], true),
117-
(&["/usr/share", "/mnt/ssd-data/test"], false),
118-
(
119-
&["/etc/fstab", "/home/user", "/mnt/hdd-data", "/usr/share"],
120-
true,
121-
),
122-
];
123-
124-
for (paths, in_hdd) in cases {
125-
let paths: Vec<_> = paths.iter().map(PathBuf::from).collect();
126-
println!("CASE: {paths:?} → {in_hdd:?}");
127-
assert_eq!(any_path_is_in_hdd::<MockedApi>(&paths, disks), *in_hdd);
128-
}
129-
}
130-
131-
#[test]
132-
fn test_path_in_hdd() {
133-
let disks = &[
134-
Disk::new(DiskKind::SSD, "/"),
135-
Disk::new(DiskKind::HDD, "/home"),
136-
Disk::new(DiskKind::HDD, "/mnt/hdd-data"),
137-
Disk::new(DiskKind::SSD, "/mnt/ssd-data"),
138-
Disk::new(DiskKind::HDD, "/mnt/hdd-data/repo"),
139-
];
140-
141-
for (path, in_hdd) in [
142-
("/etc/fstab", false),
143-
("/mnt/", false),
144-
("/mnt/hdd-data/repo/test", true),
145-
("/mnt/hdd-data/test/test", true),
146-
("/mnt/ssd-data/test/test", false),
147-
] {
148-
println!("CASE: {path} → {in_hdd:?}");
149-
assert_eq!(path_is_in_hdd::<MockedApi>(Path::new(path), disks), in_hdd);
150-
}
151-
}
152-
}
55+
mod test;

src/app/hdd/test.rs

Lines changed: 96 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,96 @@
1+
use super::{any_path_is_in_hdd, path_is_in_hdd, Api};
2+
use pipe_trait::Pipe;
3+
use pretty_assertions::assert_eq;
4+
use std::path::{Path, PathBuf};
5+
use sysinfo::DiskKind;
6+
7+
/// Fake disk for [`Api`].
8+
struct Disk {
9+
kind: DiskKind,
10+
mount_point: &'static str,
11+
}
12+
13+
impl Disk {
14+
fn new(kind: DiskKind, mount_point: &'static str) -> Self {
15+
Self { kind, mount_point }
16+
}
17+
}
18+
19+
/// Mocked implementation of [`Api`] for testing purposes.
20+
struct MockedApi;
21+
impl Api for MockedApi {
22+
type Disk = Disk;
23+
24+
fn get_disk_kind(disk: &Self::Disk) -> DiskKind {
25+
disk.kind
26+
}
27+
28+
fn get_mount_point(disk: &Self::Disk) -> &Path {
29+
Path::new(disk.mount_point)
30+
}
31+
32+
fn canonicalize(path: &Path) -> std::io::Result<PathBuf> {
33+
path.to_path_buf().pipe(Ok)
34+
}
35+
}
36+
37+
#[test]
38+
fn test_any_path_in_hdd() {
39+
let disks = &[
40+
Disk::new(DiskKind::SSD, "/"),
41+
Disk::new(DiskKind::HDD, "/home"),
42+
Disk::new(DiskKind::HDD, "/mnt/hdd-data"),
43+
Disk::new(DiskKind::SSD, "/mnt/ssd-data"),
44+
Disk::new(DiskKind::HDD, "/mnt/hdd-data/repo"),
45+
];
46+
47+
let cases: &[(&[&str], bool)] = &[
48+
(&[], false),
49+
(&["/"], false),
50+
(&["/home"], true),
51+
(&["/mnt"], false),
52+
(&["/mnt/ssd-data"], false),
53+
(&["/mnt/hdd-data"], true),
54+
(&["/mnt/hdd-data/repo"], true),
55+
(&["/etc/fstab"], false),
56+
(&["/home/usr/file"], true),
57+
(&["/home/data/repo/test"], true),
58+
(&["/usr/share"], false),
59+
(&["/mnt/ssd-data/test"], false),
60+
(&["/etc/fstab", "/home/user/file"], true),
61+
(&["/mnt/hdd-data/file", "/mnt/hdd-data/repo/test"], true),
62+
(&["/usr/share", "/mnt/ssd-data/test"], false),
63+
(
64+
&["/etc/fstab", "/home/user", "/mnt/hdd-data", "/usr/share"],
65+
true,
66+
),
67+
];
68+
69+
for (paths, in_hdd) in cases {
70+
let paths: Vec<_> = paths.iter().map(PathBuf::from).collect();
71+
println!("CASE: {paths:?} → {in_hdd:?}");
72+
assert_eq!(any_path_is_in_hdd::<MockedApi>(&paths, disks), *in_hdd);
73+
}
74+
}
75+
76+
#[test]
77+
fn test_path_in_hdd() {
78+
let disks = &[
79+
Disk::new(DiskKind::SSD, "/"),
80+
Disk::new(DiskKind::HDD, "/home"),
81+
Disk::new(DiskKind::HDD, "/mnt/hdd-data"),
82+
Disk::new(DiskKind::SSD, "/mnt/ssd-data"),
83+
Disk::new(DiskKind::HDD, "/mnt/hdd-data/repo"),
84+
];
85+
86+
for (path, in_hdd) in [
87+
("/etc/fstab", false),
88+
("/mnt/", false),
89+
("/mnt/hdd-data/repo/test", true),
90+
("/mnt/hdd-data/test/test", true),
91+
("/mnt/ssd-data/test/test", false),
92+
] {
93+
println!("CASE: {path} → {in_hdd:?}");
94+
assert_eq!(path_is_in_hdd::<MockedApi>(Path::new(path), disks), in_hdd);
95+
}
96+
}

src/app/mount_point.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ pub fn find_mount_point<'a>(
1212
}
1313

1414
#[cfg(test)]
15-
mod tests {
15+
mod test {
1616
use super::find_mount_point;
1717
use pretty_assertions::assert_eq;
1818
use std::path::Path;

0 commit comments

Comments
 (0)