Skip to content

Commit

Permalink
Use stage LOCALTEST for running tests locally (#26973)
Browse files Browse the repository at this point in the history
* Use stage `LOCALTEST` for running tests locally

Frontend has the concept of a `DEVINFRA` stage which *sort of* means
`CI`. Setting this stage has the following behaviour:

- Mocks configuration with a local file, instead of resolving
  configuration from AWS Parameter Store. This means running tests does
  not require AWS Credentials
  - Desirable for running tests in CI and locally
- Fails tests where the database of mocked request responses is out of
  date, instead of generating database updates that can be committed.
  - Desirable in CI, but not locally. We want to generate the files when
    we run the tests locally so we can commit them as part of the PR

Since #26058 we have been running all tests (in CI and locally) with
stage `DEVINFRA` but this results in issues like #26972.

This change:

- introduces a new stage `LOCALTEST` which is used when running tests on
  a developer machine
  - this stage will use the same mocked configuration as `DEVINFRA`, so
    AWS credentials are not required
  - this stage will create any necessary database files/updates instead
    of failing the tests
  - `LOCALTEST` is selected when running tests locally, but not in `CI`
    where we want to continue using `DEVINFRA`
- `DEVINFRA` continues to behave as before

Closes #26972

---------

Co-authored-by: Charlotte Emms <[email protected]>
  • Loading branch information
georgeblahblah and cemms1 authored Mar 15, 2024
1 parent a73dcf9 commit 198684c
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 2 deletions.
2 changes: 1 addition & 1 deletion common/app/common/configuration.scala
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,7 @@ object GuardianConfiguration extends GuLogging {
private lazy val parameterStore = new ParameterStore(awsRegion)

lazy val configuration: Config = {
if (stage == "DEVINFRA")
if (stage == "DEVINFRA" || stage == "LOCALTEST")
ConfigFactory.parseResourcesAnySyntax("env/DEVINFRA.properties")
else {
val userPrivate = configFromFile(s"${System.getProperty("user.home")}/.gu/frontend.conf", "devOverrides")
Expand Down
5 changes: 4 additions & 1 deletion project/ProjectSettings.scala
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,9 @@ object ProjectSettings {
.withWarnScalaVersionEviction(false),
)

def isCi = sys.env.get("CI").getOrElse("false") == "true"
def testStage = if (isCi) "DEVINFRA" else "LOCALTEST"

val frontendTestSettings = Seq(
// Use ScalaTest https://groups.google.com/d/topic/play-framework/rZBfNoGtC0M/discussion
Test / testOptions := Nil,
Expand All @@ -77,7 +80,7 @@ object ProjectSettings {
Test / javaOptions += "-XX:+UseConcMarkSweepGC",
Test / javaOptions += "-XX:ReservedCodeCacheSize=128m",
Test / baseDirectory := file("."),
Test / envVars := Map("STAGE" -> "DEVINFRA"),
Test / envVars := Map("STAGE" -> testStage),
// Set testResultLogger back to the default, fixes an issue with `sbt-teamcity-logger`
// See: https://github.com/JetBrains/sbt-tc-logger/issues/9
Test / test / testResultLogger := TestResultLogger.Default,
Expand Down

0 comments on commit 198684c

Please sign in to comment.