Skip to content
This repository has been archived by the owner on Jun 6, 2024. It is now read-only.

Commit

Permalink
add test
Browse files Browse the repository at this point in the history
  • Loading branch information
SimranMakhija7 committed May 2, 2024
1 parent 297c021 commit 4dab2be
Show file tree
Hide file tree
Showing 2 changed files with 77 additions and 1 deletion.
2 changes: 1 addition & 1 deletion src/database/database.rs
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ impl Database {
let table_namespace_cf =
ColumnFamilyDescriptor::new("TableNamespaceMap", Options::default());

let cfs_vec = vec![namespace_cf, table_cf, table_namespace_cf];
let cfs_vec = vec![namespace_cf, table_cf, table_namespace_cf];

let db = DB::open_cf_descriptors(&opts, path, cfs_vec)
.map_err(|e| std::io::Error::new(std::io::ErrorKind::Other, e.to_string()))?;
Expand Down
76 changes: 76 additions & 0 deletions src/dto/rename_request.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,3 +6,79 @@ pub struct TableRenameRequest {
pub source: TableIdent,
pub destination: TableIdent,
}

#[cfg(test)]
mod tests {
use super::*;
use crate::dto::namespace_data::NamespaceIdent;
use serde_json;
#[test]
fn test_table_rename_request() {
let source = TableIdent {
namespace: NamespaceIdent(vec!["source_namespace".to_string()]),
name: "source_table".to_string(),
};

let destination = TableIdent {
namespace: NamespaceIdent(vec!["destination_namespace".to_string()]),
name: "destination_table".to_string(),
};

let request = TableRenameRequest {
source,
destination,
};

assert_eq!(request.source.namespace.0[0], "source_namespace");
assert_eq!(request.source.name, "source_table");
assert_eq!(request.destination.namespace.0[0], "destination_namespace");
assert_eq!(request.destination.name, "destination_table");
}

#[test]
fn test_table_rename_request_serialization() {
let source = TableIdent {
namespace: NamespaceIdent(vec!["source_namespace".to_string()]),
name: "source_table".to_string(),
};

let destination = TableIdent {
namespace: NamespaceIdent(vec!["destination_namespace".to_string()]),
name: "destination_table".to_string(),
};

let request = TableRenameRequest {
source,
destination,
};
let serialized = serde_json::to_string(&request).unwrap();

assert!(serialized.contains("source_namespace"));
assert!(serialized.contains("source_table"));
assert!(serialized.contains("destination_namespace"));
assert!(serialized.contains("destination_table"));
}

#[test]
fn test_table_rename_request_deserialization() {
let data = r#"
{
"source": {
"namespace": ["source_namespace"],
"name": "source_table"
},
"destination": {
"namespace": ["destination_namespace"],
"name": "destination_table"
}
}
"#;

let request: TableRenameRequest = serde_json::from_str(data).unwrap();

assert_eq!(request.source.namespace.0[0], "source_namespace");
assert_eq!(request.source.name, "source_table");
assert_eq!(request.destination.namespace.0[0], "destination_namespace");
assert_eq!(request.destination.name, "destination_table");
}
}

0 comments on commit 4dab2be

Please sign in to comment.