-
-
Notifications
You must be signed in to change notification settings - Fork 9
Copilot/analyze test coverage #79
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
Merged
Merged
Changes from all commits
Commits
Show all changes
6 commits
Select commit
Hold shift + click to select a range
43b78e4
Add comprehensive unit tests for untested modules
Copilot 18e90e5
Add env_lock() mutex guards to scopes and version_check tests
Copilot 076f1a6
Initial plan
Copilot c2f54e0
Fix env var state leakage in tests using Drop-based EnvGuard
Copilot 5116081
Merge pull request #80 from trydirect/copilot/sub-pr-79
vsilent 8910642
Apply cargo fmt --all and cargo clippy fixes
Copilot File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -34,3 +34,62 @@ pub async fn check_remote_version() -> Result<Option<RemoteVersion>> { | |
| .context("parsing remote version response")?; | ||
| Ok(Some(rv)) | ||
| } | ||
|
|
||
| #[cfg(test)] | ||
| mod tests { | ||
| use super::*; | ||
| use crate::test_utils::EnvGuard; | ||
| use std::sync::{Mutex, OnceLock}; | ||
|
|
||
| fn env_lock() -> &'static Mutex<()> { | ||
| static LOCK: OnceLock<Mutex<()>> = OnceLock::new(); | ||
| LOCK.get_or_init(|| Mutex::new(())) | ||
| } | ||
|
|
||
| #[test] | ||
| fn remote_version_deserialize_with_checksum() { | ||
| let json = r#"{"version": "1.2.3", "checksum": "abc123"}"#; | ||
| let rv: RemoteVersion = serde_json::from_str(json).unwrap(); | ||
| assert_eq!(rv.version, "1.2.3"); | ||
| assert_eq!(rv.checksum, Some("abc123".to_string())); | ||
| } | ||
|
|
||
| #[test] | ||
| fn remote_version_deserialize_without_checksum() { | ||
| let json = r#"{"version": "1.2.3"}"#; | ||
| let rv: RemoteVersion = serde_json::from_str(json).unwrap(); | ||
| assert_eq!(rv.version, "1.2.3"); | ||
| assert_eq!(rv.checksum, None); | ||
| } | ||
|
|
||
| #[test] | ||
| fn remote_version_deserialize_null_checksum() { | ||
| let json = r#"{"version": "0.1.0", "checksum": null}"#; | ||
| let rv: RemoteVersion = serde_json::from_str(json).unwrap(); | ||
| assert_eq!(rv.version, "0.1.0"); | ||
| assert_eq!(rv.checksum, None); | ||
| } | ||
|
|
||
| #[test] | ||
| fn remote_version_deserialize_missing_version_fails() { | ||
| let json = r#"{"checksum": "abc"}"#; | ||
| let result: std::result::Result<RemoteVersion, _> = serde_json::from_str(json); | ||
| assert!(result.is_err()); | ||
| } | ||
|
|
||
| #[tokio::test] | ||
| async fn check_remote_version_no_env_returns_none() { | ||
| let _lock = env_lock().lock().expect("env lock poisoned"); | ||
| let _env = EnvGuard::remove("UPDATE_SERVER_URL"); | ||
| let result = check_remote_version().await.unwrap(); | ||
| assert!(result.is_none()); | ||
| } | ||
|
|
||
| #[tokio::test] | ||
| async fn check_remote_version_empty_env_returns_none() { | ||
| let _lock = env_lock().lock().expect("env lock poisoned"); | ||
| let _env = EnvGuard::set("UPDATE_SERVER_URL", ""); | ||
| let result = check_remote_version().await.unwrap(); | ||
| assert!(result.is_none()); | ||
| } | ||
|
Comment on lines
+80
to
+94
|
||
| } | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
These tests set/remove
UPDATE_STORAGE_PATHbut don’t restore any pre-existing value, which can leak state into other tests (or affect local runs when the env var is set). Save the original value before mutation and restore it in aDropguard so cleanup happens even if an assertion fails.