Skip to content

Commit

Permalink
integration tests
Browse files Browse the repository at this point in the history
  • Loading branch information
neumark committed Jan 13, 2023
1 parent 905a381 commit 2a3739a
Show file tree
Hide file tree
Showing 2 changed files with 77 additions and 13 deletions.
2 changes: 1 addition & 1 deletion src/config/context.rs
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,7 @@ fn build_object_store(cfg: &schema::SeafowlConfig) -> Arc<dyn ObjectStore> {
let mut builder = AmazonS3Builder::new()
.with_access_key_id(access_key_id)
.with_secret_access_key(secret_access_key)
.with_region(region.clone().unwrap_or("".to_string()))
.with_region(region.clone().unwrap_or_default())
.with_bucket_name(bucket)
.with_allow_http(true);

Expand Down
88 changes: 76 additions & 12 deletions src/repository/interface.rs
Original file line number Diff line number Diff line change
Expand Up @@ -242,15 +242,19 @@ pub mod tests {
}
}

async fn make_database_with_single_table(
// bumped into rustc bug: https://github.com/rust-lang/rust/issues/96771#issuecomment-1119886703
async fn make_database_with_single_table<'a>(
repository: Arc<dyn Repository>,
database_name: &'a str,
collection_name: &'a str,
table_name: &'a str,
) -> (DatabaseId, CollectionId, TableId, TableVersionId) {
let database_id = repository
.create_database("testdb")
.create_database(database_name)
.await
.expect("Error creating database");
let collection_id = repository
.create_collection(database_id, "testcol")
.create_collection(database_id, collection_name)
.await
.expect("Error creating collection");

Expand All @@ -263,7 +267,7 @@ pub mod tests {
};

let (table_id, table_version_id) = repository
.create_table(collection_id, "testtable", &schema)
.create_table(collection_id, table_name, &schema)
.await
.expect("Error creating table");

Expand All @@ -279,6 +283,7 @@ pub mod tests {
test_create_functions(repository.clone(), database_id).await;
test_rename_table(repository.clone(), database_id, table_id, new_version_id)
.await;
test_create_with_name_in_quotes(repository.clone()).await;
test_error_propagation(repository, table_id).await;
}

Expand All @@ -296,20 +301,21 @@ pub mod tests {
version: TableVersionId,
collection_name: String,
table_name: String,
table_id: i64,
) -> Vec<AllDatabaseColumnsResult> {
vec![
AllDatabaseColumnsResult {
collection_name: collection_name.clone(),
table_name: table_name.clone(),
table_id: 1,
table_id,
table_version_id: version,
column_name: "date".to_string(),
column_type: "{\"children\":[],\"name\":\"date\",\"nullable\":false,\"type\":{\"name\":\"date\",\"unit\":\"MILLISECOND\"}}".to_string(),
},
AllDatabaseColumnsResult {
collection_name,
table_name,
table_id: 1,
table_id,
table_version_id: version,
column_name: "value".to_string(),
column_type: "{\"children\":[],\"name\":\"value\",\"nullable\":false,\"type\":{\"name\":\"floatingpoint\",\"precision\":\"DOUBLE\"}}"
Expand All @@ -322,7 +328,13 @@ pub mod tests {
repository: Arc<dyn Repository>,
) -> (DatabaseId, TableId, TableVersionId) {
let (database_id, _, table_id, table_version_id) =
make_database_with_single_table(repository.clone()).await;
make_database_with_single_table(
repository.clone(),
"testdb",
"testcol",
"testtable",
)
.await;

// Test loading all columns

Expand All @@ -333,7 +345,7 @@ pub mod tests {

assert_eq!(
all_columns,
expected(1, "testcol".to_string(), "testtable".to_string())
expected(1, "testcol".to_string(), "testtable".to_string(), 1)
);

// Duplicate the table
Expand All @@ -353,7 +365,8 @@ pub mod tests {
expected(
new_version_id,
"testcol".to_string(),
"testtable".to_string()
"testtable".to_string(),
1
)
);

Expand All @@ -365,7 +378,7 @@ pub mod tests {

assert_eq!(
all_columns,
expected(1, "testcol".to_string(), "testtable".to_string())
expected(1, "testcol".to_string(), "testtable".to_string(), 1)
);

// Check the existing table versions
Expand All @@ -382,6 +395,55 @@ pub mod tests {
(database_id, table_id, table_version_id)
}

async fn test_create_with_name_in_quotes(repository: Arc<dyn Repository>) {
let (database_id, _, _, table_version_id) = make_database_with_single_table(
repository.clone(),
"testdb2",
"\"testcol\"",
"\"testtable\"",
)
.await;

// Test loading all columns

let all_columns = repository
.get_all_columns_in_database(database_id, None)
.await
.expect("Error getting all columns");

assert_eq!(
all_columns,
expected(
table_version_id,
"testcol".to_string(),
"testtable".to_string(),
2
)
);

// Duplicate the table
let new_version_id = repository
.create_new_table_version(table_version_id, true)
.await
.unwrap();

// Test all columns again: we should have the schema for the latest table version
let all_columns = repository
.get_all_columns_in_database(database_id, None)
.await
.expect("Error getting all columns");

assert_eq!(
all_columns,
expected(
new_version_id,
"testcol".to_string(),
"testtable".to_string(),
2
)
);
}

async fn test_create_append_partition(
repository: Arc<dyn Repository>,
table_version_id: TableVersionId,
Expand Down Expand Up @@ -529,7 +591,8 @@ pub mod tests {
expected(
table_version_id,
"testcol".to_string(),
"testtable2".to_string()
"testtable2".to_string(),
1
)
);

Expand All @@ -553,7 +616,8 @@ pub mod tests {
expected(
table_version_id,
"testcol2".to_string(),
"testtable2".to_string()
"testtable2".to_string(),
1
)
);
}
Expand Down

0 comments on commit 2a3739a

Please sign in to comment.