Creating test for generate_create_table_query

This commit is contained in:
Frédéric CAMPO 2025-02-18 22:29:58 +01:00
parent 72edbd4cf0
commit d9ab10c0a7
Signed by: llowin
GPG Key ID: 19EACF0560706F99
1 changed files with 7 additions and 4 deletions

View File

@ -6,7 +6,6 @@
#![allow(dead_code)]
use rusqlite::{self};
use serde::de::DeserializeOwned;
use std::collections::HashMap;
/// Public function to get data from db. Returns the result as a vec with structs
pub fn get_data<T>(
@ -42,7 +41,7 @@ fn generate_select_query<T: more_fields::FieldsAsSlice>(
/// Generate create table_name with fields as columns
/// This function expects a hash map containing (column name, sqlite type)
pub fn generate_create_table_query(table_name: &str, fields: HashMap<String, String>) -> String {
pub fn generate_create_table_query(table_name: &str, fields: &[(&str, &str)]) -> String {
format!(
"CREATE TABLE IF NOT EXISTS {} ({}, PRIMARY KEY('id' AUTOINCREMENT));",
table_name,
@ -66,7 +65,9 @@ mod test {
#[derive(FieldsAsSlice, Deserialize, Debug, PartialEq)]
struct TestStruct {
#[INTEGER]
id: usize,
#[TEXT]
name: String,
}
/// setting up test db and table, also adding arbitrary data inside
@ -123,9 +124,11 @@ mod test {
)
}
#[ignore = "todo"]
#[test]
fn test_generate_create_table_query() {
todo!()
let query = generate_create_table_query("TestStruct", TestStruct::attributes_slice());
assert_eq!(
query, "CREATE TABLE IF NOT EXISTS TestStruct (id INTEGER,name TEXT, PRIMARY KEY('id' AUTOINCREMENT));".to_string()
)
}
}