Skip to content

Commit

Permalink
Replace implicit cache folder with --package-folder arg
Browse files Browse the repository at this point in the history
  • Loading branch information
Serock3 committed Jul 18, 2024
1 parent 542bdf7 commit d5bd432
Show file tree
Hide file tree
Showing 4 changed files with 27 additions and 23 deletions.
4 changes: 2 additions & 2 deletions test/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -116,7 +116,7 @@ cargo run --bin test-manager run-tests debian11 \
--display \
--account 0123456789 \
--current-app <git hash or tag> \
--previous-app 2023.2
--old-app 2023.2
```

## macOS
Expand All @@ -142,7 +142,7 @@ cargo run --bin test-manager run-tests macos-ventura \
--display \
--account 0123456789 \
--current-app <git hash or tag> \
--previous-app 2023.2
--old-app 2023.2
```

## Note on `ci-runtests.sh`
Expand Down
3 changes: 2 additions & 1 deletion test/ci-runtests.sh
Original file line number Diff line number Diff line change
Expand Up @@ -198,7 +198,8 @@ function run_tests_for_os {
run-tests \
--account "${ACCOUNT_TOKEN:?Error: ACCOUNT_TOKEN not set}" \
--current-app "${cur_filename}" \
--previous-app "${prev_filename}" \
--old-app "${prev_filename}" \
--package-folder "$PACKAGES_DIR" \
--test-report "$SCRIPT_DIR/.ci-logs/${os}_report" \
"$os" 2>&1 | sed "s/${ACCOUNT_TOKEN}/\{ACCOUNT_TOKEN\}/g"
}
Expand Down
26 changes: 13 additions & 13 deletions test/test-manager/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -80,14 +80,8 @@ enum Commands {
account: String,

/// App package to test. Can be a path to the package, just the package file name, git hash
/// or tag. If the direct path is not given, the package is assumed to be in the cache
/// directory for the host OS, given by the following table:
///
/// |Platform | Value | Example |
/// | ------- | ----------------------------------- | ---------------------------- |
/// | Linux | `$XDG_CACHE_HOME` or `$HOME`/.cache | /home/alice/.cache |
/// | macOS | `$HOME`/Library/Caches | /Users/Alice/Library/Caches |
/// | Windows | `{FOLDERID_LocalAppData}` | C:\Users\Alice\AppData\Local |
/// or tag. If the direct path is not given, the package is assumed to be in the directory
/// specified by the `--package-folder` argument.
///
/// # Note
///
Expand All @@ -103,7 +97,11 @@ enum Commands {
///
/// The CLI interface must be compatible with the upgrade test.
#[arg(long, short)]
previous_app: Option<String>,
old_app: Option<String>,

/// Folder to search for packages. Defaults to current directory.
#[arg(short, long, value_name = "DIR")]
package_folder: Option<PathBuf>,

/// Only run tests matching substrings
test_filters: Vec<String>,
Expand Down Expand Up @@ -227,7 +225,8 @@ async fn main() -> Result<()> {
vnc,
account,
current_app,
previous_app,
old_app,
package_folder,
test_filters,
verbose,
test_report,
Expand Down Expand Up @@ -261,9 +260,10 @@ async fn main() -> Result<()> {
None => None,
};

let manifest = package::get_app_manifest(vm_config, current_app, previous_app)
.await
.context("Could not find the specified app packages")?;
let manifest =
package::get_app_manifest(vm_config, current_app, old_app, package_folder)
.await
.context("Could not find the specified app packages")?;

let mut instance = vm::run(&config, &name)
.await
Expand Down
17 changes: 10 additions & 7 deletions test/test-manager/src/package.rs
Original file line number Diff line number Diff line change
Expand Up @@ -23,15 +23,17 @@ pub async fn get_app_manifest(
config: &VmConfig,
current_app: String,
previous_app: Option<String>,
package_folder: Option<PathBuf>,
) -> Result<Manifest> {
let package_type = (config.os_type, config.package_type, config.architecture);

let current_app_path = find_app(&current_app, false, package_type).await?;
let current_app_path =
find_app(&current_app, false, package_type, package_folder.as_ref()).await?;
log::info!("Current app: {}", current_app_path.display());

let previous_app_path = if let Some(previous_app) = previous_app {
log::info!("Previous app: {}", previous_app);
Some(find_app(&previous_app, false, package_type).await?)
Some(find_app(&previous_app, false, package_type, package_folder.as_ref()).await?)
} else {
log::warn!("No previous app version specified");
None
Expand All @@ -44,7 +46,9 @@ pub async fn get_app_manifest(
.map(|c| c.as_str())
.expect("Could not parse version from package name: {current_app}");

let ui_e2e_tests_path = find_app(capture, true, package_type).await.ok();
let ui_e2e_tests_path = find_app(capture, true, package_type, package_folder.as_ref())
.await
.ok();
if let Some(ui_e2e_tests_path) = &ui_e2e_tests_path {
log::info!("GUI e2e test binary: {}", ui_e2e_tests_path.display());
} else {
Expand All @@ -62,6 +66,7 @@ async fn find_app(
app: &str,
e2e_bin: bool,
package_type: (OsType, Option<PackageType>, Option<Architecture>),
package_folder: Option<&PathBuf>,
) -> Result<PathBuf> {
// If it's a path, use that path
let app_path = Path::new(app);
Expand All @@ -73,10 +78,8 @@ async fn find_app(
let mut app = app.to_owned();
app.make_ascii_lowercase();

let packages_dir = dirs::cache_dir()
.context("Could not find cache directory")?
.join("mullvad-test")
.join("packages");
let current_dir = std::env::current_dir().expect("Unable to get current directory");
let packages_dir = package_folder.unwrap_or(&current_dir);
fs::create_dir_all(&packages_dir).await?;
let mut dir = fs::read_dir(packages_dir.clone())
.await
Expand Down

0 comments on commit d5bd432

Please sign in to comment.