forked from smithy-lang/smithy-rs
-
Notifications
You must be signed in to change notification settings - Fork 0
/
TestHelpers.kt
80 lines (74 loc) · 3.06 KB
/
TestHelpers.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
/*
* Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
* SPDX-License-Identifier: Apache-2.0
*/
package software.amazon.smithy.rust.codegen.client.testutil
import software.amazon.smithy.model.Model
import software.amazon.smithy.model.knowledge.NullableIndex
import software.amazon.smithy.model.node.ObjectNode
import software.amazon.smithy.model.shapes.ServiceShape
import software.amazon.smithy.model.shapes.ShapeId
import software.amazon.smithy.rust.codegen.client.smithy.ClientCodegenConfig
import software.amazon.smithy.rust.codegen.client.smithy.ClientModuleProvider
import software.amazon.smithy.rust.codegen.client.smithy.ClientRustSettings
import software.amazon.smithy.rust.codegen.client.smithy.RustClientCodegenPlugin
import software.amazon.smithy.rust.codegen.core.smithy.CodegenContext
import software.amazon.smithy.rust.codegen.core.smithy.CodegenTarget
import software.amazon.smithy.rust.codegen.core.smithy.CoreRustSettings
import software.amazon.smithy.rust.codegen.core.smithy.RuntimeConfig
import software.amazon.smithy.rust.codegen.core.smithy.RustSymbolProvider
import software.amazon.smithy.rust.codegen.core.smithy.RustSymbolProviderConfig
import software.amazon.smithy.rust.codegen.core.testutil.TestRuntimeConfig
import software.amazon.smithy.rust.codegen.core.testutil.testRustSettings
fun clientTestRustSettings(
service: ShapeId = ShapeId.from("notrelevant#notrelevant"),
moduleName: String = "test-module",
moduleVersion: String = "0.0.1",
moduleAuthors: List<String> = listOf("notrelevant"),
moduleDescription: String = "not relevant",
moduleRepository: String? = null,
runtimeConfig: RuntimeConfig = TestRuntimeConfig,
codegenConfig: ClientCodegenConfig = ClientCodegenConfig(),
license: String? = null,
examplesUri: String? = null,
customizationConfig: ObjectNode? = null,
) = ClientRustSettings(
service,
moduleName,
moduleVersion,
moduleAuthors,
moduleDescription,
moduleRepository,
runtimeConfig,
codegenConfig,
license,
examplesUri,
customizationConfig,
)
val ClientTestRustSymbolProviderConfig = RustSymbolProviderConfig(
runtimeConfig = TestRuntimeConfig,
renameExceptions = true,
nullabilityCheckMode = NullableIndex.CheckMode.CLIENT_ZERO_VALUE_V1,
moduleProvider = ClientModuleProvider,
)
fun testSymbolProvider(model: Model, serviceShape: ServiceShape? = null): RustSymbolProvider =
RustClientCodegenPlugin.baseSymbolProvider(
model,
serviceShape ?: ServiceShape.builder().version("test").id("test#Service").build(),
ClientTestRustSymbolProviderConfig,
)
fun testCodegenContext(
model: Model,
serviceShape: ServiceShape? = null,
settings: CoreRustSettings = testRustSettings(),
codegenTarget: CodegenTarget = CodegenTarget.CLIENT,
): CodegenContext = CodegenContext(
model,
testSymbolProvider(model),
serviceShape
?: model.serviceShapes.firstOrNull()
?: ServiceShape.builder().version("test").id("test#Service").build(),
ShapeId.from("test#Protocol"),
settings,
codegenTarget,
)