-
Notifications
You must be signed in to change notification settings - Fork 252
Expand file tree
/
Copy pathTestUtil.kt
More file actions
86 lines (80 loc) · 3.67 KB
/
TestUtil.kt
File metadata and controls
86 lines (80 loc) · 3.67 KB
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
/*
* Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
* SPDX-License-Identifier: Apache-2.0
*/
package software.amazon.smithy.rustsdk
import software.amazon.smithy.model.Model
import software.amazon.smithy.model.node.ObjectNode
import software.amazon.smithy.rust.codegen.client.smithy.ClientCodegenContext
import software.amazon.smithy.rust.codegen.client.smithy.ClientRustSettings
import software.amazon.smithy.rust.codegen.client.smithy.RustClientCodegenPlugin
import software.amazon.smithy.rust.codegen.client.smithy.customize.ClientCodegenDecorator
import software.amazon.smithy.rust.codegen.client.testutil.ClientDecoratableBuildPlugin
import software.amazon.smithy.rust.codegen.client.testutil.clientIntegrationTest
import software.amazon.smithy.rust.codegen.client.testutil.testClientCodegenContext
import software.amazon.smithy.rust.codegen.client.testutil.testClientRustSettings
import software.amazon.smithy.rust.codegen.core.smithy.RuntimeCrateLocation
import software.amazon.smithy.rust.codegen.core.smithy.RustCrate
import software.amazon.smithy.rust.codegen.core.testutil.IntegrationTestParams
import software.amazon.smithy.rust.codegen.core.testutil.TestRuntimeConfig
import software.amazon.smithy.rust.codegen.core.testutil.asSmithyModel
import java.io.File
// In aws-sdk-codegen, the working dir when gradle runs tests is actually `./aws`. So, to find the smithy runtime, we need
// to go up one more level
val AwsTestRuntimeConfig =
TestRuntimeConfig.copy(
runtimeCrateLocation =
run {
val path = File("../../rust-runtime")
check(path.exists()) { "$path must exist to generate a working SDK" }
RuntimeCrateLocation.path(path.absolutePath)
},
)
fun awsTestCodegenContext(
model: Model? = null,
settings: ClientRustSettings? = null,
) = testClientCodegenContext(
model ?: "namespace test".asSmithyModel(),
settings = settings ?: testClientRustSettings(runtimeConfig = AwsTestRuntimeConfig),
)
fun awsSdkIntegrationTest(
model: Model,
params: IntegrationTestParams = awsIntegrationTestParams(),
additionalDecorators: List<ClientCodegenDecorator> = listOf(),
buildPlugin: ClientDecoratableBuildPlugin = RustClientCodegenPlugin(),
environment: Map<String, String> = mapOf(),
test: (ClientCodegenContext, RustCrate) -> Unit = { _, _ -> },
) = clientIntegrationTest(
model,
params,
additionalDecorators = additionalDecorators,
buildPlugin = buildPlugin,
environment = environment,
test = test,
)
fun awsIntegrationTestParams() =
IntegrationTestParams(
cargoCommand = "cargo test --features test-util,behavior-version-latest --tests --lib",
runtimeConfig = AwsTestRuntimeConfig,
additionalSettings =
ObjectNode.builder().withMember(
"customizationConfig",
ObjectNode.builder()
.withMember(
"awsSdk",
ObjectNode.builder()
.withMember("awsSdkBuild", true)
.withMember("suppressReadme", true)
.withMember("integrationTestPath", "../sdk/integration-tests")
.withMember("partitionsConfigPath", "../sdk/aws-models/sdk-partitions.json")
.build(),
).build(),
)
.withMember(
"codegen",
ObjectNode.builder()
.withMember("includeFluentClient", false)
.withMember("includeEndpointUrlConfig", false)
.build(),
).build(),
)