Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Figure out how to test set_time #4

Closed
schneiderchristopher opened this issue Jan 30, 2023 · 2 comments
Closed

Figure out how to test set_time #4

schneiderchristopher opened this issue Jan 30, 2023 · 2 comments
Labels
good first issue Good for newcomers

Comments

@schneiderchristopher
Copy link
Owner

schneiderchristopher commented Jan 30, 2023

For now I can't test this function the way it is implement as I can't create a Metadata struct since its private.

lsr/src/path/paths.rs

Lines 64 to 81 in 01888b4

fn set_time(metadata: Metadata) -> Result<String, Error> {
if let Ok(sys_time) = metadata.modified() {
if let Ok(duration) = sys_time.duration_since(UNIX_EPOCH) {
if let Some(time) =
NaiveDateTime::from_timestamp_millis(duration.as_millis() as i64)
{
Ok(time.format("%e %b %R").to_string())
} else {
panic!("Could not get time from milliseconds")
}
} else {
panic!("Time must gone backwards!")
}
} else {
panic!("Not implement in this platform")
}
}
}

@schneiderchristopher schneiderchristopher added the good first issue Good for newcomers label Jan 30, 2023
@zihadmahiuddin
Copy link
Contributor

zihadmahiuddin commented Jan 30, 2023

I think instead of using Metadata you can use SystemTime and replace metadata with metadata.modified() where you call this function.
Then when testing, you can add a Duration to SystemTime::UNIX_EPOCH to get a specific time that you want to test with.
What do you think?

@schneiderchristopher
Copy link
Owner Author

Thanks! That was perfect.
Fixed on 8c551cc

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
good first issue Good for newcomers
Projects
None yet
Development

No branches or pull requests

2 participants