stable_fs/storage/
dummy.rs

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
use crate::{error::Error, fs::ChunkSize, fs::ChunkType};

use super::{
    types::{DirEntry, DirEntryIndex, FileSize, Metadata, Node},
    Storage,
};

pub struct DummyStorage {}

impl DummyStorage {
    pub fn new() -> Self {
        Self {}
    }
}

impl Default for DummyStorage {
    fn default() -> Self {
        Self::new()
    }
}

impl Storage for DummyStorage {
    fn root_node(&self) -> Node {
        panic!("Not supported")
    }

    fn new_node(&mut self) -> Node {
        panic!("Not supported")
    }

    fn get_version(&self) -> u32 {
        0
    }

    fn get_metadata(&self, _node: Node) -> Result<Metadata, Error> {
        panic!("Not supported")
    }

    fn put_metadata(&mut self, _node: Node, _metadata: Metadata) {
        panic!("Not supported")
    }

    fn get_direntry(&self, _node: Node, _index: DirEntryIndex) -> Result<DirEntry, Error> {
        panic!("Not supported")
    }

    fn put_direntry(&mut self, _node: Node, _index: DirEntryIndex, _entry: DirEntry) {
        panic!("Not supported")
    }

    fn rm_direntry(&mut self, _node: Node, _index: DirEntryIndex) {
        panic!("Not supported")
    }

    fn read(&mut self, _node: Node, _offset: FileSize, _buf: &mut [u8]) -> Result<FileSize, Error> {
        panic!("Not supported")
    }

    fn mount_node(
        &mut self,
        _node: Node,
        _memory: Box<dyn ic_stable_structures::Memory>,
    ) -> Result<(), Error> {
        panic!("Not supported")
    }

    fn unmount_node(
        &mut self,
        _node: Node,
    ) -> Result<Box<dyn ic_stable_structures::Memory>, Error> {
        panic!("Not supported")
    }

    fn is_mounted(&self, _node: Node) -> bool {
        panic!("Not supported")
    }

    fn get_mounted_memory(&self, _node: Node) -> Option<&dyn ic_stable_structures::Memory> {
        panic!("Not supported")
    }

    fn init_mounted_memory(&mut self, _node: Node) -> Result<(), Error> {
        panic!("Not supported")
    }

    fn store_mounted_memory(&mut self, _node: Node) -> Result<(), Error> {
        panic!("Not supported")
    }

    fn write(&mut self, _node: Node, _offset: FileSize, _buf: &[u8]) -> Result<FileSize, Error> {
        panic!("Not supported")
    }

    fn rm_file(&mut self, _node: Node) -> Result<(), Error> {
        panic!("Not supported")
    }

    fn set_chunk_size(&mut self, _chunk_size: ChunkSize) -> Result<(), Error> {
        panic!("Not supported")
    }

    fn chunk_size(&self) -> usize {
        panic!("Not supported")
    }

    fn set_chunk_type(&mut self, _chunk_type: ChunkType) {
        panic!("Not supported")
    }

    fn chunk_type(&self) -> ChunkType {
        panic!("Not supported")
    }

    fn flush(&mut self, _node: Node) {
        panic!("Not supported")
    }
}

#[cfg(test)]
mod tests {

    use super::*;
    use crate::storage::types::{FileType, Times};

    #[test]
    #[should_panic]
    fn put_metadata_panic() {
        let mut storage = DummyStorage::new();
        let node = storage.new_node();
        storage.put_metadata(
            node,
            Metadata {
                node,
                file_type: FileType::RegularFile,
                link_count: 1,
                size: 10,
                times: Times::default(),
                first_dir_entry: Some(42),
                last_dir_entry: Some(24),
                chunk_type: None,
            },
        )
    }

    #[test]
    #[should_panic]
    fn get_metadata_panic() {
        let storage = DummyStorage::new();

        let _ = storage.get_metadata(0u64);
    }

    #[test]
    #[should_panic]
    fn new_node_panic() {
        let mut storage = DummyStorage::new();
        storage.new_node();
    }

    #[test]
    #[should_panic]
    fn root_node_panic() {
        let storage = DummyStorage::new();
        storage.root_node();
    }

    #[test]
    fn get_version_panic() {
        let storage = DummyStorage::new();
        assert_eq!(0, storage.get_version());
    }

    #[test]
    #[should_panic]
    fn get_direntry_panic() {
        let storage = DummyStorage::new();
        let _ = storage.get_direntry(0u64, 0u32);
    }

    #[test]
    #[should_panic]
    fn put_direntry_panic() {
        let mut storage = DummyStorage::new();
        storage.put_direntry(0u64, 0u32, DirEntry::default());
    }

    #[test]
    #[should_panic]
    fn rm_direntry_panic() {
        let mut storage = DummyStorage::new();
        storage.rm_direntry(0u64, 0u32);
    }
}