qubit_fs_testkit/write_fixture_case.rs
1// =============================================================================
2// Copyright (c) 2026 Haixing Hu.
3//
4// SPDX-License-Identifier: Apache-2.0
5//
6// Licensed under the Apache License, Version 2.0.
7// =============================================================================
8//! Owned write requests prepared independently of the operation under test.
9
10use qubit_fs::path::Path;
11use qubit_fs::write::WriteOptions;
12
13/// A write request; its expected behavior is determined by `WriteScenario`.
14///
15/// Fixtures supply representable requests, never weaker expected results.
16///
17/// # Examples
18///
19/// ```
20/// use qubit_fs::path::Path;
21/// use qubit_fs::write::{WriteDisposition, WriteOptions};
22/// use qubit_fs_testkit::WriteFixtureCase;
23///
24/// let request = WriteFixtureCase::new(
25/// Path::parse("/isolated/write")?,
26/// b"payload".to_vec(),
27/// WriteOptions::default().with_disposition(WriteDisposition::CreateNew),
28/// );
29/// assert_eq!(request.bytes(), b"payload");
30/// # Ok::<(), qubit_fs::error::FsError>(())
31/// ```
32#[must_use]
33#[derive(Clone, Debug)]
34pub struct WriteFixtureCase {
35 /// Destination path passed to the write operation.
36 path: Path,
37 /// Owned payload the suite will verify independently.
38 bytes: Vec<u8>,
39 /// Requested disposition, preconditions, and guarantees.
40 options: WriteOptions,
41}
42
43impl WriteFixtureCase {
44 /// Creates an owned request for the selected scenario.
45 ///
46 /// # Parameters
47 ///
48 /// * `path` - destination path owned by the request.
49 /// * `bytes` - payload owned for independent verification.
50 /// * `options` - requested disposition, preconditions, and guarantees.
51 ///
52 /// # Returns
53 ///
54 /// The request retaining all three supplied values.
55 #[inline]
56 pub fn new(path: Path, bytes: Vec<u8>, options: WriteOptions) -> Self {
57 Self { path, bytes, options }
58 }
59
60 /// Returns the destination mapped into the fixture's isolated namespace.
61 ///
62 /// # Returns
63 ///
64 /// A borrow of the destination path stored in this request.
65 #[must_use = "the destination path should be inspected before the request is used"]
66 #[inline]
67 pub const fn path(&self) -> &Path {
68 &self.path
69 }
70
71 /// Returns the payload the suite will verify independently.
72 ///
73 /// # Returns
74 ///
75 /// A borrow of the bytes stored in this request.
76 #[must_use]
77 #[inline]
78 pub fn bytes(&self) -> &[u8] {
79 &self.bytes
80 }
81
82 /// Returns the requested disposition, preconditions, and guarantees.
83 ///
84 /// # Returns
85 ///
86 /// A borrow of the write options stored in this request.
87 #[must_use = "the write options should be inspected before the request is used"]
88 #[inline]
89 pub const fn options(&self) -> &WriteOptions {
90 &self.options
91 }
92}