5 5 | import aws.smithy.kotlin.runtime.http.interceptors.SmokeTestsFailureException
|
6 6 | import aws.smithy.kotlin.runtime.http.interceptors.SmokeTestsInterceptor
|
7 7 | import aws.smithy.kotlin.runtime.http.interceptors.SmokeTestsSuccessException
|
8 8 | import aws.smithy.kotlin.runtime.io.use
|
9 9 | import aws.smithy.kotlin.runtime.smoketests.exitProcess
|
10 10 | import aws.smithy.kotlin.runtime.util.PlatformProvider
|
11 11 |
|
12 12 | private var exitCode = 0
|
13 13 | private val skipTags = PlatformProvider.System.getenv("AWS_SMOKE_TEST_SKIP_TAGS")?.let { it.split(",").map { it.trim() }.toSet() } ?: emptySet()
|
14 14 | private val serviceFilter = PlatformProvider.System.getenv("AWS_SMOKE_TEST_SERVICE_IDS")?.let { it.split(",").map { it.trim() }.toSet() } ?: emptySet()
|
15 - | private val regionOverride = PlatformProvider.System.getenv("AWS_SMOKE_TEST_REGION")
|
16 15 |
|
17 16 | public suspend fun main() {
|
18 17 | describeInstancesFailure()
|
19 18 | describeRegionsSuccess()
|
20 19 | exitProcess(exitCode)
|
21 20 | }
|
22 21 |
|
23 22 | private suspend fun describeInstancesFailure() {
|
24 23 | val tags = setOf<String>()
|
25 24 | if ((serviceFilter.isNotEmpty() && "EC2" !in serviceFilter) || tags.any { it in skipTags }) {
|
26 25 | println("ok EC2 DescribeInstancesFailure - error expected from service # skip")
|
27 26 | return
|
28 27 | }
|
29 28 |
|
30 29 | try {
|
31 30 | aws.sdk.kotlin.services.ec2.Ec2Client {
|
32 - | region = regionOverride ?:
|
33 - | "us-west-2"
|
31 + | region = "us-west-2"
|
34 32 | interceptors.add(SmokeTestsInterceptor())
|
35 33 |
|
36 34 | }.use { client ->
|
37 35 | client.describeInstances(
|
38 36 | aws.sdk.kotlin.services.ec2.model.DescribeInstancesRequest {
|
39 37 | instanceIds = listOf("i-12345678")
|
40 38 | }
|
41 39 | )
|
42 40 | }
|
43 41 |
|
44 42 | } catch (e: Exception) {
|
45 43 | val success = e is SmokeTestsFailureException
|
46 44 | val status = if (success) "ok" else "not ok"
|
47 45 | println("$status EC2 DescribeInstancesFailure - error expected from service ")
|
48 46 | if (!success) exitCode = 1
|
49 47 | }
|
50 48 | }
|
51 49 |
|
52 50 | private suspend fun describeRegionsSuccess() {
|
53 51 | val tags = setOf<String>()
|
54 52 | if ((serviceFilter.isNotEmpty() && "EC2" !in serviceFilter) || tags.any { it in skipTags }) {
|
55 53 | println("ok EC2 DescribeRegionsSuccess - no error expected from service # skip")
|
56 54 | return
|
57 55 | }
|
58 56 |
|
59 57 | try {
|
60 58 | aws.sdk.kotlin.services.ec2.Ec2Client {
|
61 - | region = regionOverride ?:
|
62 - | "us-west-2"
|
59 + | region = "us-west-2"
|
63 60 | interceptors.add(SmokeTestsInterceptor())
|
64 61 |
|
65 62 | }.use { client ->
|
66 63 | client.describeRegions(
|
67 64 | aws.sdk.kotlin.services.ec2.model.DescribeRegionsRequest {
|
68 65 | }
|
69 66 | )
|
70 67 | }
|
71 68 |
|
72 69 | } catch (e: Exception) {
|