Skip to content

Commit 608e606

Browse files
chore: support programmatically generating and skipping protocol tests (#2506)
* chore: ensure protocol tests are still generated * chore: skip query error test * chore: update smithy gradle plugin * chore: regenerate protocol tests
1 parent 8b05bdd commit 608e606

File tree

10 files changed

+49
-4
lines changed

10 files changed

+49
-4
lines changed

Diff for: codegen/protocol-test-codegen/build.gradle.kts

+1-1
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@
1616
import software.amazon.smithy.gradle.tasks.SmithyBuild
1717

1818
plugins {
19-
id("software.amazon.smithy") version "0.5.2"
19+
id("software.amazon.smithy") version "0.5.3"
2020
}
2121

2222
dependencies {

Diff for: codegen/sdk-codegen/build.gradle.kts

+1-1
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ import software.amazon.smithy.model.node.Node
1717
import software.amazon.smithy.gradle.tasks.SmithyBuild
1818

1919
plugins {
20-
id("software.amazon.smithy") version "0.5.2"
20+
id("software.amazon.smithy") version "0.5.3"
2121
}
2222

2323
dependencies {

Diff for: codegen/smithy-aws-typescript-codegen/build.gradle.kts

+1
Original file line numberDiff line numberDiff line change
@@ -22,5 +22,6 @@ dependencies {
2222
api("software.amazon.smithy:smithy-aws-traits:[1.8.0, 1.9.0[")
2323
api("software.amazon.smithy:smithy-waiters:[1.8.0, 1.9.0[")
2424
api("software.amazon.smithy:smithy-aws-iam-traits:[1.8.0, 1.9.0[")
25+
api("software.amazon.smithy:smithy-protocol-test-traits:[1.8.0, 1.9.0[")
2526
api("software.amazon.smithy.typescript:smithy-typescript-codegen:0.3.0")
2627
}

Diff for: codegen/smithy-aws-typescript-codegen/src/main/java/software/amazon/smithy/aws/typescript/codegen/AwsEc2.java

+5
Original file line numberDiff line numberDiff line change
@@ -167,4 +167,9 @@ protected void deserializeOutputDocument(
167167
writer.write("contents = $L;",
168168
outputStructure.accept(new XmlMemberDeserVisitor(context, "data", Format.DATE_TIME)));
169169
}
170+
171+
@Override
172+
public void generateProtocolTests(GenerationContext context) {
173+
AwsProtocolUtils.generateProtocolTests(this, context);
174+
}
170175
}

Diff for: codegen/smithy-aws-typescript-codegen/src/main/java/software/amazon/smithy/aws/typescript/codegen/AwsProtocolUtils.java

+21
Original file line numberDiff line numberDiff line change
@@ -33,8 +33,12 @@
3333
import software.amazon.smithy.model.traits.TimestampFormatTrait;
3434
import software.amazon.smithy.model.traits.TimestampFormatTrait.Format;
3535
import software.amazon.smithy.model.traits.XmlNamespaceTrait;
36+
import software.amazon.smithy.protocoltests.traits.HttpMessageTestCase;
37+
import software.amazon.smithy.typescript.codegen.HttpProtocolTestGenerator;
38+
import software.amazon.smithy.typescript.codegen.TypeScriptSettings;
3639
import software.amazon.smithy.typescript.codegen.TypeScriptWriter;
3740
import software.amazon.smithy.typescript.codegen.integration.HttpProtocolGeneratorUtils;
41+
import software.amazon.smithy.typescript.codegen.integration.ProtocolGenerator;
3842
import software.amazon.smithy.typescript.codegen.integration.ProtocolGenerator.GenerationContext;
3943
import software.amazon.smithy.utils.SmithyInternalApi;
4044

@@ -274,4 +278,21 @@ static String getInputTimestampValueProvider(
274278
TimestampFormatTrait.Format format = httpIndex.determineTimestampFormat(memberShape, DOCUMENT, defaultFormat);
275279
return HttpProtocolGeneratorUtils.getTimestampInputParam(context, inputLocation, memberShape, format);
276280
}
281+
282+
static void generateProtocolTests(ProtocolGenerator generator, GenerationContext context) {
283+
new HttpProtocolTestGenerator(context, generator, AwsProtocolUtils::filterProtocolTests).run();
284+
}
285+
286+
private static boolean filterProtocolTests(
287+
ServiceShape service,
288+
OperationShape operation,
289+
HttpMessageTestCase testCase,
290+
TypeScriptSettings settings
291+
) {
292+
// TODO: Consume AWSQueryError trait as a follow-up.
293+
if (testCase.getId().equals("QueryCustomizedError")) {
294+
return true;
295+
}
296+
return false;
297+
}
277298
}

Diff for: codegen/smithy-aws-typescript-codegen/src/main/java/software/amazon/smithy/aws/typescript/codegen/AwsQuery.java

+5
Original file line numberDiff line numberDiff line change
@@ -168,4 +168,9 @@ protected void deserializeOutputDocument(
168168
writer.write("contents = $L;",
169169
outputStructure.accept(new XmlMemberDeserVisitor(context, dataSource, Format.DATE_TIME)));
170170
}
171+
172+
@Override
173+
public void generateProtocolTests(GenerationContext context) {
174+
AwsProtocolUtils.generateProtocolTests(this, context);
175+
}
171176
}

