Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: update test operation generator to find any operation in the service closure #3922

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@

package software.amazon.smithy.rustsdk.endpoints

import software.amazon.smithy.model.knowledge.TopDownIndex
import software.amazon.smithy.model.node.Node
import software.amazon.smithy.model.shapes.OperationShape
import software.amazon.smithy.model.shapes.ShapeId
Expand Down Expand Up @@ -222,4 +223,7 @@ class OperationInputTestGenerator(_ctx: ClientCodegenContext, private val test:
}

fun ClientCodegenContext.operationId(testOperationInput: EndpointTestOperationInput): ShapeId =
this.serviceShape.allOperations.first { it.name == testOperationInput.operationName }
TopDownIndex.of(this.model)
.getContainedOperations(this.serviceShape)
.map { it.toShapeId() }
.first { it.name == testOperationInput.operationName }
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,50 @@ class OperationInputTestGeneratorTests {
assertEquals("operations#Ping", operationId.toString())
}

@Test
fun `finds operation shape by name from nested operations`() {
val prefix = "\$version: \"2\""
val operationModel =
"""
$prefix
namespace operations.bells
resource Bell {
operations: [Ding]
}
operation Ding {}
""".trimIndent()
val serviceModel =
"""
$prefix
namespace service
use operations.bells#Bell
service MyService {
resources: [Bell]
}
""".trimIndent()

val model =
Model.assembler()
.discoverModels()
.addUnparsedModel("operation.smithy", operationModel)
.addUnparsedModel("main.smithy", serviceModel)
.assemble()
.unwrap()

val context = testClientCodegenContext(model)
val testOperationInput =
EndpointTestOperationInput.builder()
.operationName("Ding")
.build()

val operationId = context.operationId(testOperationInput)
assertEquals("operations.bells#Ding", operationId.toString())
}

@Test
fun `fails for operation name not found`() {
val model =
Expand Down
Loading