Skip to content

Commit

Permalink
clean up, pause PR here
Browse files Browse the repository at this point in the history
  • Loading branch information
neilkakkar committed Jun 20, 2024
1 parent 8c60f92 commit d0f00a4
Show file tree
Hide file tree
Showing 6 changed files with 19 additions and 63 deletions.
17 changes: 17 additions & 0 deletions rust/feature-flags/README.md
Original file line number Diff line number Diff line change
@@ -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
```
Expand Down
Empty file.
24 changes: 0 additions & 24 deletions rust/feature-flags/src/fixtures/migrate_python_db.sh

This file was deleted.

2 changes: 0 additions & 2 deletions rust/feature-flags/src/flag_definitions.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
2 changes: 2 additions & 0 deletions rust/feature-flags/src/server.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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);

Expand Down
37 changes: 0 additions & 37 deletions rust/feature-flags/src/test_utils.rs
Original file line number Diff line number Diff line change
Expand Up @@ -139,43 +139,6 @@ pub async fn setup_pg_client(url: Option<String>) -> Arc<PgClient> {
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<PgClient>) -> Result<Team, Error> {
const ORG_ID: &str = "019026a4be8000005bf3171d00629163";

Expand Down

0 comments on commit d0f00a4

Please sign in to comment.