-
Notifications
You must be signed in to change notification settings - Fork 31
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Create integration test configuration (#264)
* Create integration test configuration * Temporarily enable GitHub action for pull requests * Include service account identifier * Roll back action setup to clone of pre-merge * Remove application default config * Collapse integration tests into single execution * haha yes it works now * Update script from comments.js * Create debug step to containerize * Use block scalar with chomping * Include Git sample * Echo several lines of text * Echo command output * Roll back to previous version * Disable Terraform plan * Restore gradle build action step * Restore conditions and remove unnecessary steps * Restore Google Cloud Auth step * Include debugging for comment deletion step * Use for over forEach for enclosed await * Revise github actions workflow * Roll back comment changes * Fix variable name * Delete all existing comments * Log user state * Print the whole thing * once more, with data * How much longer must this go on? * Iterate over list items instead of keys * Adjust scripts, deletion behaviour * Include exports reference * Correct javascript lambda * Include javascript in spotless configuration * Trigger build * Include backticks for string literal * Remove indentation indicator * Formatting changes * Restore debug trigger for integration test * Further logging for comments filter * Moar comments * Asynchronous commands are asynchronous * Logs again... * Boolean not actually assigned to value * Simplify condition * Include return statement * Linespace chomping and console logs * How many times should i continue to make this mistake * Force rerun of test task * Remove test trigger, disable cache for integration --------- Co-authored-by: Davies Ashley <[email protected]>
- Loading branch information
Showing
13 changed files
with
236 additions
and
203 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,68 @@ | ||
name: Integration Tests | ||
|
||
on: | ||
workflow_dispatch: | ||
inputs: | ||
debug: | ||
description: 'Debug' | ||
required: false | ||
default: false | ||
type: boolean | ||
|
||
concurrency: | ||
group: ${{ github.workflow }}-${{ github.ref }} | ||
cancel-in-progress: true | ||
|
||
jobs: | ||
build: | ||
runs-on: ubuntu-latest | ||
|
||
permissions: | ||
id-token: 'write' | ||
|
||
steps: | ||
- name: Setup JDK | ||
uses: actions/setup-java@v3 | ||
with: | ||
distribution: temurin | ||
java-version: 17 | ||
|
||
- name: Checkout Repository | ||
uses: actions/checkout@v3 | ||
with: | ||
fetch-depth: 0 | ||
|
||
- name: Google Cloud Auth | ||
id: google_cloud_auth | ||
uses: google-github-actions/auth@v1 | ||
with: | ||
workload_identity_provider: ${{ secrets.GOOGLE_WORKLOAD_IDENTITY }} | ||
service_account: ${{ secrets.GOOGLE_SERVICE_ACCOUNT_ID }} | ||
token_format: access_token | ||
|
||
- name: Run Gradle Tasks | ||
id: gradle_build | ||
uses: gradle/gradle-build-action@v2 | ||
env: | ||
GOOGLE_PROJECT_API_KEY: ${{ secrets.google_project_api_key }} | ||
GOOGLE_SERVICE_ACCOUNT_ID: ${{ secrets.GOOGLE_SERVICE_ACCOUNT_ID }} | ||
MOBILE_SDK_APP_ID: ${{ secrets.mobile_sdk_app_id }} | ||
PLAYGROUND_API_KEY: ${{ secrets.PLAYGROUND_API_KEY }} | ||
with: | ||
gradle-home-cache-cleanup: true | ||
arguments: > | ||
cloud-run:integrationTest | ||
${{ inputs.debug && '--debug' || '--info' }} | ||
--console=plain | ||
- name: Produce Test Summary | ||
uses: test-summary/action@v2 | ||
with: | ||
paths: "**/build/test-results/test/TEST-*.xml" | ||
|
||
- name: Upload Test Report | ||
uses: actions/upload-artifact@v3 | ||
with: | ||
name: test-report | ||
path: "**/build/reports/tests" | ||
if-no-files-found: error |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
132 changes: 132 additions & 0 deletions
132
cloud-run/src/jvmIntegrationTest/kotlin/io/ashdavies/cloud/ApplicationTest.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,132 @@ | ||
package io.ashdavies.cloud | ||
|
||
import io.ashdavies.http.AppCheckToken | ||
import io.ashdavies.playground.models.Event | ||
import io.ashdavies.playground.models.FirebaseApp | ||
import io.ktor.client.HttpClient | ||
import io.ktor.client.HttpClientConfig | ||
import io.ktor.client.call.body | ||
import io.ktor.client.engine.HttpClientEngineConfig | ||
import io.ktor.client.plugins.contentnegotiation.ContentNegotiation | ||
import io.ktor.client.request.get | ||
import io.ktor.client.request.header | ||
import io.ktor.client.request.post | ||
import io.ktor.client.request.put | ||
import io.ktor.client.request.setBody | ||
import io.ktor.client.statement.bodyAsText | ||
import io.ktor.http.ContentType | ||
import io.ktor.http.HttpHeaders | ||
import io.ktor.http.HttpStatusCode | ||
import io.ktor.http.contentType | ||
import io.ktor.serialization.kotlinx.json.json | ||
import io.ktor.server.application.Application | ||
import io.ktor.server.testing.ApplicationTestBuilder | ||
import io.ktor.server.testing.testApplication | ||
import io.ktor.util.KtorDsl | ||
import kotlinx.coroutines.ExperimentalCoroutinesApi | ||
import kotlinx.serialization.Serializable | ||
import kotlin.test.Test | ||
import kotlin.test.assertEquals | ||
import kotlin.test.assertNotNull | ||
|
||
private val DefaultHttpConfig: HttpClientConfig<out HttpClientEngineConfig>.() -> Unit = { | ||
install(ContentNegotiation, ContentNegotiation.Config::json) | ||
} | ||
|
||
@ExperimentalCoroutinesApi | ||
internal class ApplicationTest { | ||
|
||
@Test | ||
fun `should sign in with custom token`() = testMainApplication { client -> | ||
val apiKey = requireNotNull(System.getenv("GOOGLE_PROJECT_API_KEY")) | ||
|
||
val authResult = client.post("/firebase/auth") { | ||
setBody(mapOf("uid" to "[email protected]")) | ||
contentType(ContentType.Application.Json) | ||
header("X-API-Key", apiKey) | ||
}.body<Map<String, String>>() | ||
|
||
assertNotNull(authResult["idToken"]) | ||
} | ||
|
||
@Test | ||
fun `should get events with default limit`() = testMainApplication { client -> | ||
val response = client.get("/events") { contentType(ContentType.Application.Json) } | ||
val body = response.body<List<Event>>() | ||
|
||
assertEquals(50, body.size) | ||
} | ||
|
||
@Test | ||
fun `should aggregate events`() = testMainApplication { client -> | ||
val client = createClient { install(ContentNegotiation, ContentNegotiation.Config::json) } | ||
val response = client.post("/events:aggregate") | ||
|
||
assertEquals(HttpStatusCode.OK, response.status) | ||
} | ||
|
||
@Test | ||
fun `should create test application`() = testMainApplication { client -> | ||
val response = client.get("/hello") | ||
|
||
assertEquals( | ||
expected = HttpStatusCode.OK, | ||
actual = response.status, | ||
) | ||
|
||
assertEquals( | ||
actual = response.bodyAsText(), | ||
expected = "Hello, World!", | ||
) | ||
} | ||
|
||
@Test | ||
fun `should return app check token for request`() = testMainApplication { client -> | ||
val tokenResponse = client.post("/firebase/token") { | ||
setBody(FirebaseApp(System.getenv("MOBILE_SDK_APP_ID"))) | ||
// headers { append("X-API-Key", playgroundApiKey) } | ||
contentType(ContentType.Application.Json) | ||
}.body<TokenResponse>() | ||
|
||
assertEquals( | ||
actual = tokenResponse.ttlMillis, | ||
expected = 3_600_000, | ||
) | ||
|
||
val verifyResponse = client.put("/firebase/token:verify") { | ||
header(HttpHeaders.AppCheckToken, tokenResponse.token) | ||
}.body<VerifyResponse>() | ||
|
||
assertEquals( | ||
expected = verifyResponse.appId, | ||
actual = verifyResponse.subject, | ||
) | ||
} | ||
} | ||
|
||
@KtorDsl | ||
private fun testMainApplication( | ||
configuration: HttpClientConfig<out HttpClientEngineConfig>.() -> Unit = DefaultHttpConfig, | ||
application: Application.() -> Unit = { main() }, | ||
block: suspend ApplicationTestBuilder.(HttpClient) -> Unit, | ||
) = testApplication { | ||
val client = createClient(configuration) | ||
application(application) | ||
block(client) | ||
} | ||
|
||
@Serializable | ||
private data class TokenResponse( | ||
val ttlMillis: Long, | ||
val token: String, | ||
) | ||
|
||
@Serializable | ||
private data class VerifyResponse( | ||
val audience: List<String>, | ||
val expiresAt: Long, | ||
val subject: String, | ||
val issuedAt: Long, | ||
val issuer: String, | ||
val appId: String, | ||
) |
28 changes: 0 additions & 28 deletions
28
cloud-run/src/jvmIntegrationTest/kotlin/io/ashdavies/cloud/AuthTest.kt
This file was deleted.
Oops, something went wrong.
32 changes: 0 additions & 32 deletions
32
cloud-run/src/jvmIntegrationTest/kotlin/io/ashdavies/cloud/EventsTest.kt
This file was deleted.
Oops, something went wrong.
Oops, something went wrong.