Skip to content

Commit e64a7d0

Browse files
lucix-awsMadrigal
andauthored
migrate protocol test codegen to smithy-go (#3335)
* migrate protocol test codegen to smithy-go * add endpoint resolution to kitchen sink * update codegen --------- Co-authored-by: Luis Madrigal <599908+Madrigal@users.noreply.github.com>
1 parent d5b9ac6 commit e64a7d0

File tree

1,560 files changed

+5000
-6862
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

1,560 files changed

+5000
-6862
lines changed

SMITHY_GO_CODEGEN_VERSION

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,2 +1 @@
1-
a27260fac103bb3e98839df5d562bc36596e3c0d
2-
1+
a46ced700b2b64c1db83ace21668b666dd901980

codegen/smithy-aws-go-codegen/src/main/java/software/amazon/smithy/aws/go/codegen/AwsEndpointResolverInitializerGenerator.java

Lines changed: 0 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -22,13 +22,11 @@
2222
import software.amazon.smithy.codegen.core.SymbolProvider;
2323
import software.amazon.smithy.go.codegen.GoSettings;
2424
import software.amazon.smithy.go.codegen.GoWriter;
25-
import software.amazon.smithy.go.codegen.ChainWritable;
2625
import software.amazon.smithy.go.codegen.Writable;
2726
import software.amazon.smithy.go.codegen.SmithyGoDependency;
2827
import software.amazon.smithy.go.codegen.SymbolUtils;
2928
import software.amazon.smithy.go.codegen.TriConsumer;
3029
import software.amazon.smithy.go.codegen.endpoints.EndpointResolutionGenerator;
31-
import software.amazon.smithy.go.codegen.integration.ConfigField;
3230
import software.amazon.smithy.go.codegen.integration.ConfigFieldResolver;
3331
import software.amazon.smithy.go.codegen.integration.GoIntegration;
3432
import software.amazon.smithy.go.codegen.integration.RuntimeClientPlugin;
@@ -48,18 +46,6 @@ public class AwsEndpointResolverInitializerGenerator implements GoIntegration {
4846

4947
private Map<String, Object> commonCodegenArgs;
5048

51-
52-
private static final ConfigField EndpointResolverV2 = ConfigField.builder()
53-
.name(EndpointResolutionGenerator.RESOLVER_INTERFACE_NAME)
54-
.type(buildPackageSymbol(EndpointResolutionGenerator.RESOLVER_INTERFACE_NAME))
55-
.documentation(String.format("""
56-
Resolves the endpoint used for a particular service operation.
57-
This should be used over the deprecated %s.
58-
""", EndpointGenerator.RESOLVER_INTERFACE_NAME)
59-
)
60-
.withHelper(true)
61-
.build();
62-
6349
private static final ConfigFieldResolver ResolveEndpointResolverV2 = ConfigFieldResolver.builder()
6450
.resolver(buildPackageSymbol(RESOLVE_ENDPOINT_RESOLVER_V2))
6551
.location(ConfigFieldResolver.Location.CLIENT)
@@ -150,7 +136,6 @@ private Writable generateResolveMethod() {
150136
public List<RuntimeClientPlugin> getClientPlugins() {
151137
return ListUtils.of(
152138
RuntimeClientPlugin.builder()
153-
.addConfigField(EndpointResolverV2)
154139
.addConfigFieldResolver(ResolveEndpointResolverV2)
155140
.build()
156141
);

codegen/smithy-aws-go-codegen/src/main/java/software/amazon/smithy/aws/go/codegen/AwsProtocolUtils.java

Lines changed: 0 additions & 224 deletions
Original file line numberDiff line numberDiff line change
@@ -15,25 +15,10 @@
1515

1616
package software.amazon.smithy.aws.go.codegen;
1717

18-
import java.util.Set;
19-
import java.util.TreeSet;
20-
21-
import software.amazon.smithy.aws.go.codegen.customization.AwsCustomGoDependency;
22-
import software.amazon.smithy.codegen.core.Symbol;
2318
import software.amazon.smithy.go.codegen.GoWriter;
2419
import software.amazon.smithy.go.codegen.SmithyGoDependency;
2520
import software.amazon.smithy.go.codegen.SymbolUtils;
26-
import software.amazon.smithy.go.codegen.integration.HttpProtocolTestGenerator;
27-
import software.amazon.smithy.go.codegen.integration.HttpProtocolUnitTestGenerator;
28-
import software.amazon.smithy.go.codegen.integration.HttpProtocolUnitTestGenerator.ConfigValue;
29-
import software.amazon.smithy.go.codegen.integration.HttpProtocolUnitTestRequestGenerator;
30-
import software.amazon.smithy.go.codegen.integration.HttpProtocolUnitTestResponseErrorGenerator;
31-
import software.amazon.smithy.go.codegen.integration.HttpProtocolUnitTestResponseGenerator;
32-
import software.amazon.smithy.go.codegen.integration.IdempotencyTokenMiddlewareGenerator;
3321
import software.amazon.smithy.go.codegen.integration.ProtocolGenerator.GenerationContext;
34-
import software.amazon.smithy.model.shapes.Shape;
35-
import software.amazon.smithy.model.shapes.ShapeId;
36-
import software.amazon.smithy.utils.SetUtils;
3722

3823
/**
3924
* Utility methods for generating AWS protocols.
@@ -42,215 +27,6 @@ public final class AwsProtocolUtils {
4227
private AwsProtocolUtils() {
4328
}
4429

45-
/**
46-
* Generates HTTP protocol tests with all required AWS-specific configuration set.
47-
*
48-
* @param context The generation context.
49-
*/
50-
public static void generateHttpProtocolTests(GenerationContext context) {
51-
Set<HttpProtocolUnitTestGenerator.ConfigValue> configValues = new TreeSet<>(SetUtils.of(
52-
HttpProtocolUnitTestGenerator.ConfigValue.builder()
53-
.name(AddAwsConfigFields.REGION_CONFIG_NAME)
54-
.value(writer -> writer.write("$S,", "us-west-2"))
55-
.build(),
56-
HttpProtocolUnitTestGenerator.ConfigValue.builder()
57-
.name(AddAwsConfigFields.ENDPOINT_RESOLVER_CONFIG_NAME)
58-
.value(writer -> {
59-
writer.addUseImports(AwsGoDependency.AWS_CORE);
60-
writer.openBlock("$L(func(region string, options $L) (e aws.Endpoint, err error) {", "}),",
61-
EndpointGenerator.RESOLVER_FUNC_NAME, EndpointGenerator.RESOLVER_OPTIONS, () -> {
62-
writer.write("e.URL = serverURL");
63-
writer.write("e.SigningRegion = \"us-west-2\"");
64-
writer.write("return e, err");
65-
});
66-
})
67-
.build(),
68-
HttpProtocolUnitTestGenerator.ConfigValue.builder()
69-
.name("APIOptions")
70-
.value(writer -> {
71-
Symbol stackSymbol = SymbolUtils.createPointableSymbolBuilder("Stack",
72-
SmithyGoDependency.SMITHY_MIDDLEWARE).build();
73-
writer.openBlock("[]func($P) error{", "},", stackSymbol, () -> {
74-
writer.openBlock("func(s $P) error {", "},", stackSymbol, () -> {
75-
writer.write("s.Finalize.Clear()");
76-
writer.write("s.Initialize.Remove(`OperationInputValidation`)");
77-
writer.write("return nil");
78-
});
79-
});
80-
})
81-
.build()
82-
));
83-
84-
// TODO can this check be replaced with a lookup into the runtime plugins?
85-
if (IdempotencyTokenMiddlewareGenerator.hasOperationsWithIdempotencyToken(context.getModel(),
86-
context.getService())) {
87-
configValues.add(
88-
HttpProtocolUnitTestGenerator.ConfigValue.builder()
89-
.name(IdempotencyTokenMiddlewareGenerator.IDEMPOTENCY_CONFIG_NAME)
90-
.value(writer -> {
91-
writer.addUseImports(SmithyGoDependency.SMITHY_RAND);
92-
writer.addUseImports(SmithyGoDependency.SMITHY_TESTING);
93-
writer.write("smithyrand.NewUUIDIdempotencyToken(&smithytesting.ByteLoop{}),");
94-
})
95-
.build()
96-
);
97-
}
98-
99-
Set<ConfigValue> inputConfigValues = new TreeSet<>(configValues);
100-
inputConfigValues.add(HttpProtocolUnitTestGenerator.ConfigValue.builder()
101-
.name(AddAwsConfigFields.HTTP_CLIENT_CONFIG_NAME)
102-
.value(writer -> {
103-
writer.addUseImports(AwsGoDependency.AWS_PROTOCOL_TEST_HTTP_CLIENT);
104-
writer.write("protocoltesthttp.NewClient(),");
105-
})
106-
.build());
107-
108-
// skip request compression tests, not yet implemented in the SDK
109-
Set<HttpProtocolUnitTestGenerator.SkipTest> inputSkipTests = new TreeSet<>(SetUtils.of(
110-
// CBOR default value serialization (SHOULD)
111-
HttpProtocolUnitTestGenerator.SkipTest.builder()
112-
.service(ShapeId.from("smithy.protocoltests.rpcv2Cbor#RpcV2Protocol"))
113-
.operation(ShapeId.from("smithy.protocoltests.rpcv2Cbor#OperationWithDefaults"))
114-
.addTestName("RpcV2CborClientPopulatesDefaultValuesInInput")
115-
.addTestName("RpcV2CborClientSkipsTopLevelDefaultValuesInInput")
116-
.addTestName("RpcV2CborClientUsesExplicitlyProvidedMemberValuesOverDefaults")
117-
.addTestName("RpcV2CborClientUsesExplicitlyProvidedValuesInTopLevel")
118-
.addTestName("RpcV2CborClientIgnoresNonTopLevelDefaultsOnMembersWithClientOptional")
119-
.build(),
120-
121-
HttpProtocolUnitTestGenerator.SkipTest.builder()
122-
.service(ShapeId.from("aws.protocoltests.restxml#RestXml"))
123-
.operation(ShapeId.from("aws.protocoltests.restxml#HttpPayloadWithUnion"))
124-
.addTestName("RestXmlHttpPayloadWithUnion")
125-
.addTestName("RestXmlHttpPayloadWithUnsetUnion")
126-
.build(),
127-
128-
// REST-JSON default value serialization
129-
HttpProtocolUnitTestGenerator.SkipTest.builder()
130-
.service(ShapeId.from("aws.protocoltests.restjson#RestJson"))
131-
.operation(ShapeId.from("aws.protocoltests.restjson#OperationWithDefaults"))
132-
.addTestName("RestJsonClientPopulatesDefaultValuesInInput")
133-
.addTestName("RestJsonClientUsesExplicitlyProvidedValuesInTopLevel")
134-
.build(),
135-
HttpProtocolUnitTestGenerator.SkipTest.builder()
136-
.service(ShapeId.from("aws.protocoltests.restjson#RestJson"))
137-
.operation(ShapeId.from("aws.protocoltests.restjson#OperationWithNestedStructure"))
138-
.addTestName("RestJsonClientPopulatesNestedDefaultValuesWhenMissing")
139-
.build(),
140-
141-
HttpProtocolUnitTestGenerator.SkipTest.builder()
142-
.service(ShapeId.from("aws.protocoltests.json10#JsonRpc10"))
143-
.operation(ShapeId.from("aws.protocoltests.json10#OperationWithDefaults"))
144-
.addTestName("AwsJson10ClientPopulatesDefaultValuesInInput")
145-
.addTestName("AwsJson10ClientSkipsTopLevelDefaultValuesInInput")
146-
.addTestName("AwsJson10ClientUsesExplicitlyProvidedMemberValuesOverDefaults")
147-
.addTestName("AwsJson10ClientUsesExplicitlyProvidedValuesInTopLevel")
148-
.build(),
149-
HttpProtocolUnitTestGenerator.SkipTest.builder()
150-
.service(ShapeId.from("aws.protocoltests.json10#JsonRpc10"))
151-
.operation(ShapeId.from("aws.protocoltests.json10#OperationWithNestedStructure"))
152-
.addTestName("AwsJson10ClientPopulatesNestedDefaultValuesWhenMissing")
153-
.build()
154-
));
155-
156-
Set<HttpProtocolUnitTestGenerator.SkipTest> outputSkipTests = new TreeSet<>(SetUtils.of(
157-
// CBOR default value deserialization (SHOULD)
158-
HttpProtocolUnitTestGenerator.SkipTest.builder()
159-
.service(ShapeId.from("smithy.protocoltests.rpcv2Cbor#RpcV2Protocol"))
160-
.operation(ShapeId.from("smithy.protocoltests.rpcv2Cbor#OperationWithDefaults"))
161-
.addTestName("RpcV2CborClientPopulatesDefaultsValuesWhenMissingInResponse")
162-
.addTestName("RpcV2CborClientIgnoresDefaultValuesIfMemberValuesArePresentInResponse")
163-
.build(),
164-
HttpProtocolUnitTestGenerator.SkipTest.builder()
165-
.service(ShapeId.from("smithy.protocoltests.rpcv2Cbor#RpcV2Protocol"))
166-
.operation(ShapeId.from("smithy.protocoltests.rpcv2Cbor#RpcV2CborDenseMaps"))
167-
.addTestName("RpcV2CborDeserializesDenseSetMapAndSkipsNull")
168-
.build(),
169-
170-
// REST-JSON optional (SHOULD) test cases
171-
HttpProtocolUnitTestGenerator.SkipTest.builder()
172-
.service(ShapeId.from("aws.protocoltests.restjson#RestJson"))
173-
.operation(ShapeId.from("aws.protocoltests.restjson#JsonMaps"))
174-
.addTestName("RestJsonDeserializesDenseSetMapAndSkipsNull")
175-
.build(),
176-
177-
// REST-JSON default value deserialization
178-
HttpProtocolUnitTestGenerator.SkipTest.builder()
179-
.service(ShapeId.from("aws.protocoltests.restjson#RestJson"))
180-
.operation(ShapeId.from("aws.protocoltests.restjson#OperationWithDefaults"))
181-
.addTestName("RestJsonClientPopulatesDefaultsValuesWhenMissingInResponse")
182-
.build(),
183-
HttpProtocolUnitTestGenerator.SkipTest.builder()
184-
.service(ShapeId.from("aws.protocoltests.restjson#RestJson"))
185-
.operation(ShapeId.from("aws.protocoltests.restjson#OperationWithNestedStructure"))
186-
.addTestName("RestJsonClientPopulatesNestedDefaultsWhenMissingInResponseBody")
187-
.build(),
188-
189-
// REST-XML opinionated test - prefix headers as empty vs nil map
190-
HttpProtocolUnitTestGenerator.SkipTest.builder()
191-
.service(ShapeId.from("aws.protocoltests.restxml#RestXml"))
192-
.operation(ShapeId.from("aws.protocoltests.restxml#HttpPrefixHeaders"))
193-
.addTestName("HttpPrefixHeadersAreNotPresent")
194-
.build(),
195-
196-
HttpProtocolUnitTestGenerator.SkipTest.builder()
197-
.service(ShapeId.from("aws.protocoltests.restjson#RestJson"))
198-
.operation(ShapeId.from("aws.protocoltests.restjson#JsonUnions"))
199-
.addTestName("RestJsonDeserializeIgnoreType")
200-
.build(),
201-
HttpProtocolUnitTestGenerator.SkipTest.builder()
202-
.service(ShapeId.from("aws.protocoltests.json10#JsonRpc10"))
203-
.operation(ShapeId.from("aws.protocoltests.json10#JsonUnions"))
204-
.addTestName("AwsJson10DeserializeIgnoreType")
205-
.build(),
206-
HttpProtocolUnitTestGenerator.SkipTest.builder()
207-
.service(ShapeId.from("aws.protocoltests.json#JsonProtocol"))
208-
.operation(ShapeId.from("aws.protocoltests.json#JsonUnions"))
209-
.addTestName("AwsJson11DeserializeIgnoreType")
210-
.build(),
211-
212-
HttpProtocolUnitTestGenerator.SkipTest.builder()
213-
.service(ShapeId.from("aws.protocoltests.json10#JsonRpc10"))
214-
.operation(ShapeId.from("aws.protocoltests.json10#OperationWithDefaults"))
215-
.addTestName("AwsJson10ClientPopulatesDefaultsValuesWhenMissingInResponse")
216-
.addTestName("AwsJson10ClientIgnoresDefaultValuesIfMemberValuesArePresentInResponse")
217-
.build(),
218-
// We don't populate default values if none are sent by the server
219-
HttpProtocolUnitTestGenerator.SkipTest.builder()
220-
.service(ShapeId.from("aws.protocoltests.json10#JsonRpc10"))
221-
.operation(ShapeId.from("aws.protocoltests.json10#OperationWithNestedStructure"))
222-
.addTestName("AwsJson10ClientPopulatesNestedDefaultsWhenMissingInResponseBody")
223-
.build(),
224-
HttpProtocolUnitTestGenerator.SkipTest.builder()
225-
.service(ShapeId.from("aws.protocoltests.json10#JsonRpc10"))
226-
.operation(ShapeId.from("aws.protocoltests.json10#OperationWithRequiredMembers"))
227-
.addTestName("AwsJson10ClientErrorCorrectsWhenServerFailsToSerializeRequiredValues")
228-
.build(),
229-
HttpProtocolUnitTestGenerator.SkipTest.builder()
230-
.service(ShapeId.from("aws.protocoltests.json10#JsonRpc10"))
231-
.operation(ShapeId.from("aws.protocoltests.json10#OperationWithRequiredMembersWithDefaults"))
232-
.addTestName("AwsJson10ClientErrorCorrectsWithDefaultValuesWhenServerFailsToSerializeRequiredValues")
233-
.build()
234-
));
235-
236-
new HttpProtocolTestGenerator(context,
237-
(HttpProtocolUnitTestRequestGenerator.Builder) new HttpProtocolUnitTestRequestGenerator
238-
.Builder()
239-
.settings(context.getSettings())
240-
.addSkipTests(inputSkipTests)
241-
.addClientConfigValues(inputConfigValues),
242-
(HttpProtocolUnitTestResponseGenerator.Builder) new HttpProtocolUnitTestResponseGenerator
243-
.Builder()
244-
.settings(context.getSettings())
245-
.addSkipTests(outputSkipTests)
246-
.addClientConfigValues(configValues),
247-
(HttpProtocolUnitTestResponseErrorGenerator.Builder) new HttpProtocolUnitTestResponseErrorGenerator
248-
.Builder()
249-
.settings(context.getSettings())
250-
.addClientConfigValues(configValues)
251-
).generateProtocolTests();
252-
}
253-
25430
public static void initializeJsonDecoder(GoWriter writer, String bodyLocation) {
25531
// Use a ring buffer and tee reader to help in pinpointing any deserialization errors.
25632
writer.addUseImports(SmithyGoDependency.SMITHY_IO);

codegen/smithy-aws-go-codegen/src/main/java/software/amazon/smithy/aws/go/codegen/AwsQuery.java

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -156,11 +156,6 @@ protected void writeErrorMessageCodeDeserializer(GenerationContext context) {
156156
XmlProtocolUtils.writeXmlErrorMessageCodeDeserializer(context);
157157
}
158158

159-
@Override
160-
public void generateProtocolTests(GenerationContext context) {
161-
AwsProtocolUtils.generateHttpProtocolTests(context);
162-
}
163-
164159
@Override
165160
public Map<String, ShapeId> getOperationErrors(GenerationContext context, OperationShape operation) {
166161
Map<String, ShapeId> errors = new TreeMap<>();

codegen/smithy-aws-go-codegen/src/main/java/software/amazon/smithy/aws/go/codegen/JsonRpcProtocolGenerator.java

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -170,11 +170,6 @@ protected void deserializeError(GenerationContext context, StructureShape shape)
170170
writer.write("return output");
171171
}
172172

173-
@Override
174-
public void generateProtocolTests(GenerationContext context) {
175-
AwsProtocolUtils.generateHttpProtocolTests(context);
176-
}
177-
178173
@Override
179174
protected void writeErrorMessageCodeDeserializer(GenerationContext context) {
180175
var tmpl = goTemplate("""

codegen/smithy-aws-go-codegen/src/main/java/software/amazon/smithy/aws/go/codegen/RestJsonProtocolGenerator.java

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -513,11 +513,6 @@ public void generateSharedDeserializerComponents(GenerationContext context) {
513513
super.generateSharedDeserializerComponents(context);
514514
}
515515

516-
@Override
517-
public void generateProtocolTests(GenerationContext context) {
518-
AwsProtocolUtils.generateHttpProtocolTests(context);
519-
}
520-
521516
@Override
522517
public void generateProtocolDocumentMarshalerUnmarshalDocument(GenerationContext context) {
523518
JsonProtocolDocumentUtils.generateProtocolDocumentMarshalerUnmarshalDocument(context);

codegen/smithy-aws-go-codegen/src/main/java/software/amazon/smithy/aws/go/codegen/RestXmlProtocolGenerator.java

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -62,11 +62,6 @@ abstract class RestXmlProtocolGenerator extends HttpBindingProtocolGenerator {
6262
super(true);
6363
}
6464

65-
@Override
66-
public void generateProtocolTests(GenerationContext context) {
67-
AwsProtocolUtils.generateHttpProtocolTests(context);
68-
}
69-
7065
@Override
7166
protected TimestampFormatTrait.Format getDocumentTimestampFormat() {
7267
return TimestampFormatTrait.Format.DATE_TIME;

codegen/smithy-aws-go-codegen/src/main/java/software/amazon/smithy/aws/go/codegen/protocol/AwsRpc2CborProtocolGenerator.java

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -32,11 +32,6 @@
3232
* a 2000+ line dumpster fire in this repo.
3333
*/
3434
public final class AwsRpc2CborProtocolGenerator extends Rpc2CborProtocolGenerator {
35-
@Override
36-
public void generateProtocolTests(GenerationContext context) {
37-
AwsProtocolUtils.generateHttpProtocolTests(context);
38-
}
39-
4035
@Override
4136
public void generateEventStreamComponents(GenerationContext context) {
4237
// This automagically wires up ALL the framing logic for both directions of streams. All we have to do is fill

internal/kitchensinktest/credential_refresh_retry_test.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,7 @@ func TestCredentialRefreshRetry(t *testing.T) {
3434
Credentials: &mockCredentials{
3535
credentials: credvalues,
3636
},
37+
EndpointResolverV2: &endpointResolver{},
3738
})
3839

3940
_, err := svc.GetItem(context.Background(), nil)

0 commit comments

Comments
 (0)