Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add integration test mode #64

Merged
merged 1 commit into from
Oct 14, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
}
Loading