Diff for: codegen/smithy-aws-typescript-codegen/src/main/java/software/amazon/smithy/aws/typescript/codegen/AwsRestXml.java

+5
Original file line numberDiff line numberDiff line change
@@ -350,4 +350,9 @@ private void deserializeDocumentBody(
350350
});
351351
}
352352
}
353+
354+
@Override
355+
public void generateProtocolTests(GenerationContext context) {
356+
AwsProtocolUtils.generateProtocolTests(this, context);
357+
}
353358
}

Diff for: codegen/smithy-aws-typescript-codegen/src/main/java/software/amazon/smithy/aws/typescript/codegen/JsonRpcProtocolGenerator.java

+5
Original file line numberDiff line numberDiff line change
@@ -141,4 +141,9 @@ protected void deserializeOutputDocument(
141141
private DocumentMemberDeserVisitor getMemberDeserVisitor(GenerationContext context, String dataSource) {
142142
return new JsonMemberDeserVisitor(context, dataSource, getDocumentTimestampFormat());
143143
}
144+
145+
@Override
146+
public void generateProtocolTests(GenerationContext context) {
147+
AwsProtocolUtils.generateProtocolTests(this, context);
148+
}
144149
}

Diff for: codegen/smithy-aws-typescript-codegen/src/main/java/software/amazon/smithy/aws/typescript/codegen/RestJsonProtocolGenerator.java

+5
Original file line numberDiff line numberDiff line change
@@ -341,4 +341,9 @@ protected void readPayload(
341341
private DocumentMemberDeserVisitor getMemberDeserVisitor(GenerationContext context, String dataSource) {
342342
return new JsonMemberDeserVisitor(context, dataSource, getDocumentTimestampFormat());
343343
}
344+
345+
@Override
346+
public void generateProtocolTests(GenerationContext context) {
347+
AwsProtocolUtils.generateProtocolTests(this, context);
348+
}
344349
}

Diff for: protocol_tests/aws-query/tests/functional/awsquery.spec.ts

-2
Original file line numberDiff line numberDiff line change
@@ -548,8 +548,6 @@ it("QueryInvalidGreetingError:Error:GreetingWithErrors", async () => {
548548
/**
549549
* Parses customized XML errors
550550
*/
551-
// Manually skipping to unblock smithy-1.8.x update.
552-
// TODO: Consume AWSQueryError trait as a follow-up.
553551
it.skip("QueryCustomizedError:Error:GreetingWithErrors", async () => {
554552
const client = new QueryProtocolClient({
555553
...clientParams,

0 commit comments

Comments
 (0)