Implement ResponseWriterStub for testing

This commit is contained in:
Yuriy Dupyn 2024-02-05 19:57:42 +01:00
parent 002ac4c648
commit ad06715676
2 changed files with 56 additions and 1 deletions

View file

@ -174,6 +174,7 @@ mod tests {
use super::*; use super::*;
use crate::operation::Operation; use crate::operation::Operation;
use crate::schema::Column; use crate::schema::Column;
use crate::response_writer::ResponseWriterStub;
use crate::type_system::{DbType, IndexableValue, Value}; use crate::type_system::{DbType, IndexableValue, Value};
use std::collections::HashSet; use std::collections::HashSet;
@ -202,8 +203,12 @@ mod tests {
let users_schema = users_schema(); let users_schema = users_schema();
let users = users_schema.table_name().clone(); let users = users_schema.table_name().clone();
let db_path = Path::new("db-test-0");
let mut response_writer = ResponseWriterStub::new();
// state // state
// .interpret(Operation::CreateTable(users_schema)) // .interpret(db_path, &mut response_writer, Operation::CreateTable(users_schema)).await
// .unwrap(); // .unwrap();
// assert!(state.tables.len() == 1); // assert!(state.tables.len() == 1);

View file

@ -34,3 +34,53 @@ pub trait ResponseWriter {
async fn write_table_row(&mut self, row: &RestrictedRow) -> anyhow::Result<()>; async fn write_table_row(&mut self, row: &RestrictedRow) -> anyhow::Result<()>;
async fn write_command_complete(&mut self, status: CompleteStatus) -> anyhow::Result<()>; async fn write_command_complete(&mut self, status: CompleteStatus) -> anyhow::Result<()>;
} }
// ===Stub implementation for testing===
//
pub struct ResponseWriterStub {}
impl ResponseWriterStub {
pub fn new() -> Self {
ResponseWriterStub {}
}
}
#[async_trait]
impl ResponseWriter for ResponseWriterStub
{
async fn write_table_header(
&mut self,
table_schema: &TableSchema,
columns: &ColumnSelection,
) -> anyhow::Result<()> {
let column_names = table_schema.get_columns();
for &column in columns {
let column_name = column_names[column];
print!("{}, ", column_name)
}
println!();
Ok(())
}
async fn write_table_row(&mut self, row: &RestrictedRow) -> anyhow::Result<()> {
for (_, value) in row.iter() {
print!("{:?}", value)
}
println!();
Ok(())
}
async fn write_command_complete(&mut self, status: CompleteStatus) -> anyhow::Result<()> {
use CompleteStatus::*;
match status {
Insert { oid, rows } => println!("oid = {}, rows = {}", oid, rows),
Delete(count) => println!("Deleted {}", count),
Select(count) => println!("Selected {}", count),
CreateTable => println!("Table created"),
CreateIndex => println!("Index created"),
}
Ok(())
}
}