Move add_version and get_child_version to server module

..and add some tests specifically for those functions, in the absence of
all the HTTP nonsense.
This commit is contained in:
Dustin J. Mitchell
2020-11-26 19:44:30 -05:00
parent fb22b9686f
commit 5b1b911bf7
5 changed files with 201 additions and 73 deletions

View File

@@ -2,10 +2,8 @@ use crate::api::{
failure_to_ise, ServerState, HISTORY_SEGMENT_CONTENT_TYPE, PARENT_VERSION_ID_HEADER,
VERSION_ID_HEADER,
};
use crate::server::{ClientId, GetVersionResult, VersionId};
use crate::storage::StorageTxn;
use crate::server::{get_child_version, ClientId, VersionId};
use actix_web::{error, get, web, HttpResponse, Result};
use failure::Fallible;
/// Get a child version.
///
@@ -41,20 +39,6 @@ pub(crate) async fn service(
}
}
fn get_child_version<'a>(
mut txn: Box<dyn StorageTxn + 'a>,
client_id: ClientId,
parent_version_id: VersionId,
) -> Fallible<Option<GetVersionResult>> {
Ok(txn
.get_version_by_parent(client_id, parent_version_id)?
.map(|version| GetVersionResult {
version_id: version.version_id,
parent_version_id: version.parent_version_id,
history_segment: version.history_segment,
}))
}
#[cfg(test)]
mod test {
use crate::api::ServerState;