This repository has been archived by the owner on Dec 23, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
33 changed files
with
395 additions
and
131 deletions.
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -8,6 +8,7 @@ workspace = { members = [ | |
name = "scipio" | ||
version = "0.1.0" | ||
edition = "2021" | ||
authors = ["Anish Sinha <[email protected]>"] | ||
|
||
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html | ||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -2,6 +2,3 @@ pub mod bases; | |
pub mod entities; | ||
pub mod records; | ||
pub mod responses; | ||
|
||
#[cfg(test)] | ||
mod tests; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
7 changes: 3 additions & 4 deletions
7
scipio-airtable/src/base_data/tests/bases.rs → scipio-airtable/src/tests/bases.rs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,53 @@ | ||
use std::future::Future; | ||
use std::pin::Pin; | ||
use std::sync::Arc; | ||
use std::{env, thread}; | ||
|
||
use anyhow::Result; | ||
use rstest::fixture; | ||
use tokio::runtime::Runtime; | ||
use tokio::sync::Mutex; | ||
|
||
use crate::Airtable; | ||
|
||
type BoxedAsyncFn = Box<dyn Fn() -> Pin<Box<dyn Future<Output = Result<()>> + Send>> + Send + Sync>; | ||
|
||
pub struct AsyncTestContext { | ||
pub airtable: Airtable, | ||
pub cleanup: Arc<Mutex<Vec<BoxedAsyncFn>>>, | ||
} | ||
|
||
impl Drop for AsyncTestContext { | ||
fn drop(&mut self) { | ||
let cleanup = self.cleanup.clone(); | ||
let handle = thread::spawn(move || { | ||
Runtime::new().expect("error creating runtime to handle cleanup").block_on(async move { | ||
let mut error_count = 0; | ||
for cleanup_fn in cleanup.lock().await.iter() { | ||
if let Err(err) = cleanup_fn().await { | ||
error_count += 1; | ||
log::error!("Error during cleanup: {:?}", err); | ||
} | ||
} | ||
if error_count > 0 { | ||
panic!("{} cleanup functions failed", error_count); | ||
} | ||
}) | ||
}); | ||
|
||
handle.join().expect("error joining cleanup thread"); | ||
} | ||
} | ||
|
||
#[fixture] | ||
pub fn context() -> AsyncTestContext { | ||
dotenvy::dotenv().expect("error loading environment variables"); | ||
tracing_subscriber::fmt().with_max_level(tracing::Level::INFO).init(); | ||
let api_token = | ||
env::var("TEST_AIRTABLE_API_TOKEN").expect("missing TEST_AIRTABLE_API_TOKEN variable"); | ||
let client = Airtable::new(&api_token, 5).expect("error creating Airtable client"); | ||
|
||
log::info!("Creating async test context"); | ||
|
||
AsyncTestContext { airtable: client, cleanup: Arc::new(Mutex::new(vec![])) } | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,52 @@ | ||
mod bases; | ||
mod fixtures; | ||
mod records; | ||
|
||
use serde::{Deserialize, Serialize}; | ||
|
||
#[derive(Debug, Serialize, Deserialize, Clone)] | ||
pub struct Customer { | ||
#[serde(rename = "Record Id")] | ||
pub record_id: String, | ||
#[serde(rename = "Customer Id")] | ||
pub customer_id: String, | ||
#[serde(rename = "First Name")] | ||
pub first_name: String, | ||
#[serde(rename = "Last Name")] | ||
pub last_name: String, | ||
#[serde(rename = "Company")] | ||
pub company: String, | ||
#[serde(rename = "City")] | ||
pub city: String, | ||
#[serde(rename = "Country")] | ||
pub country: String, | ||
#[serde(rename = "Phone 1")] | ||
pub phone_1: String, | ||
#[serde(rename = "Phone 2")] | ||
pub phone_2: String, | ||
#[serde(rename = "Email")] | ||
pub email: String, | ||
#[serde(rename = "Subscription Date")] | ||
pub subscription_date: String, | ||
#[serde(rename = "Website")] | ||
pub website: String, | ||
} | ||
|
||
impl Customer { | ||
pub fn field_names() -> Vec<&'static str> { | ||
vec![ | ||
"Record Id", | ||
"Customer Id", | ||
"First Name", | ||
"Last Name", | ||
"Company", | ||
"City", | ||
"Country", | ||
"Phone 1", | ||
"Phone 2", | ||
"Email", | ||
"Subscription Date", | ||
"Website", | ||
] | ||
} | ||
} |
Oops, something went wrong.