From d0f00a4ee83cf15c7eda6c68f957750a4a04e5d9 Mon Sep 17 00:00:00 2001 From: Neil Kakkar Date: Thu, 20 Jun 2024 17:04:12 +0100 Subject: [PATCH] clean up, pause PR here --- rust/feature-flags/README.md | 17 +++++++++ rust/feature-flags/src/fixtures/flags.sql | 0 .../src/fixtures/migrate_python_db.sh | 24 ------------ rust/feature-flags/src/flag_definitions.rs | 2 - rust/feature-flags/src/server.rs | 2 + rust/feature-flags/src/test_utils.rs | 37 ------------------- 6 files changed, 19 insertions(+), 63 deletions(-) delete mode 100644 rust/feature-flags/src/fixtures/flags.sql delete mode 100644 rust/feature-flags/src/fixtures/migrate_python_db.sh diff --git a/rust/feature-flags/README.md b/rust/feature-flags/README.md index 1c9500900aade..efce036124524 100644 --- a/rust/feature-flags/README.md +++ b/rust/feature-flags/README.md @@ -1,6 +1,23 @@ # Testing +First, make sure docker compose is running (from main posthog repo), and test database exists: + +``` +docker compose -f ../docker-compose.dev.yml up -d +``` + +``` +TEST=1 python manage.py setup_test_environment --only-postgres +``` + +We only need to run the above once, when the test database is created. + +TODO: Would be nice to make the above automatic. + + +Then, run the tests: + ``` cargo test --package feature-flags ``` diff --git a/rust/feature-flags/src/fixtures/flags.sql b/rust/feature-flags/src/fixtures/flags.sql deleted file mode 100644 index e69de29bb2d1d..0000000000000 diff --git a/rust/feature-flags/src/fixtures/migrate_python_db.sh b/rust/feature-flags/src/fixtures/migrate_python_db.sh deleted file mode 100644 index ac2b632848d12..0000000000000 --- a/rust/feature-flags/src/fixtures/migrate_python_db.sh +++ /dev/null @@ -1,24 +0,0 @@ -#!/bin/bash - -# Set the project directory -# TODO: Handle for CI and local -PROJECT_DIR="/Users/neilkakkar/Project/posthog" - -# Navigate to the project directory -cd "$PROJECT_DIR" - -# Activate the virtual environment -source env/bin/activate - -# Set the DEBUG environment variable -export DEBUG=1 - -# Set DATABASE_URL environment variable -export DATABASE_URL="postgres://posthog:posthog@localhost:5432/test_posthog_rs" - - -# Run the Django migration command -python manage.py migrate - -# Deactivate the virtual environment -deactivate \ No newline at end of file diff --git a/rust/feature-flags/src/flag_definitions.rs b/rust/feature-flags/src/flag_definitions.rs index 1486001b2efcc..cc208ae8b073f 100644 --- a/rust/feature-flags/src/flag_definitions.rs +++ b/rust/feature-flags/src/flag_definitions.rs @@ -33,8 +33,6 @@ pub enum OperatorType { IsDateBefore, } -// TODO: WAT? Is there a better way than just deriving this macro for PgHasArrayType? -// Maybe I should just extract the json and then serde deserialize it? #[derive(Debug, Clone, Deserialize)] pub struct PropertyFilter { pub key: String, diff --git a/rust/feature-flags/src/server.rs b/rust/feature-flags/src/server.rs index b8ad81a611bfb..a2fa8b5790b63 100644 --- a/rust/feature-flags/src/server.rs +++ b/rust/feature-flags/src/server.rs @@ -22,6 +22,8 @@ where .await .expect("failed to create postgres client"), ); + // TODO: Handle errors when creating postgres client, and redis client. + // Technically we can work with just one. let app = router::router(redis_client, postgres_client); diff --git a/rust/feature-flags/src/test_utils.rs b/rust/feature-flags/src/test_utils.rs index c1e2a62a7d57d..062fd78f1aa99 100644 --- a/rust/feature-flags/src/test_utils.rs +++ b/rust/feature-flags/src/test_utils.rs @@ -139,43 +139,6 @@ pub async fn setup_pg_client(url: Option) -> Arc { Arc::new(client) } -/// Run the Python migration script -pub fn run_database_migrations() -> anyhow::Result<()> { - // TODO: Make this more efficient by skipping migrations if they have already been run. - // TODO: Potentially create a separate db, test_posthog_rs, and use here. - // TODO: Running this in every test is too slow, can I create some setup where this runs only once, and all tests run after? - // Seems doable easily in CI, how about local dev? Potentially just make it a manual step for now. - // "Make sure db exists first by running this fn", and then tests will work..... - - let home_directory = fs::canonicalize("../../").expect("Failed to get home directory"); - let output = Command::new("python") - .current_dir(home_directory) - .arg("manage.py") - .arg("migrate") - .env("DEBUG", "1") - .env( - "DATABASE_URL", - "postgres://posthog:posthog@localhost:5432/test_posthog", - ) - .output() - .expect("Failed to execute migration script"); - - if !output.status.success() { - eprintln!( - "Migration script failed: {}", - String::from_utf8_lossy(&output.stderr) - ); - return Err(anyhow::anyhow!("Migration script execution failed")); - } - - println!( - "Migration script output: {}", - String::from_utf8_lossy(&output.stdout) - ); - - Ok(()) -} - pub async fn insert_new_team_in_pg(client: Arc) -> Result { const ORG_ID: &str = "019026a4be8000005bf3171d00629163";