|
| 1 | +package aws.sdk.kotlin.codegen.endpoints |
| 2 | + |
| 3 | +import software.amazon.smithy.build.MockManifest |
| 4 | +import software.amazon.smithy.kotlin.codegen.KotlinCodegenPlugin |
| 5 | +import software.amazon.smithy.kotlin.codegen.core.GenerationContext |
| 6 | +import software.amazon.smithy.kotlin.codegen.core.KotlinDelegator |
| 7 | +import software.amazon.smithy.kotlin.codegen.core.KotlinWriter |
| 8 | +import software.amazon.smithy.kotlin.codegen.integration.KotlinIntegration |
| 9 | +import software.amazon.smithy.kotlin.codegen.rendering.protocol.ProtocolGenerator |
| 10 | +import software.amazon.smithy.kotlin.codegen.test.* |
| 11 | +import software.amazon.smithy.model.shapes.ShapeId |
| 12 | +import software.amazon.smithy.rulesengine.language.syntax.parameters.Parameter |
| 13 | +import software.amazon.smithy.rulesengine.language.syntax.parameters.ParameterType |
| 14 | +import kotlin.test.Test |
| 15 | +import kotlin.test.assertTrue |
| 16 | + |
| 17 | +class BindAwsEndpointBuiltinsTest { |
| 18 | + @Test |
| 19 | + fun testRenderAccountIdEndpointModeBuiltin() { |
| 20 | + val model = "".prependNamespaceAndService().toSmithyModel() |
| 21 | + val serviceName = TestModelDefault.SERVICE_NAME |
| 22 | + val packageName = TestModelDefault.NAMESPACE |
| 23 | + val settings = model.defaultSettings(serviceName, packageName) |
| 24 | + val generator = MockHttpProtocolGenerator(model) |
| 25 | + val integrations = emptyList<KotlinIntegration>() |
| 26 | + val manifest = MockManifest() |
| 27 | + val provider = KotlinCodegenPlugin.createSymbolProvider(model, settings = settings) |
| 28 | + val service = model.getShape(ShapeId.from("$packageName#$serviceName")).get().asServiceShape().get() |
| 29 | + val delegator = KotlinDelegator(settings, model, manifest, provider, integrations) |
| 30 | + |
| 31 | + val ctx = ProtocolGenerator.GenerationContext( |
| 32 | + settings, |
| 33 | + model, |
| 34 | + service, |
| 35 | + provider, |
| 36 | + integrations, |
| 37 | + generator.protocol, |
| 38 | + delegator, |
| 39 | + ) |
| 40 | + val writer = KotlinWriter(TestModelDefault.NAMESPACE) |
| 41 | + val parameters = listOf( |
| 42 | + Parameter |
| 43 | + .builder() |
| 44 | + .builtIn(AwsBuiltins.ACCOUNT_ID_ENDPOINT_MODE) |
| 45 | + .type(ParameterType.STRING) |
| 46 | + .name("accountIdEndpointMode") |
| 47 | + .build(), |
| 48 | + ) |
| 49 | + |
| 50 | + renderBindAwsBuiltins( |
| 51 | + ctx, |
| 52 | + writer, |
| 53 | + parameters, |
| 54 | + ) |
| 55 | + |
| 56 | + assertTrue( |
| 57 | + writer |
| 58 | + .rawString() |
| 59 | + .contains("accountIdEndpointMode = config.accountIdEndpointMode.toString().lowercase()"), |
| 60 | + ) |
| 61 | + } |
| 62 | +} |
0 commit comments