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

Can't generated endpoint tests if operation shape is not in same namespace as service #2767

Closed
mcmasn-amzn opened this issue Jun 13, 2023 · 2 comments

Comments

@mcmasn-amzn
Copy link
Contributor

I'm trying to use smithy.rules#endpointTests, but running into an error ExpectationNotMetException: Shape not found in model.

My model looks like this

namespace my.service

use their.namespace#ListFoo

service MyService {
   operations: [ListFoo]
}
namespace their.namespace

operation ListFoo {}

My endpoint test looks like this

use smithy.rules#endpointTests
apply MyService @endpointTests({"version": "1" "testCases": [
  {
        "documentation": "Endpoint override"
        "expect": {
            "endpoint": {
                "url": "http://localhost:4000"
            }
        }
        "params": {
            "endpoint": "http://localhost:4000"
        }
        "operationInputs": [
            { "operationName": "ListFoo", "operationParams": {} }
        ]
    }
]})

Root cause

It seems the root cause is an assumption here that operation is in the same namespace as the service object.

https://github.com/awslabs/smithy-rs/blob/8e37d42f3cc01da7b3d8efd9ff3433d564d4debf/aws/sdk-codegen/src/main/kotlin/software/amazon/smithy/rustsdk/endpoints/OperationInputTestGenerator.kt#L125-L126

Suggestions

  • lookup operation shape ID by searching the ServiceShape::getAllOperations
  • Support a qualified shaped ID
  • add a new parameter to set operation namespace

Stack traces

When shape is not in same namespace

Projection foo-client failed: software.amazon.smithy.model.node.ExpectationNotMetException: Shape not found in model: their.namespace#ListFoo
software.amazon.smithy.model.node.ExpectationNotMetException: Shape not found in model: their.namespace#ListFoo
        at software.amazon.smithy.model.Model.lambda$expectShape$1(Model.java:713)
        at java.base/java.util.Optional.orElseThrow(Optional.java:403)
        at software.amazon.smithy.model.Model.expectShape(Model.java:713)
        at software.amazon.smithy.model.Model.expectShape(Model.java:729)
        at software.amazon.smithy.rustsdk.endpoints.OperationInputTestGenerator$operationInvocation$1.invoke(OperationInputTestGenerator.kt:186)
        at software.amazon.smithy.rustsdk.endpoints.OperationInputTestGenerator$operationInvocation$1.invoke(OperationInputTestGenerator.kt:183)
        at software.amazon.smithy.rust.codegen.core.rustlang.RustWriter$RustSymbolFormatter.apply(RustWriter.kt:794)
        at software.amazon.smithy.rust.codegen.core.rustlang.RustWriter$RustSymbolFormatter.apply(RustWriter.kt:767)
        at software.amazon.smithy.utils.AbstractCodeWriter.applyFormatter(AbstractCodeWriter.java:1989)
        at software.amazon.smithy.utils.CodeFormatter$Operation.lambda$formatted$1(CodeFormatter.java:108)
        at software.amazon.smithy.utils.CodeFormatter$BlockOperation$Unconditional.apply(CodeFormatter.java:228)
        at software.amazon.smithy.utils.CodeFormatter.run(CodeFormatter.java:41)
        at software.amazon.smithy.utils.AbstractCodeWriter.format(AbstractCodeWriter.java:1673)
        at software.amazon.smithy.utils.AbstractCodeWriter.write(AbstractCodeWriter.java:1732)
        at software.amazon.smithy.rust.codegen.core.rustlang.RustWriter.write(RustWriter.kt:515)
        at software.amazon.smithy.rust.codegen.core.rustlang.RustWriterKt$rustTemplate$1.invoke(RustWriter.kt:238)
        at software.amazon.smithy.rust.codegen.core.rustlang.RustWriterKt$rustTemplate$1.invoke(RustWriter.kt:237)
        at software.amazon.smithy.rust.codegen.core.rustlang.RustWriterKt.withTemplate(RustWriter.kt:111)
        at software.amazon.smithy.rust.codegen.core.rustlang.RustWriterKt.withTemplate$default(RustWriter.kt:97)
        at software.amazon.smithy.rust.codegen.core.rustlang.RustWriterKt.rustTemplate(RustWriter.kt:237)
        at software.amazon.smithy.rustsdk.endpoints.OperationInputTestGenerator$generateInput$1$1.invoke(OperationInputTestGenerator.kt:139)
        at software.amazon.smithy.rustsdk.endpoints.OperationInputTestGenerator$generateInput$1$1.invoke(OperationInputTestGenerator.kt:138)

@rcoh
Copy link
Collaborator

rcoh commented Jun 13, 2023

hmmm...this is actually a fundamental limitation of the endpoint tests traits. Your idea of searching all operations is a good one as a stopgap 👍🏻

github-merge-queue bot pushed a commit that referenced this issue Jul 10, 2023
…2782)

## Motivation and Context
Addresses #2767

This fixes an issue for users who write endpoint tests that rely on an
operation and service shape from different namespaces.

## Description
Instead of assuming operation namespace matches service namespace, 

## Testing
`./gradlew :aws:sdk-codegen:test`


----

_By submitting this pull request, I confirm that you can use, modify,
copy, and redistribute this contribution, under the terms of your
choice._

---------

Co-authored-by: Zelda Hessler <[email protected]>
@mcmasn-amzn
Copy link
Contributor Author

Resolved with #2782

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants