summaryrefslogtreecommitdiff
path: root/src/package_manager
diff options
context:
space:
mode:
authorStevan Andjelkovic <stevan@advancedtelematic.com>2016-04-04 14:01:46 +0200
committerStevan Andjelkovic <stevan@advancedtelematic.com>2016-04-04 14:12:16 +0200
commit6a3a3d9a105de838dbf6bb55de73433ace0bacd7 (patch)
treec416f77ac6c50b396ee95027c221b6a10c9cebb1 /src/package_manager
parenta18de475a6e61f444049ccf80c08262601bc3431 (diff)
downloadrvi_sota_client-6a3a3d9a105de838dbf6bb55de73433ace0bacd7.tar.gz
Clean up the code in the tests a wee bit.
Diffstat (limited to 'src/package_manager')
-rw-r--r--src/package_manager/tpm.rs71
1 files changed, 27 insertions, 44 deletions
diff --git a/src/package_manager/tpm.rs b/src/package_manager/tpm.rs
index 9358466..0aef2dc 100644
--- a/src/package_manager/tpm.rs
+++ b/src/package_manager/tpm.rs
@@ -56,12 +56,10 @@ impl PackageManager for Tpm {
.open(config.packages_dir.clone() +
&config.package_manager.extension()));
- {
- let mut writer = BufWriter::new(f);
+ let mut writer = BufWriter::new(f);
- try!(writer.write(pkg.as_bytes()));
- try!(writer.write(b"\n"));
- }
+ try!(writer.write(pkg.as_bytes()));
+ try!(writer.write(b"\n"));
return Ok(())
@@ -97,30 +95,34 @@ mod tests {
}
}
- fn package_manager(s: &str) -> PackageManager {
- PackageManager::File(s.to_string())
+ fn make_config(file: &str) -> OtaConfig {
+
+ let packages_dir = "/tmp/".to_string();
+ let package_manager = PackageManager::File(file.to_string());
+
+ let mut config = OtaConfig::default();
+
+ config = OtaConfig {
+ packages_dir: packages_dir,
+ package_manager: package_manager,
+ .. config
+ };
+
+ return config
+
}
#[test]
fn test_installed_packages() {
- const PACKAGES_DIR: &'static str = "/tmp/";
- let package_manager = package_manager("test1");
+ let config = make_config("test1");
- let mut f = File::create(PACKAGES_DIR.to_string() +
- &package_manager.extension()).unwrap();
+ let mut f = File::create(config.packages_dir.clone() +
+ &config.package_manager.extension()).unwrap();
f.write(b"apa 0.0.0\n").unwrap();
f.write(b"bepa 1.0.0").unwrap();
- let mut config = OtaConfig::default();
-
- config = OtaConfig {
- packages_dir: PACKAGES_DIR.to_string(),
- package_manager: package_manager,
- .. config
- };
-
assert_eq!(Tpm.installed_packages(&config).unwrap(), vec!(pkg1(), pkg2()));
}
@@ -128,23 +130,13 @@ mod tests {
#[test]
fn bad_installed_packages() {
+ let config = make_config("test2");
- const PACKAGES_DIR: &'static str = "/tmp/";
- let package_manager = package_manager("test2");
-
- let mut f = File::create(PACKAGES_DIR.to_string() +
- &package_manager.extension()).unwrap();
+ let mut f = File::create(config.packages_dir.clone() +
+ &config.package_manager.extension()).unwrap();
f.write(b"cepa-2.0.0\n").unwrap();
- let mut config = OtaConfig::default();
-
- config = OtaConfig {
- packages_dir: PACKAGES_DIR.to_string(),
- package_manager: package_manager,
- .. config
- };
-
assert_eq!(Tpm.installed_packages(&config).unwrap(), Vec::new());
}
@@ -152,19 +144,10 @@ mod tests {
#[test]
fn test_install_package() {
- const PACKAGES_DIR: &'static str = "/tmp/";
- let package_manager = package_manager("test3");
-
- let _ = fs::remove_file(PACKAGES_DIR.to_string() +
- &package_manager.extension());
-
- let mut config = OtaConfig::default();
+ let config = make_config("test3");
- config = OtaConfig {
- packages_dir: "/tmp/".to_string(),
- package_manager: package_manager,
- .. config
- };
+ let _ = fs::remove_file(config.packages_dir.to_string() +
+ &config.package_manager.extension());
Tpm.install_package(&config, "apa 0.0.0").unwrap();
Tpm.install_package(&config, "bepa 1.0.0").unwrap();