This repository has been archived by the owner on Jun 23, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 53
/
MaintenanceModeTest.kt
117 lines (102 loc) · 3.55 KB
/
MaintenanceModeTest.kt
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
package smoke
import org.awaitility.Awaitility.await
import org.http4k.cloudnative.env.Environment
import org.http4k.core.ContentType.Companion.APPLICATION_JSON
import org.http4k.core.Method.POST
import org.http4k.core.Request
import org.http4k.core.Status.Companion.SERVICE_UNAVAILABLE
import org.junit.jupiter.api.AfterEach
import org.junit.jupiter.api.BeforeEach
import org.junit.jupiter.api.Nested
import org.junit.jupiter.api.Tag
import org.junit.jupiter.api.Test
import smoke.actors.createHandler
import smoke.clients.AwsLambda
import smoke.env.SmokeTests
import java.time.Duration
@Tag("serial")
class MaintenanceModeTest {
private val config = SmokeTests.loadConfig()
private val client = createHandler(Environment.ENV)
private fun postRequest(uri: String, authHeader: String) =
Request(POST, uri)
.header("Authorization", authHeader)
.header("Content-Type", APPLICATION_JSON.value)
@Nested
inner class VirologySubmissionLambda {
@BeforeEach
fun setup() = AwsLambda.enableMaintenanceMode(config.virology_submission_lambda_function_name)
@AfterEach
fun tearDown() = AwsLambda.disableMaintenanceMode(config.virology_submission_lambda_function_name)
@Test
fun `order virology test`() {
assertInMaintenanceMode(
postRequest(
"${config.virology_kit_endpoint}/home-kit/order",
config.auth_headers.mobile
)
)
}
@Test
fun `retrieve virology test result`() {
assertInMaintenanceMode(
postRequest(
"${config.virology_kit_endpoint}/results",
config.auth_headers.mobile
)
)
}
}
@Nested
inner class VirologyUploadLambda {
@BeforeEach
fun setup() = AwsLambda.enableMaintenanceMode(config.virology_upload_lambda_function_name)
@AfterEach
fun tearDown() = AwsLambda.disableMaintenanceMode(config.virology_upload_lambda_function_name)
@Test
fun `upload npex test result`() {
assertInMaintenanceMode(
postRequest(
config.test_results_npex_upload_endpoint,
config.auth_headers.testResultUpload
)
)
}
@Test
fun `upload fiorano test result`() {
assertInMaintenanceMode(
postRequest(
config.test_results_fiorano_upload_endpoint,
config.auth_headers.testResultUpload
)
)
}
@Test
fun `upload english token-gen test result`() {
assertInMaintenanceMode(
postRequest(
config.test_results_eng_tokengen_upload_endpoint,
config.auth_headers.testResultUpload
)
)
}
@Test
fun `upload welsh token-gen test result`() {
assertInMaintenanceMode(
postRequest(
config.test_results_wls_tokengen_upload_endpoint,
config.auth_headers.testResultUpload
)
)
}
}
private fun assertInMaintenanceMode(request: Request) {
await()
.atMost(Duration.ofMinutes(1))
.pollInterval(Duration.ofSeconds(1))
.until {
val response = client(request)
response.status == SERVICE_UNAVAILABLE && response.bodyString() == ""
}
}
}