mirror of
https://chromium.googlesource.com/crosvm/crosvm
synced 2025-02-09 20:04:20 +00:00
Cargo already uses the term 'integration test' for tests living in the tests/ directory of a crate. To prevent confusion, rename our 'integration_tests' crate to 'e2e_tests'. BUG=None TEST=presubmit Change-Id: Icfa819eaed08be54ab0f36092f1ba367f3f1ce88 Reviewed-on: https://chromium-review.googlesource.com/c/crosvm/crosvm/+/4004977 Commit-Queue: Dennis Kempin <denniskempin@google.com> Reviewed-by: Zihan Chen <zihanchen@google.com>
62 lines
2 KiB
Rust
62 lines
2 KiB
Rust
// Copyright 2022 The ChromiumOS Authors
|
|
// Use of this source code is governed by a BSD-style license that can be
|
|
// found in the LICENSE file.
|
|
|
|
use std::env;
|
|
|
|
use prebuilts::download_prebuilt;
|
|
use prebuilts::download_prebuilts;
|
|
use tempfile::TempDir;
|
|
|
|
static LIBRARY: &str = "prebuilts_test";
|
|
static PREBUILT_FILE1: &str = "prebuilt_test";
|
|
static PREBUILT_FILE2: &str = "prebuilt_test2";
|
|
static VERSION: u32 = 1;
|
|
|
|
fn setup_env(build_type: &str) -> TempDir {
|
|
let tempdir = tempfile::tempdir().unwrap();
|
|
if build_type == "debug" {
|
|
env::set_var("DEBUG", "");
|
|
} else {
|
|
env::remove_var("DEBUG");
|
|
}
|
|
env::set_var("CARGO_CFG_TARGET_FAMILY", "windows");
|
|
env::set_var("CARGO_CFG_TARGET_ARCH", "x86_64");
|
|
env::set_var("CARGO_CFG_TARGET_ENV", "gnu");
|
|
let deps = tempdir.path().join("deps");
|
|
std::fs::create_dir_all(&deps).unwrap();
|
|
let out_dir = tempdir.path().join("build").join("crate_name").join("out");
|
|
std::fs::create_dir_all(&out_dir).unwrap();
|
|
env::set_var("OUT_DIR", out_dir.as_os_str().to_str().unwrap());
|
|
tempdir
|
|
}
|
|
|
|
#[test]
|
|
fn test_download_prebuilt() {
|
|
for build_type in ["release", "debug"] {
|
|
let _tempdir = setup_env(build_type);
|
|
let file = download_prebuilt(LIBRARY, VERSION, PREBUILT_FILE1).unwrap();
|
|
assert!(file.exists());
|
|
assert_eq!(
|
|
std::fs::read_to_string(&file).unwrap(),
|
|
format!("hello world {}\n", build_type)
|
|
);
|
|
}
|
|
}
|
|
|
|
#[test]
|
|
fn test_download_prebuilt_files() {
|
|
for build_type in ["release", "debug"] {
|
|
let _tempdir = setup_env(build_type);
|
|
let files =
|
|
download_prebuilts(LIBRARY, VERSION, &[PREBUILT_FILE1, PREBUILT_FILE2]).unwrap();
|
|
for file in files {
|
|
assert!(file.exists());
|
|
assert_eq!(
|
|
std::fs::read_to_string(&file).unwrap(),
|
|
format!("hello world {}\n", build_type),
|
|
"failed for file {file:?}"
|
|
);
|
|
}
|
|
}
|
|
}
|