Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[storage] Add get_mut() to FileRecords #114 #115

Merged
merged 2 commits into from
Aug 27, 2022
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
71 changes: 47 additions & 24 deletions src/storage/file_records.rs
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,10 @@ impl FileRecords {
self.records.get(&index)
}

pub(crate) fn get_mut(&mut self, index: i64) -> Option<&mut FileRecord> {
self.records.get_mut(&index)
}

pub(crate) fn remove(&mut self, index: i64) {
self.records.remove(&index);
self.free_list.push(index);
Expand Down Expand Up @@ -63,30 +67,6 @@ impl From<Vec<FileRecord>> for FileRecords {
mod tests {
use super::*;

#[test]
fn default_constructed() {
let _records = FileRecords::default();
}

#[test]
fn get() {
let mut file_records = FileRecords::default();
let position = 32_u64;
let size = 64_u64;

file_records.create(position, size);
let expected_record = FileRecord {
index: 0,
position,
size,
};

assert_eq!(
file_records.get(expected_record.index),
Some(&expected_record)
);
}

#[test]
fn create() {
let mut file_records = FileRecords::default();
Expand All @@ -103,6 +83,11 @@ mod tests {
assert_eq!(actual_record, expected_record);
}

#[test]
fn default_constructed() {
let _records = FileRecords::default();
}

#[test]
fn from_records() {
let record1 = FileRecord {
Expand Down Expand Up @@ -158,6 +143,44 @@ mod tests {
assert_eq!(new_record3.index, 5);
}

#[test]
fn get() {
let mut file_records = FileRecords::default();
let position = 32_u64;
let size = 64_u64;

file_records.create(position, size);
let expected_record = FileRecord {
index: 0,
position,
size,
};

assert_eq!(
file_records.get(expected_record.index),
Some(&expected_record)
);
}

#[test]
fn get_mut() {
let mut file_records = FileRecords::default();
let position = 32_u64;
let size = 64_u64;

file_records.create(position, size);
let mut expected_record = FileRecord {
index: 0,
position,
size,
};

assert_eq!(
file_records.get_mut(expected_record.index),
Some(&mut expected_record)
);
}

#[test]
fn remove() {
let mut file_records = FileRecords::default();
Expand Down