Skip to content

Conversation

zizixcm
Copy link
Contributor

@zizixcm zizixcm commented Sep 18, 2022

Resolves #83

Refactored ToolInfo.select_asset(&assets) to return a custom AssetError error instead of a string and added tests for the function.

The AssetError enum has two possible values:

  • NameUnknown: this is when AssetName does not know what the asset name is for a specific OS the user uses.
  • NotFound: this is when the AssetName is not in the Assets slice passed into the select_asset(&assets) method.

Implemented std::fmt::Display trait for AssetError and added tests for it.

Additional tasks

  • Documentation for changes provided/changed
  • Tests added

Copy link
Owner

@chshersh chshersh left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Awesome refactoring! 👏🏻

I left a few comments with improvements. Happy to merge when they are addressed 🙂

@@ -103,7 +103,7 @@ store_directory = "~/.local/bin"
By default `tool-sync` reads configuration from `$HOME/.tool.toml` you can run `tool
default-config` to print a default configuration example to std out. You can
redirect this out put to a file like so `tool default-config >
$HOME/.tools.toml`.
$HOME/.tool.toml`.
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for the documentation fix! 🙏🏻

Comment on lines 42 to 52
#[cfg(test)]
mod tests {
use super::*;

#[test]
fn display_asset_error() {
let asset_name = "test_asset";
let error_str = AssetError::NotFound(asset_name.to_string()).to_string();
assert_ne!(error_str.find(asset_name), None);
}
}
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Let's remove this test. It doesn't test much so there's no need to maintain it

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

agree, testing error messages is generally brittle

Comment on lines 19 to 23
/// Asset name of this OS is unknown
NameUnknown,

/// Asset name is not in the fetched assets
NotFound(String),
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

NameUnknown and NotFound sounds too similar in a semantic sense to me. I could switch those two names and enum still would make sense to me (both OS and Asset name can be either unknown or not found).

In this context, NotFound is fine but let's rename NameUnknown to OsSelectorUnknown. Just to give some connection to the fact that it's more related to OS configuration and not the asset name in the list of assets.

Copy link
Contributor Author

@zizixcm zizixcm Sep 18, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

yeah I struggled with naming these two errors, OsSelectorUnknown makes sense

Comment on lines +111 to +113
#[cfg(test)]
mod tests {
use super::*;
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Great work on tests! 👏🏻

Let's also add one more test for the OsSelectorUknown constructor 👍🏻

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

good catch. added

Copy link
Owner

@chshersh chshersh left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks amazing! 👏🏻

Thanks a lot for your contribution, @zixuanzhang-x 🤗

@chshersh chshersh merged commit 1dcd1e7 into chshersh:main Sep 18, 2022
@zizixcm zizixcm deleted the assert_error branch September 18, 2022 22:39
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Create 'AssetError' and test 'select_asset' function
2 participants