Skip to content

Commit 1d75257

Browse files
committed
test(core): Use forAll instead of a test matrix
Use `forAll` instead of a test matrix in the tests for the keep alive option. This reduces the duration of those tests from roughly 90 seconds to below 20 seconds, because the Keycloak realm is not recreated for every single API call. Signed-off-by: Martin Nonnenmacher <[email protected]>
1 parent dbf2a93 commit 1d75257

File tree

1 file changed

+29
-27
lines changed

1 file changed

+29
-27
lines changed

core/src/test/kotlin/api/RepositoriesRouteIntegrationTest.kt

Lines changed: 29 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -895,15 +895,16 @@ class RepositoriesRouteIntegrationTest : AbstractIntegrationTest({
895895
ForbiddenKeepAliveWorkerTestcase("Scanner", "scannerKeepAlive", keepAliveScanner = true)
896896
)
897897

898-
keepAliveTestCases.forEach { testCase ->
899-
"respond with 'Forbidden' if 'keepAliveWorker' set in the ${testCase.workerName} config (non super-user)" {
900-
integrationTestApplication {
901-
val repositoryId = createRepository().id
898+
"respond with 'Forbidden' if 'keepAliveWorker' is set by a non super-user" {
899+
integrationTestApplication {
900+
val repositoryId = createRepository().id
902901

903-
keycloak.keycloakAdminClient.addUserRole(
904-
TEST_USER.username.value,
905-
RepositoryPermission.TRIGGER_ORT_RUN.roleName(repositoryId)
906-
)
902+
keycloak.keycloakAdminClient.addUserRole(
903+
TEST_USER.username.value,
904+
RepositoryPermission.TRIGGER_ORT_RUN.roleName(repositoryId)
905+
)
906+
907+
keepAliveTestCases.forAll { testCase ->
907908
val createRun = CreateOrtRun(
908909
"main",
909910
null,
@@ -926,15 +927,18 @@ class RepositoriesRouteIntegrationTest : AbstractIntegrationTest({
926927
response.body<ErrorResponse>().message shouldContainIgnoringCase testCase.workerName
927928
}
928929
}
930+
}
929931

930-
"respond with 'Forbidden' if '${testCase.parameterName}' set configuration parameters (non super-user)" {
931-
integrationTestApplication {
932-
val repositoryId = createRepository().id
932+
"respond with 'Forbidden' if the 'keepAlive' parameter is set by a non super-user" {
933+
integrationTestApplication {
934+
val repositoryId = createRepository().id
933935

934-
keycloak.keycloakAdminClient.addUserRole(
935-
TEST_USER.username.value,
936-
RepositoryPermission.TRIGGER_ORT_RUN.roleName(repositoryId)
937-
)
936+
keycloak.keycloakAdminClient.addUserRole(
937+
TEST_USER.username.value,
938+
RepositoryPermission.TRIGGER_ORT_RUN.roleName(repositoryId)
939+
)
940+
941+
keepAliveTestCases.forAll { testCase ->
938942
val createRun = CreateOrtRun(
939943
"main",
940944
null,
@@ -959,14 +963,13 @@ class RepositoriesRouteIntegrationTest : AbstractIntegrationTest({
959963
response.body<ErrorResponse>().message shouldContainIgnoringCase testCase.workerName
960964
}
961965
}
966+
}
962967

963-
"continue if 'keepAliveWorker' is true in the ${testCase.workerName} config (super-user calling)" {
964-
integrationTestApplication {
965-
val repositoryId = createRepository().id
968+
"continue if 'keepAliveWorker' is set by a super-user" {
969+
integrationTestApplication {
970+
val repositoryId = createRepository().id
966971

967-
val analyzerJob = AnalyzerJobConfiguration(
968-
keepAliveWorker = true,
969-
)
972+
keepAliveTestCases.forAll { testCase ->
970973
val createRun = CreateOrtRun(
971974
"main",
972975
null,
@@ -987,14 +990,13 @@ class RepositoriesRouteIntegrationTest : AbstractIntegrationTest({
987990
response shouldHaveStatus HttpStatusCode.Created
988991
}
989992
}
993+
}
990994

991-
"continue if '${testCase.parameterName}' is defined in configuration parameters (super-user calling)" {
992-
integrationTestApplication {
993-
val repositoryId = createRepository().id
995+
"continue if the 'keepAlive' parameter is set by a super-user" {
996+
integrationTestApplication {
997+
val repositoryId = createRepository().id
994998

995-
val analyzerJob = AnalyzerJobConfiguration(
996-
keepAliveWorker = true,
997-
)
999+
keepAliveTestCases.forAll { testCase ->
9981000
val createRun = CreateOrtRun(
9991001
"main",
10001002
null,

0 commit comments

Comments
 (0)