Skip to content

Commit

Permalink
add tests, cleanup
Browse files Browse the repository at this point in the history
  • Loading branch information
bryanoltman committed May 21, 2024
1 parent 7bb7968 commit 6b7f951
Show file tree
Hide file tree
Showing 2 changed files with 41 additions and 4 deletions.
5 changes: 1 addition & 4 deletions library/src/cache/patch_manager.rs
Original file line number Diff line number Diff line change
Expand Up @@ -238,11 +238,8 @@ impl PatchManager {
.clone()
.context("Patch signature is missing")?;

Check warning on line 239 in library/src/cache/patch_manager.rs

View check run for this annotation

Codecov / codecov/patch

library/src/cache/patch_manager.rs#L236-L239

Added lines #L236 - L239 were not covered by tests

// and that the signature is valid.
// Check that the signature is valid.
let patch_hash = hash_file(&artifact_path)?;
// info!("patch hash is {}", patch.hash);
// info!("hash digest is {}", hex::encode(hash));
// info!("hashes match? {}", hex::encode(hash) == patch.hash);
check_signature(&patch_hash, &patch_signature, public_key)?;

Check warning on line 243 in library/src/cache/patch_manager.rs

View check run for this annotation

Codecov / codecov/patch

library/src/cache/patch_manager.rs#L242-L243

Added lines #L242 - L243 were not covered by tests
}

Expand Down
40 changes: 40 additions & 0 deletions library/src/config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -220,4 +220,44 @@ mod tests {
let config = super::with_config(|config| Ok(config.clone())).unwrap();
assert_eq!(config.libapp_path.to_str(), Some("first_path"));
}

#[serial]
#[test]
fn set_config_correctly_sets_values() {
testing_reset_config();

set_config(
AppConfig {
app_storage_dir: "/app_storage".to_string(),
code_cache_dir: "/code_cache".to_string(),
release_version: "1.0.0".to_string(),
original_libapp_paths: vec!["libapp.so".to_string()],
},
Box::new(FakeExternalFileProvider {}),
"first_path".into(),
&crate::yaml::YamlConfig {
app_id: "fake_app_id".to_string(),
channel: Some("fake_channel".to_string()),
auto_update: Some(true),
base_url: Some("fake_base_url".to_string()),
patch_public_key: Some("patch_public_key".to_string()),
},
NetworkHooks::default(),
);

let config = super::with_config(|config| Ok(config.clone())).unwrap();
assert_eq!(config.storage_dir.to_str(), Some("/app_storage"));
assert_eq!(config.download_dir.to_str(), Some("/code_cache/downloads"));
assert!(config.auto_update);
assert_eq!(config.channel, "fake_channel");
assert_eq!(config.app_id, "fake_app_id");
assert_eq!(config.release_version, "1.0.0");
assert_eq!(config.libapp_path.to_str(), Some("first_path"));
assert_eq!(config.base_url, "fake_base_url");
// We should also validate network hooks here
assert_eq!(
config.patch_public_key,
Some("patch_public_key".to_string())
);
}
}

0 comments on commit 6b7f951

Please sign in to comment.