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 71e6639 commit 659c81d
Showing 1 changed file with 67 additions and 1 deletion.
68 changes: 67 additions & 1 deletion src/dto/table_data.rs
Original file line number Diff line number Diff line change
Expand Up @@ -35,10 +35,76 @@ pub struct TableCreation {
// pub properties: Option<HashMap<String, String>>,
}

#[derive(Debug, Serialize, Deserialize, Clone)]
#[derive(PartialEq, Debug, Serialize, Deserialize, Clone)]
pub struct TableMetadata {
pub table_uuid: String,
// pub file_urls: Option<Vec<String>>,
// pub columns: Option<Vec<ColumnData>>,
// pub properties: Option<HashMap<String, String>>,
}

#[cfg(test)]
mod tests {
use super::*;
use serde_json;

#[test]
fn test_table_ident() {
let namespace = NamespaceIdent(vec!["namespace".to_string()]);
let name = "table".to_string();
let table_ident = TableIdent::new(namespace.clone(), name.clone());

assert_eq!(table_ident.namespace, namespace);
assert_eq!(table_ident.name, name);
}

#[test]
fn test_table_creation() {
let name = "table".to_string();
let table_creation = TableCreation::builder().name(name.clone()).build();

assert_eq!(table_creation.name, name);
}

#[test]
fn test_table_metadata() {
let table_uuid = "uuid".to_string();
let table_metadata = TableMetadata { table_uuid: table_uuid.clone() };

assert_eq!(table_metadata.table_uuid, table_uuid);
}

#[test]
fn test_table() {
let id = TableIdent::new(NamespaceIdent(vec!["namespace".to_string()]), "table".to_string());
let metadata = TableMetadata { table_uuid: "uuid".to_string() };
let table = Table { id: id.clone(), metadata: metadata.clone() };

assert_eq!(table.id, id);
assert_eq!(table.metadata, metadata);
}

#[test]
fn test_table_ident_serialization() {
let table_ident = TableIdent::new(NamespaceIdent(vec!["namespace".to_string()]), "table".to_string());
let serialized = serde_json::to_string(&table_ident).unwrap();

assert!(serialized.contains("namespace"));
assert!(serialized.contains("table"));
}

#[test]
fn test_table_ident_deserialization() {
let data = r#"
{
"namespace": ["namespace"],
"name": "table"
}
"#;

let table_ident: TableIdent = serde_json::from_str(data).unwrap();

assert_eq!(table_ident.namespace.0[0], "namespace");
assert_eq!(table_ident.name, "table");
}
}

0 comments on commit 659c81d

Please sign in to comment.