You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@opendal.apache.org by xu...@apache.org on 2024/04/09 04:43:51 UTC
(opendal) branch main updated: feat(bin/ofs): Add behavior test for ofs (#4373)
This is an automated email from the ASF dual-hosted git repository.
xuanwo pushed a commit to branch main
in repository https://gitbox.apache.org/repos/asf/opendal.git
The following commit(s) were added to refs/heads/main by this push:
new 333029cf96 feat(bin/ofs): Add behavior test for ofs (#4373)
333029cf96 is described below
commit 333029cf96b8df1a19ef6db5e3333d988e8a62a9
Author: Ho 229 <ho...@gmail.com>
AuthorDate: Tue Apr 9 12:43:46 2024 +0800
feat(bin/ofs): Add behavior test for ofs (#4373)
* test: ofs
* ci: setup ofs behavior test
* refactor: use public APIs
* fix: make clippy happy
* chore: remove unused dep
---
.github/actions/test_behavior_bin_ofs/action.yaml | 49 ++++++++++
.github/scripts/test_behavior/plan.py | 40 +++++++-
.github/workflows/test_behavior.yml | 13 +++
.github/workflows/test_behavior_bin_ofs.yml | 61 +++++++++++++
bin/ofs/Cargo.lock | 106 ++++++++++++++++++++++
bin/ofs/Cargo.toml | 7 ++
bin/ofs/tests/common/mod.rs | 88 ++++++++++++++++++
bin/ofs/tests/file.rs | 91 +++++++++++++++++++
bin/ofs/tests/path.rs | 73 +++++++++++++++
9 files changed, 527 insertions(+), 1 deletion(-)
diff --git a/.github/actions/test_behavior_bin_ofs/action.yaml b/.github/actions/test_behavior_bin_ofs/action.yaml
new file mode 100644
index 0000000000..fe0e957bd9
--- /dev/null
+++ b/.github/actions/test_behavior_bin_ofs/action.yaml
@@ -0,0 +1,49 @@
+# Licensed to the Apache Software Foundation (ASF) under one
+# or more contributor license agreements. See the NOTICE file
+# distributed with this work for additional information
+# regarding copyright ownership. The ASF licenses this file
+# to you under the Apache License, Version 2.0 (the
+# "License"); you may not use this file except in compliance
+# with the License. You may obtain a copy of the License at
+#
+# http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing,
+# software distributed under the License is distributed on an
+# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+# KIND, either express or implied. See the License for the
+# specific language governing permissions and limitations
+# under the License.
+
+name: Test Ofs
+description: 'Test Ofs with given setup and service'
+inputs:
+ setup:
+ description: "The setup action for test"
+ service:
+ description: "The service to test"
+ feature:
+ description: "The feature to test"
+
+runs:
+ using: "composite"
+ steps:
+ - name: Setup
+ shell: bash
+ run: |
+ mkdir -p ./dynamic_test_bin_ofs &&
+ cat <<EOF >./dynamic_test_bin_ofs/action.yml
+ runs:
+ using: composite
+ steps:
+ - name: Setup Test
+ uses: ./.github/services/${{ inputs.service }}/${{ inputs.setup }}
+ - name: Run Test Ofs
+ shell: bash
+ working-directory: bin/ofs
+ run: cargo test --features ${{ inputs.feature }} --no-default-features
+ env:
+ OPENDAL_TEST: ${{ inputs.service }}
+ EOF
+ - name: Run
+ uses: ./dynamic_test_bin_ofs
diff --git a/.github/scripts/test_behavior/plan.py b/.github/scripts/test_behavior/plan.py
index a159c5571c..436bda51d4 100755
--- a/.github/scripts/test_behavior/plan.py
+++ b/.github/scripts/test_behavior/plan.py
@@ -33,6 +33,7 @@ PROJECT_DIR = GITHUB_DIR.parent
LANGUAGE_BINDING = ["java", "python", "nodejs"]
+BIN = ["ofs"]
def provided_cases() -> list[dict[str, str]]:
root_dir = f"{GITHUB_DIR}/services"
@@ -82,6 +83,8 @@ class Hint:
binding_python: bool = field(default=False, init=False)
# Is binding nodejs affected?
binding_nodejs: bool = field(default=False, init=False)
+ # Is bin ofs affected?
+ bin_ofs: bool = field(default=False, init=False)
# Should we run all services test?
all_service: bool = field(default=False, init=False)
@@ -137,6 +140,8 @@ def calculate_hint(changed_files: list[str]) -> Hint:
hint.core = True
for language in LANGUAGE_BINDING:
setattr(hint, f"binding_{language}", True)
+ for bin in BIN:
+ setattr(hint, f"bin_{bin}", True)
hint.services.add(match.group(1))
# core test affected
@@ -145,6 +150,8 @@ def calculate_hint(changed_files: list[str]) -> Hint:
hint.core = True
for language in LANGUAGE_BINDING:
setattr(hint, f"binding_{language}", True)
+ for bin in BIN:
+ setattr(hint, f"bin_{bin}", True)
hint.services.add(match.group(1))
# fixture affected
@@ -153,7 +160,14 @@ def calculate_hint(changed_files: list[str]) -> Hint:
hint.core = True
for language in LANGUAGE_BINDING:
setattr(hint, f"binding_{language}", True)
+ for bin in BIN:
+ setattr(hint, f"bin_{bin}", True)
hint.services.add(match.group(1))
+
+ # bin affected
+ for bin in BIN:
+ if p.startswith(f"bin/{bin}"):
+ setattr(hint, f"bin_{bin}", True)
return hint
@@ -206,7 +220,7 @@ def generate_language_binding_cases(
if os.getenv("GITHUB_IS_PUSH") == "true":
return cases
- # Return empty if core is False
+ # Return empty if this binding is False
if not getattr(hint, f"binding_{language}"):
return []
@@ -218,6 +232,23 @@ def generate_language_binding_cases(
cases = [v for v in cases if v["service"] in hint.services]
return cases
+def generate_bin_cases(
+ cases: list[dict[str, str]], hint: Hint, bin: str
+) -> list[dict[str, str]]:
+ cases = unique_cases(cases)
+
+ if bin == "ofs":
+ hint.services.add("fs")
+ hint.services.add("s3")
+
+ # Return empty if this bin is False
+ if not getattr(hint, f"bin_{bin}"):
+ return []
+
+ # Filter all cases that not shown un in changed files
+ cases = [v for v in cases if v["service"] in hint.services]
+ return cases
+
def plan(changed_files: list[str]) -> dict[str, Any]:
cases = provided_cases()
@@ -254,6 +285,13 @@ def plan(changed_files: list[str]) -> dict[str, Any]:
jobs["components"][f"binding_{language}"] = True
jobs[f"binding_{language}"].append({"os": "ubuntu-latest", "cases": cases})
+ for bin in BIN:
+ jobs[f"bin_{bin}"] = []
+ jobs["components"][f"bin_{bin}"] = False
+ cases = generate_bin_cases(cases, hint, bin)
+ if len(cases) > 0:
+ jobs["components"][f"bin_{bin}"] = True
+ jobs[f"bin_{bin}"].append({"os": "ubuntu-latest", "cases": cases})
return jobs
diff --git a/.github/workflows/test_behavior.yml b/.github/workflows/test_behavior.yml
index 57918c6410..4f53ea9abf 100644
--- a/.github/workflows/test_behavior.yml
+++ b/.github/workflows/test_behavior.yml
@@ -132,3 +132,16 @@ jobs:
with:
os: ${{ matrix.os }}
cases: ${{ toJson(matrix.cases) }}
+
+ test_bin_ofs:
+ name: bin_ofs / ${{ matrix.os }}
+ needs: [plan]
+ if: fromJson(needs.plan.outputs.plan).components.bin_ofs
+ secrets: inherit
+ strategy:
+ matrix:
+ include: ${{ fromJson(needs.plan.outputs.plan).bin_ofs }}
+ uses: ./.github/workflows/test_behavior_bin_ofs.yml
+ with:
+ os: ${{ matrix.os }}
+ cases: ${{ toJson(matrix.cases) }}
diff --git a/.github/workflows/test_behavior_bin_ofs.yml b/.github/workflows/test_behavior_bin_ofs.yml
new file mode 100644
index 0000000000..a4e7f81ea0
--- /dev/null
+++ b/.github/workflows/test_behavior_bin_ofs.yml
@@ -0,0 +1,61 @@
+# Licensed to the Apache Software Foundation (ASF) under one
+# or more contributor license agreements. See the NOTICE file
+# distributed with this work for additional information
+# regarding copyright ownership. The ASF licenses this file
+# to you under the Apache License, Version 2.0 (the
+# "License"); you may not use this file except in compliance
+# with the License. You may obtain a copy of the License at
+#
+# http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing,
+# software distributed under the License is distributed on an
+# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+# KIND, either express or implied. See the License for the
+# specific language governing permissions and limitations
+# under the License.
+
+name: Behavior Test Bin Ofs
+
+on:
+ workflow_call:
+ inputs:
+ os:
+ required: true
+ type: string
+ cases:
+ required: true
+ type: string
+
+jobs:
+ test:
+ name: ${{ matrix.cases.service }} / ${{ matrix.cases.setup }}
+ runs-on: ${{ inputs.os }}
+ strategy:
+ matrix:
+ cases: ${{ fromJson(inputs.cases) }}
+ steps:
+ - uses: actions/checkout@v4
+ - name: Setup Rust toolchain
+ uses: ./.github/actions/setup
+ with:
+ need-protoc: true
+ need-rocksdb: true
+ github-token: ${{ secrets.GITHUB_TOKEN }}
+
+ # TODO: 1password is only supported on linux
+ #
+ # Waiting for https://github.com/1Password/load-secrets-action/issues/46
+ - name: Setup 1Password Connect
+ if: runner.os == 'Linux'
+ uses: 1password/load-secrets-action/configure@v1
+ with:
+ connect-host: ${{ secrets.OP_CONNECT_HOST }}
+ connect-token: ${{ secrets.OP_CONNECT_TOKEN }}
+
+ - name: Test Bin Ofs
+ uses: ./.github/actions/test_behavior_bin_ofs
+ with:
+ setup: ${{ matrix.cases.setup }}
+ service: ${{ matrix.cases.service }}
+ feature: ${{ matrix.cases.feature }}
diff --git a/bin/ofs/Cargo.lock b/bin/ofs/Cargo.lock
index f05ea70b38..5a0c34d3f4 100644
--- a/bin/ofs/Cargo.lock
+++ b/bin/ofs/Cargo.lock
@@ -489,6 +489,7 @@ checksum = "645c6916888f6cb6350d2550b80fb63e734897a8498abe35cfb732b6487804b0"
dependencies = [
"futures-channel",
"futures-core",
+ "futures-executor",
"futures-io",
"futures-sink",
"futures-task",
@@ -511,6 +512,17 @@ version = "0.3.30"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "dfc6580bb841c5a68e9ef15c77ccc837b40a7504914d52e47b8b0e9bbda25a1d"
+[[package]]
+name = "futures-executor"
+version = "0.3.30"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "a576fc72ae164fca6b9db127eaa9a9dda0d61316034f33a0a0d4eda41f02b01d"
+dependencies = [
+ "futures-core",
+ "futures-task",
+ "futures-util",
+]
+
[[package]]
name = "futures-io"
version = "0.3.30"
@@ -928,8 +940,13 @@ dependencies = [
"nix 0.27.1",
"opendal",
"sharded-slab",
+ "tempfile",
+ "test-context",
"tokio",
"url",
+ "urlencoding",
+ "uuid",
+ "walkdir",
]
[[package]]
@@ -1273,6 +1290,15 @@ version = "1.0.16"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "f98d2aa92eebf49b69786be48e4477826b256916e84a57ff2a4f21923b48eb4c"
+[[package]]
+name = "same-file"
+version = "1.0.6"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "93fc1dc3aaa9bfed95e02e6eadabb4baf7e3078b0bd1b4d7b6b0b68378900502"
+dependencies = [
+ "winapi-util",
+]
+
[[package]]
name = "serde"
version = "1.0.196"
@@ -1416,6 +1442,39 @@ version = "0.1.2"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "2047c6ded9c721764247e62cd3b03c09ffc529b2ba5b10ec482ae507a4a70160"
+[[package]]
+name = "tempfile"
+version = "3.10.1"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "85b77fafb263dd9d05cbeac119526425676db3784113aa9295c88498cbf8bff1"
+dependencies = [
+ "cfg-if",
+ "fastrand",
+ "rustix",
+ "windows-sys 0.52.0",
+]
+
+[[package]]
+name = "test-context"
+version = "0.3.0"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "6676ab8513edfd2601a108621103fdb45cac9098305ca25ec93f7023b06b05d9"
+dependencies = [
+ "futures",
+ "test-context-macros",
+]
+
+[[package]]
+name = "test-context-macros"
+version = "0.3.0"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "78ea17a2dc368aeca6f554343ced1b1e31f76d63683fa8016e5844bd7a5144a1"
+dependencies = [
+ "proc-macro2",
+ "quote",
+ "syn",
+]
+
[[package]]
name = "tiny-keccak"
version = "2.0.2"
@@ -1621,6 +1680,12 @@ dependencies = [
"percent-encoding",
]
+[[package]]
+name = "urlencoding"
+version = "2.1.3"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "daf8dba3b7eb870caf1ddeed7bc9d2a049f3cfdfae7cb521b087cc33ae4c49da"
+
[[package]]
name = "utf8parse"
version = "0.2.1"
@@ -1643,6 +1708,16 @@ version = "0.9.4"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "49874b5167b65d7193b8aba1567f5c7d93d001cafc34600cee003eda787e483f"
+[[package]]
+name = "walkdir"
+version = "2.5.0"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "29790946404f91d9c5d06f9874efddea1dc06c5efe94541a7d6863108e3a5e4b"
+dependencies = [
+ "same-file",
+ "winapi-util",
+]
+
[[package]]
name = "want"
version = "0.3.1"
@@ -1768,6 +1843,37 @@ dependencies = [
"winsafe",
]
+[[package]]
+name = "winapi"
+version = "0.3.9"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "5c839a674fcd7a98952e593242ea400abe93992746761e38641405d28b00f419"
+dependencies = [
+ "winapi-i686-pc-windows-gnu",
+ "winapi-x86_64-pc-windows-gnu",
+]
+
+[[package]]
+name = "winapi-i686-pc-windows-gnu"
+version = "0.4.0"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "ac3b87c63620426dd9b991e5ce0329eff545bccbbb34f3be09ff6fb6ab51b7b6"
+
+[[package]]
+name = "winapi-util"
+version = "0.1.6"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "f29e6f9198ba0d26b4c9f07dbe6f9ed633e1f3d5b8b414090084349e46a52596"
+dependencies = [
+ "winapi",
+]
+
+[[package]]
+name = "winapi-x86_64-pc-windows-gnu"
+version = "0.4.0"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "712e227841d057c1ee1cd2fb22fa7e5a5461ae8e48fa2ca79ec42cfc1931183f"
+
[[package]]
name = "windows-core"
version = "0.52.0"
diff --git a/bin/ofs/Cargo.toml b/bin/ofs/Cargo.toml
index 260777954d..8442aa0aa1 100644
--- a/bin/ofs/Cargo.toml
+++ b/bin/ofs/Cargo.toml
@@ -55,3 +55,10 @@ nix = { version = "0.27.1", features = ["user"] }
default = ["services-fs", "services-s3"]
services-fs = ["opendal/services-fs"]
services-s3 = ["opendal/services-s3"]
+
+[dev-dependencies]
+test-context = "0.3.0"
+tempfile = "3.10.1"
+walkdir = "2.5.0"
+uuid = "1.7.0"
+urlencoding = "2.1.3"
diff --git a/bin/ofs/tests/common/mod.rs b/bin/ofs/tests/common/mod.rs
new file mode 100644
index 0000000000..5b5d4b87fd
--- /dev/null
+++ b/bin/ofs/tests/common/mod.rs
@@ -0,0 +1,88 @@
+// Licensed to the Apache Software Foundation (ASF) under one
+// or more contributor license agreements. See the NOTICE file
+// distributed with this work for additional information
+// regarding copyright ownership. The ASF licenses this file
+// to you under the Apache License, Version 2.0 (the
+// "License"); you may not use this file except in compliance
+// with the License. You may obtain a copy of the License at
+//
+// http://www.apache.org/licenses/LICENSE-2.0
+//
+// Unless required by applicable law or agreed to in writing,
+// software distributed under the License is distributed on an
+// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+// KIND, either express or implied. See the License for the
+// specific language governing permissions and limitations
+// under the License.
+
+use std::{collections::HashMap, env, process::Command};
+
+use tempfile::TempDir;
+use test_context::AsyncTestContext;
+use tokio::task::JoinHandle;
+
+pub(crate) struct OfsTestContext {
+ pub mount_point: TempDir,
+ 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 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_task,
+ }
+ }
+
+ 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_task.abort();
+ self.mount_point.close().unwrap();
+ }
+}
+
+fn backend_scheme() -> Option<String> {
+ let scheme = env::var("OPENDAL_TEST").ok()?;
+ let prefix = format!("opendal_{scheme}_");
+
+ let mut cfg = env::vars()
+ .filter_map(|(k, v)| {
+ k.to_lowercase()
+ .strip_prefix(&prefix)
+ .map(|k| (k.to_string(), v))
+ })
+ .collect::<HashMap<String, String>>();
+
+ // Use random root unless OPENDAL_DISABLE_RANDOM_ROOT is set to true.
+ let disable_random_root = env::var("OPENDAL_DISABLE_RANDOM_ROOT").unwrap_or_default() == "true";
+ if !disable_random_root {
+ let root = format!(
+ "{}{}/",
+ cfg.get("root").cloned().unwrap_or_else(|| "/".to_string()),
+ uuid::Uuid::new_v4()
+ );
+ cfg.insert("root".to_string(), root);
+ }
+
+ let params = cfg
+ .into_iter()
+ .map(|(k, v)| format!("{}={}", urlencoding::encode(&k), urlencoding::encode(&v)))
+ .collect::<Vec<_>>()
+ .join("&");
+
+ Some(format!("{scheme}://?{params}"))
+}
diff --git a/bin/ofs/tests/file.rs b/bin/ofs/tests/file.rs
new file mode 100644
index 0000000000..83db1fb0b3
--- /dev/null
+++ b/bin/ofs/tests/file.rs
@@ -0,0 +1,91 @@
+// Licensed to the Apache Software Foundation (ASF) under one
+// or more contributor license agreements. See the NOTICE file
+// distributed with this work for additional information
+// regarding copyright ownership. The ASF licenses this file
+// to you under the Apache License, Version 2.0 (the
+// "License"); you may not use this file except in compliance
+// with the License. You may obtain a copy of the License at
+//
+// http://www.apache.org/licenses/LICENSE-2.0
+//
+// Unless required by applicable law or agreed to in writing,
+// software distributed under the License is distributed on an
+// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+// KIND, either express or implied. See the License for the
+// specific language governing permissions and limitations
+// under the License.
+
+mod common;
+
+use std::io::SeekFrom;
+
+use common::OfsTestContext;
+
+use test_context::test_context;
+use tokio::{
+ fs::{self, File},
+ io::{AsyncReadExt, AsyncSeekExt, AsyncWriteExt},
+};
+
+static TEST_TEXT: &str = include_str!("../Cargo.toml");
+
+#[test_context(OfsTestContext)]
+#[tokio::test]
+async fn test_file(ctx: &mut OfsTestContext) {
+ let path = ctx.mount_point.path().join("test_file.txt");
+ let mut file = File::create(&path).await.unwrap();
+
+ file.write_all(TEST_TEXT.as_bytes()).await.unwrap();
+ drop(file);
+
+ let mut file = File::open(&path).await.unwrap();
+ let mut buf = String::new();
+ file.read_to_string(&mut buf).await.unwrap();
+ assert_eq!(buf, TEST_TEXT);
+ drop(file);
+
+ fs::remove_file(path).await.unwrap();
+}
+
+#[test_context(OfsTestContext)]
+#[tokio::test]
+async fn test_file_append(ctx: &mut OfsTestContext) {
+ let path = ctx.mount_point.path().join("test_file_append.txt");
+ let mut file = File::create(&path).await.unwrap();
+
+ file.write_all(TEST_TEXT.as_bytes()).await.unwrap();
+ drop(file);
+
+ let mut file = File::options().append(true).open(&path).await.unwrap();
+ file.write_all(b"test").await.unwrap();
+ drop(file);
+
+ let mut file = File::open(&path).await.unwrap();
+ let mut buf = String::new();
+ file.read_to_string(&mut buf).await.unwrap();
+ assert_eq!(buf, TEST_TEXT.to_owned() + "test");
+ drop(file);
+
+ fs::remove_file(path).await.unwrap();
+}
+
+#[test_context(OfsTestContext)]
+#[tokio::test]
+async fn test_file_seek(ctx: &mut OfsTestContext) {
+ let path = ctx.mount_point.path().join("test_file_seek.txt");
+ let mut file = File::create(&path).await.unwrap();
+
+ file.write_all(TEST_TEXT.as_bytes()).await.unwrap();
+ drop(file);
+
+ let mut file = File::open(&path).await.unwrap();
+ file.seek(SeekFrom::Start(TEST_TEXT.len() as u64 / 2))
+ .await
+ .unwrap();
+ let mut buf = String::new();
+ file.read_to_string(&mut buf).await.unwrap();
+ assert_eq!(buf, TEST_TEXT[TEST_TEXT.len() / 2..]);
+ drop(file);
+
+ fs::remove_file(path).await.unwrap();
+}
diff --git a/bin/ofs/tests/path.rs b/bin/ofs/tests/path.rs
new file mode 100644
index 0000000000..cf33f52efb
--- /dev/null
+++ b/bin/ofs/tests/path.rs
@@ -0,0 +1,73 @@
+// Licensed to the Apache Software Foundation (ASF) under one
+// or more contributor license agreements. See the NOTICE file
+// distributed with this work for additional information
+// regarding copyright ownership. The ASF licenses this file
+// to you under the Apache License, Version 2.0 (the
+// "License"); you may not use this file except in compliance
+// with the License. You may obtain a copy of the License at
+//
+// http://www.apache.org/licenses/LICENSE-2.0
+//
+// Unless required by applicable law or agreed to in writing,
+// software distributed under the License is distributed on an
+// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+// KIND, either express or implied. See the License for the
+// specific language governing permissions and limitations
+// under the License.
+
+mod common;
+
+use common::OfsTestContext;
+
+use test_context::test_context;
+use tokio::fs;
+use walkdir::WalkDir;
+
+#[test_context(OfsTestContext)]
+#[tokio::test]
+async fn test_path(ctx: &mut OfsTestContext) {
+ let actual_entries = [
+ ("dir1", false),
+ ("dir2", false),
+ ("dir3", false),
+ ("dir3/dir4", false),
+ ("dir3/dir5", false),
+ ("dir3/file3", true),
+ ("dir3/file4", true),
+ ("file1", true),
+ ("file2", true),
+ ]
+ .into_iter()
+ .map(|(x, y)| (x.to_string(), y))
+ .collect::<Vec<_>>();
+
+ for (path, is_file) in actual_entries.iter() {
+ let path = ctx.mount_point.path().join(path);
+ match is_file {
+ true => fs::write(path, "hello").await.unwrap(),
+ false => fs::create_dir(path).await.unwrap(),
+ }
+ }
+
+ assert_eq!(
+ actual_entries,
+ WalkDir::new(ctx.mount_point.path())
+ .min_depth(1)
+ .max_depth(2)
+ .sort_by_file_name()
+ .into_iter()
+ .map(|x| {
+ let x = x.unwrap();
+ (
+ x.path()
+ .strip_prefix(&ctx.mount_point)
+ .unwrap()
+ .to_str()
+ .unwrap()
+ .to_string(),
+ x.file_type().is_file(),
+ )
+ })
+ .collect::<Vec<_>>()
+ );
+}