Skip to content

Commit

Permalink
refactor: use public APIs
Browse files Browse the repository at this point in the history
  • Loading branch information
ho-229 committed Mar 25, 2024
1 parent db6493b commit e0967c3
Showing 1 changed file with 13 additions and 15 deletions.
28 changes: 13 additions & 15 deletions bin/ofs/tests/common/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -15,44 +15,42 @@
// specific language governing permissions and limitations
// under the License.

use std::{
collections::HashMap,
env,
process::{Child, Command},
};
use std::{collections::HashMap, env, process::Command};

use assert_cmd::cargo::CommandCargoExt;
use tempfile::TempDir;
use test_context::AsyncTestContext;
use tokio::task::JoinHandle;

pub(crate) struct OfsTestContext {
pub mount_point: TempDir,
pub ofs_process: Child,
ofs_task: JoinHandle<anyhow::Result<()>>,
}

impl AsyncTestContext for OfsTestContext {
async fn setup() -> Self {
let backend = backend_scheme().unwrap();

let mount_point = tempfile::tempdir().unwrap();
let cmd = Command::cargo_bin("ofs")
.unwrap()
.args([mount_point.path().to_str().unwrap(), &backend])
.spawn()
.unwrap();

let ofs_task = tokio::spawn(ofs::execute(ofs::Config {
mount_path: mount_point.path().to_string_lossy().to_string(),
backend: backend.parse().unwrap(),
}));

OfsTestContext {
mount_point,
ofs_process: cmd,
ofs_task,
}
}

async fn teardown(mut self) {
async fn teardown(self) {
// FIXME: ofs could not unmount
Command::new("fusermount3")
.args(["-u", self.mount_point.path().to_str().unwrap()])
.output()
.unwrap();
self.ofs_process.kill().unwrap();

self.ofs_task.abort();
self.mount_point.close().unwrap();
}
}
Expand Down

0 comments on commit e0967c3

Please sign in to comment.