stable_fs/storage/
dummy.rs1use crate::{
2 error::Error,
3 fs::{ChunkSize, ChunkType},
4 storage::types::{FileName, MountedFileSizePolicy},
5};
6
7use super::{
8 Storage,
9 types::{DirEntry, DirEntryIndex, FileSize, Metadata, Node},
10};
11
12pub struct DummyStorage {}
13
14impl DummyStorage {
15 pub fn new() -> Self {
16 Self {}
17 }
18}
19
20impl Default for DummyStorage {
21 fn default() -> Self {
22 Self::new()
23 }
24}
25
26impl Storage for DummyStorage {
27 fn root_node(&self) -> Node {
28 panic!("Not supported")
29 }
30
31 fn new_node(&mut self) -> Node {
32 panic!("Not supported")
33 }
34
35 fn get_version(&self) -> u32 {
36 0
37 }
38
39 fn get_metadata(&self, _node: Node) -> Result<Metadata, Error> {
40 panic!("Not supported")
41 }
42
43 fn put_metadata(&mut self, _node: Node, _metadata: &Metadata) -> Result<(), Error> {
44 panic!("Not supported")
45 }
46
47 fn get_direntry(&self, _node: Node, _index: DirEntryIndex) -> Result<DirEntry, Error> {
48 panic!("Not supported")
49 }
50
51 fn put_direntry(&mut self, _node: Node, _index: DirEntryIndex, _entry: DirEntry) {
52 panic!("Not supported")
53 }
54
55 fn rm_direntry(&mut self, _node: Node, _index: DirEntryIndex) {
56 panic!("Not supported")
57 }
58
59 fn read(&mut self, _node: Node, _offset: FileSize, _buf: &mut [u8]) -> Result<FileSize, Error> {
60 panic!("Not supported")
61 }
62
63 fn mount_node(
64 &mut self,
65 _node: Node,
66 _memory: Box<dyn ic_stable_structures::Memory>,
67 _policy: MountedFileSizePolicy,
68 ) -> Result<(), Error> {
69 panic!("Not supported")
70 }
71
72 fn unmount_node(
73 &mut self,
74 _node: Node,
75 ) -> Result<Box<dyn ic_stable_structures::Memory>, Error> {
76 panic!("Not supported")
77 }
78
79 fn is_mounted(&self, _node: Node) -> bool {
80 panic!("Not supported")
81 }
82
83 fn get_mounted_memory(&self, _node: Node) -> Option<&dyn ic_stable_structures::Memory> {
84 panic!("Not supported")
85 }
86
87 fn init_mounted_memory(&mut self, _node: Node) -> Result<(), Error> {
88 panic!("Not supported")
89 }
90
91 fn store_mounted_memory(&mut self, _node: Node) -> Result<(), Error> {
92 panic!("Not supported")
93 }
94
95 fn write(&mut self, _node: Node, _offset: FileSize, _buf: &[u8]) -> Result<FileSize, Error> {
96 panic!("Not supported")
97 }
98
99 fn rm_file(&mut self, _node: Node) -> Result<(), Error> {
100 panic!("Not supported")
101 }
102
103 fn set_chunk_size(&mut self, _chunk_size: ChunkSize) -> Result<(), Error> {
104 panic!("Not supported")
105 }
106
107 fn chunk_size(&self) -> usize {
108 panic!("Not supported")
109 }
110
111 fn set_chunk_type(&mut self, _chunk_type: ChunkType) {
112 panic!("Not supported")
113 }
114
115 fn chunk_type(&self) -> ChunkType {
116 panic!("Not supported")
117 }
118
119 fn flush(&mut self, _node: Node) {
120 panic!("Not supported")
121 }
122
123 fn resize_file(&mut self, _node: Node, _new_size: FileSize) -> Result<(), Error> {
124 panic!("Not supported")
125 }
126
127 fn with_direntries(
128 &self,
129 _node: Node,
130 _initial_index: Option<DirEntryIndex>,
131 _f: &mut dyn FnMut(&DirEntryIndex, &DirEntry) -> bool,
132 ) {
133 panic!("Not supported")
134 }
135
136 fn new_direntry_index(&self, _node: Node) -> DirEntryIndex {
137 panic!("Not supported")
138 }
139
140 fn get_direntry_index_by_name(&self, _en: &(Node, FileName)) -> Option<DirEntryIndex> {
141 panic!("Not supported")
142 }
143}
144
145#[cfg(test)]
146mod tests {
147
148 use super::*;
149 use crate::storage::types::{FileType, Times};
150
151 #[test]
152 #[should_panic]
153 fn put_metadata_panic() {
154 let mut storage = DummyStorage::new();
155 let node = storage.new_node();
156 storage
157 .put_metadata(
158 node,
159 &Metadata {
160 node,
161 file_type: FileType::RegularFile,
162 link_count: 1,
163 size: 10,
164 times: Times::default(),
165 chunk_type: None,
166 maximum_size_allowed: None,
167 first_dir_entry: None,
168 last_dir_entry: None,
169 },
170 )
171 .unwrap();
172 }
173
174 #[test]
175 #[should_panic]
176 fn get_metadata_panic() {
177 let storage = DummyStorage::new();
178
179 let _ = storage.get_metadata(0u64);
180 }
181
182 #[test]
183 #[should_panic]
184 fn new_node_panic() {
185 let mut storage = DummyStorage::new();
186 storage.new_node();
187 }
188
189 #[test]
190 #[should_panic]
191 fn root_node_panic() {
192 let storage = DummyStorage::new();
193 storage.root_node();
194 }
195
196 #[test]
197 fn get_version_panic() {
198 let storage = DummyStorage::new();
199 assert_eq!(0, storage.get_version());
200 }
201
202 #[test]
203 #[should_panic]
204 fn get_direntry_panic() {
205 let storage = DummyStorage::new();
206 let _ = storage.get_direntry(0u64, 0u32);
207 }
208
209 #[test]
210 #[should_panic]
211 fn put_direntry_panic() {
212 let mut storage = DummyStorage::new();
213 storage.put_direntry(0u64, 0u32, DirEntry::default());
214 }
215
216 #[test]
217 #[should_panic]
218 fn rm_direntry_panic() {
219 let mut storage = DummyStorage::new();
220 storage.rm_direntry(0u64, 0u32);
221 }
222}