-
Notifications
You must be signed in to change notification settings - Fork 55
misc: make route 53 uri tests resilient to model version changes #1540
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
Merged
Merged
Changes from 6 commits
Commits
Show all changes
9 commits
Select commit
Hold shift + click to select a range
db27155
misc: make route 53 uri tests resilient to model version changes
0marperez 549c70e
misc: clean up
0marperez 4ed128f
misc: clean up 2
0marperez 18a5af9
trigger CI
0marperez 52b5e2b
fix: add dummy credentials to tests
0marperez 595be9b
Merge branch 'main' of https://github.com/awslabs/aws-sdk-kotlin into…
0marperez bd361c8
misc: add HTTP_TEST dependency to all e2e test source sets
0marperez 629a7f3
fix: dependency application
0marperez 3e4a0b6
fix: scope down dependency
0marperez File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,168 @@ | ||
| package aws.sdk.kotlin.services.route53 | ||
|
|
||
| import aws.sdk.kotlin.runtime.auth.credentials.StaticCredentialsProvider | ||
| import aws.smithy.kotlin.runtime.auth.awscredentials.Credentials | ||
| import aws.smithy.kotlin.runtime.client.ProtocolRequestInterceptorContext | ||
| import aws.smithy.kotlin.runtime.http.interceptors.HttpInterceptor | ||
| import aws.smithy.kotlin.runtime.http.request.HttpRequest | ||
| import aws.smithy.kotlin.runtime.httptest.TestEngine | ||
| import kotlinx.coroutines.test.runTest | ||
| import kotlin.test.Test | ||
| import kotlin.test.assertEquals | ||
| import kotlin.test.fail | ||
|
|
||
| class Route53UriTest { | ||
| /** | ||
| * Validates that HostedZoneId isn't trimmed when not prefixed | ||
| */ | ||
| @Test | ||
| fun listResourceRecordSetsNoTrim() = runTest { | ||
| Route53Client { | ||
| region = "us-east-1" | ||
| httpClient = TestEngine() | ||
| interceptors = mutableListOf( | ||
| AssertUrlInterceptor( | ||
| expectedUrl = "/0000-00-00/hostedzone/IDOFMYHOSTEDZONE/rrset", | ||
| ), | ||
| ) | ||
| credentialsProvider = StaticCredentialsProvider(Credentials("AKID", "SECRETAK")) | ||
| }.use { client -> | ||
| client.listResourceRecordSets { | ||
| hostedZoneId = "IDOFMYHOSTEDZONE" | ||
| } | ||
| } | ||
| } | ||
|
|
||
| /** | ||
| * Validates that HostedZoneId is trimmed | ||
| */ | ||
| @Test | ||
| fun listResourceRecordSetsTrim() = runTest { | ||
| Route53Client { | ||
| region = "us-east-1" | ||
| httpClient = TestEngine() | ||
| interceptors = mutableListOf( | ||
| AssertUrlInterceptor( | ||
| expectedUrl = "/0000-00-00/hostedzone/IDOFMYHOSTEDZONE/rrset", | ||
| ), | ||
| ) | ||
| credentialsProvider = StaticCredentialsProvider(Credentials("AKID", "SECRETAK")) | ||
| }.use { client -> | ||
| client.listResourceRecordSets { | ||
| hostedZoneId = "hostedzone/IDOFMYHOSTEDZONE" | ||
| } | ||
| } | ||
| } | ||
|
|
||
| /** | ||
| * Validates that HostedZoneId is trimmed even with a leading slash | ||
| */ | ||
| @Test | ||
| fun listResourceRecordSetsTrimLeadingSlash() = runTest { | ||
| Route53Client { | ||
| region = "us-east-1" | ||
| httpClient = TestEngine() | ||
| interceptors = mutableListOf( | ||
| AssertUrlInterceptor( | ||
| expectedUrl = "/0000-00-00/hostedzone/IDOFMYHOSTEDZONE/rrset", | ||
| ), | ||
| ) | ||
| credentialsProvider = StaticCredentialsProvider(Credentials("AKID", "SECRETAK")) | ||
| }.use { client -> | ||
| client.listResourceRecordSets { | ||
| hostedZoneId = "/hostedzone/IDOFMYHOSTEDZONE" | ||
| } | ||
| } | ||
| } | ||
|
|
||
| /** | ||
| * Validates that HostedZoneId isn't over-trimmed | ||
| */ | ||
| @Test | ||
| fun listResourceRecordSetsTrimMultiSlash() = runTest { | ||
| Route53Client { | ||
| region = "us-east-1" | ||
| httpClient = TestEngine() | ||
| interceptors = mutableListOf( | ||
| AssertUrlInterceptor( | ||
| expectedUrl = "/0000-00-00/hostedzone/IDOFMY%2FHOSTEDZONE/rrset", | ||
| ), | ||
| ) | ||
| credentialsProvider = StaticCredentialsProvider(Credentials("AKID", "SECRETAK")) | ||
| }.use { client -> | ||
| client.listResourceRecordSets { | ||
| hostedZoneId = "/hostedzone/IDOFMY/HOSTEDZONE" | ||
| } | ||
| } | ||
| } | ||
|
|
||
| /** | ||
| * This test validates that change id is correctly trimmed | ||
| */ | ||
| @Test | ||
| fun getChangeTrimChangeId() = runTest { | ||
| Route53Client { | ||
| region = "us-east-1" | ||
| httpClient = TestEngine() | ||
| interceptors = mutableListOf( | ||
| AssertUrlInterceptor( | ||
| expectedUrl = "/0000-00-00/change/SOMECHANGEID", | ||
| ), | ||
| ) | ||
| credentialsProvider = StaticCredentialsProvider(Credentials("AKID", "SECRETAK")) | ||
| }.use { client -> | ||
| client.getChange { | ||
| id = "/change/SOMECHANGEID" | ||
| } | ||
| } | ||
| } | ||
|
|
||
| /** | ||
| * This test validates that delegation set id is correctly trimmed | ||
| */ | ||
| @Test | ||
| fun getReusableDelegationSetTrimDelegationSetId() = runTest { | ||
| Route53Client { | ||
| region = "us-east-1" | ||
| httpClient = TestEngine() | ||
| interceptors = mutableListOf( | ||
| AssertUrlInterceptor( | ||
| expectedUrl = "/0000-00-00/delegationset/DELEGATIONSETID", | ||
| ), | ||
| ) | ||
| credentialsProvider = StaticCredentialsProvider(Credentials("AKID", "SECRETAK")) | ||
| }.use { client -> | ||
| client.getReusableDelegationSet { | ||
| id = "/delegationset/DELEGATIONSETID" | ||
| } | ||
| } | ||
| } | ||
|
|
||
| /** | ||
| * Model version can change the URL used as it's included in the URL. | ||
| * This interceptor removes the model version from the expected and actual URLs. | ||
| * Then performs an equality assertion between the two. | ||
| * | ||
| * https://github.com/awslabs/aws-sdk-kotlin/issues/1370 | ||
| */ | ||
| private class AssertUrlInterceptor(private val expectedUrl: String) : HttpInterceptor { | ||
| override fun readBeforeTransmit(context: ProtocolRequestInterceptorContext<Any, HttpRequest>) { | ||
| val actualUrl = context.protocolRequest.url.path.toString() | ||
|
|
||
| val parsedActualUrl = removeModelVersion(actualUrl) | ||
| val parsedExpectedUrl = removeModelVersion(expectedUrl) | ||
|
|
||
| assertEquals(parsedExpectedUrl, parsedActualUrl) | ||
| } | ||
|
|
||
| private fun removeModelVersion(url: String) = | ||
| try { | ||
| url.replaceFirst( | ||
| Regex("^/\\d{4}-\\d{2}-\\d{2}/"), | ||
| "//", | ||
| ) | ||
| } catch (e: Exception) { | ||
| fail("The URL '$url' is not in the expected format", e) | ||
| } | ||
| } | ||
| } |
This file was deleted.
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Correctness: We shouldn't hardcode this service-specific logic into the main
GradleGenerator. We should either:Sectionand a customization for Route53 which adds the necessary code in that section –or–There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I tried creating a Section and a customization for Route53 but our section logic doesn't seem to handle sections in
KotlinIntegrationsThere was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You mean hardcoding it how it is now but for every service? i.e. removing the
ifstatementThere was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
What do you mean by that? We use SectionWriter all over in our integrations: https://github.com/search?q=repo%3Aawslabs%2Faws-sdk-kotlin%20path%3A%2F%5Ecodegen%5C%2Faws-sdk-codegen%5C%2Fsrc%5C%2Fmain%5C%2Fkotlin%5C%2Faws%5C%2Fsdk%5C%2Fkotlin%5C%2Fcodegen%5C%2F%2F%20sectionWriter&type=code
Uh oh!
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Oh I meant a
SectionIdthat is declared in aKotlinIntegrationcan't be processed by aSectionWriterin anotherKotlinIntegrationUh oh!
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Oh ok. I think it should as long as the SectionId is accessible and the order is set up correctly? If not, I'd say that's a bug and we should open an issue for it
I also think just adding the
http-testdependency to all services is fineThere was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Cool, I'll try again later and open an issue for it if needed
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I found out why this isn't working for the
GradleGenerator, it's because of the way that thebuild.gradle.ktsfile is created. TheGradleGeneratoruses the fileManifest instead of useFileWriter so this step is skipped