Skip to content

Commit

Permalink
Merge pull request #64 from ISibboI/60-add-debug-mode-to-backend
Browse files Browse the repository at this point in the history
Add integration test mode
  • Loading branch information
ISibboI authored Oct 14, 2023
2 parents 4e06d15 + bf1c5fa commit ceeff31
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 1 deletion.
4 changes: 3 additions & 1 deletion .github/workflows/web-api-ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,9 @@ jobs:
run: nix build --out-link integrationTestsBinary .#integrationTestsBinary

- name: Set up environment variables
run: echo "PASSWORD_PEPPER=test-test-test-test" >> $GITHUB_ENV
run: |
echo "PASSWORD_PEPPER=test-test-test-test" >> $GITHUB_ENV
echo "RVOC_INTEGRATION_TEST_MODE=true" >> $GITHUB_ENV
- name: Run database migrations
run: debugBinary/bin/rvoc-backend apply-migrations
Expand Down
10 changes: 10 additions & 0 deletions backend/rvoc-backend/src/configuration/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,11 @@ use secstr::SecUtf8;
/// The configuration of the application.
#[derive(Debug, Clone)]
pub struct Configuration {
/// If set, then some features that are unsuitable for integration tests are disabled.
/// For example:
/// * Do not run the wiktionary update.
pub integration_test_mode: bool,

/// The url to access postgres.
pub postgres_url: SecUtf8,

Expand Down Expand Up @@ -81,6 +86,10 @@ impl Configuration {
/// Read the configuration values from environment variables.
pub fn from_environment() -> RVocResult<Self> {
let result = Self {
integration_test_mode: read_env_var_with_default_as_type(
"RVOC_INTEGRATION_TEST_MODE",
false,
)?,
postgres_url: read_env_var_with_default_as_type(
"POSTGRES_RVOC_URL",
"postgres://rvoc@localhost/rvoc",
Expand Down Expand Up @@ -186,6 +195,7 @@ impl Configuration {

pub fn test_configuration() -> Self {
Self {
integration_test_mode: true,
postgres_url: "postgres://rvoc@localhost/rvoc".into(),
opentelemetry_url: None,
shutdown_timeout: Duration::seconds(30),
Expand Down
7 changes: 7 additions & 0 deletions backend/rvoc-backend/src/job_queue/jobs/update_witkionary.rs
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
use tracing::warn;

use crate::{
configuration::Configuration, database::RVocAsyncDatabaseConnectionPool, error::RVocResult,
update_wiktionary::run_update_wiktionary,
Expand All @@ -7,5 +9,10 @@ pub async fn update_wiktionary(
database_connection_pool: &RVocAsyncDatabaseConnectionPool,
configuration: &Configuration,
) -> RVocResult<()> {
if configuration.integration_test_mode {
warn!("Not running update_wiktionary because integration_test_mode is enabled");
return Ok(());
}

run_update_wiktionary(database_connection_pool, configuration).await
}

0 comments on commit ceeff31

Please sign in to comment.