From 20cbae844861acbd5570e6eaeeba3b5c634fae42 Mon Sep 17 00:00:00 2001 From: Luc Talatinian Date: Wed, 16 Aug 2023 16:38:20 -0400 Subject: [PATCH] restore changes from corrupted branch feat-protocol-test --- .../aws/go/codegen/AwsGoDependency.java | 2 +- .../aws/go/codegen/AwsProtocolUtils.java | 92 +------------------ internal/protocoltest/mockHttpClient.go | 26 ++++++ 3 files changed, 32 insertions(+), 88 deletions(-) create mode 100644 internal/protocoltest/mockHttpClient.go diff --git a/codegen/smithy-aws-go-codegen/src/main/java/software/amazon/smithy/aws/go/codegen/AwsGoDependency.java b/codegen/smithy-aws-go-codegen/src/main/java/software/amazon/smithy/aws/go/codegen/AwsGoDependency.java index a0b310ad380..b21e135dcce 100644 --- a/codegen/smithy-aws-go-codegen/src/main/java/software/amazon/smithy/aws/go/codegen/AwsGoDependency.java +++ b/codegen/smithy-aws-go-codegen/src/main/java/software/amazon/smithy/aws/go/codegen/AwsGoDependency.java @@ -57,7 +57,7 @@ public class AwsGoDependency { null, Versions.INTERNAL_SIGV4A, "v4a"); public static final GoDependency S3_INTERNAL_ARN = aws("service/internal/s3shared/arn", "s3arn"); public static final GoDependency AWS_ARN = aws("aws/arn", "awsarn"); - + public static final GoDependency AWS_PROTOCOL_TEST_HTTP_CLIENT = aws("internal/protocoltest", "protocoltesthttp"); public static final GoDependency REGEXP = SmithyGoDependency.stdlib("regexp"); diff --git a/codegen/smithy-aws-go-codegen/src/main/java/software/amazon/smithy/aws/go/codegen/AwsProtocolUtils.java b/codegen/smithy-aws-go-codegen/src/main/java/software/amazon/smithy/aws/go/codegen/AwsProtocolUtils.java index 2b6e3f04f48..0b94ebc976c 100644 --- a/codegen/smithy-aws-go-codegen/src/main/java/software/amazon/smithy/aws/go/codegen/AwsProtocolUtils.java +++ b/codegen/smithy-aws-go-codegen/src/main/java/software/amazon/smithy/aws/go/codegen/AwsProtocolUtils.java @@ -17,6 +17,8 @@ import java.util.Set; import java.util.TreeSet; + +import software.amazon.smithy.aws.go.codegen.customization.AwsCustomGoDependency; import software.amazon.smithy.codegen.core.Symbol; import software.amazon.smithy.go.codegen.GoWriter; import software.amazon.smithy.go.codegen.SmithyGoDependency; @@ -98,96 +100,12 @@ static void generateHttpProtocolTests(GenerationContext context) { inputConfigValues.add(HttpProtocolUnitTestGenerator.ConfigValue.builder() .name(AddAwsConfigFields.HTTP_CLIENT_CONFIG_NAME) .value(writer -> { - writer.addUseImports(AwsGoDependency.AWS_HTTP_TRANSPORT); - writer.write("awshttp.NewBuildableClient(),"); + writer.addUseImports(AwsGoDependency.AWS_PROTOCOL_TEST_HTTP_CLIENT); + writer.write("protocoltesthttp.NewClient(),"); }) .build()); - Set inputSkipTests = new TreeSet<>(SetUtils.of( - // Endpoint prefix serialization doesn't work with test runner's handling of request URLs. - // e.g. http://foo.127.0.0.1:59850/ dial fail - HttpProtocolUnitTestGenerator.SkipTest.builder() - .service(ShapeId.from("aws.protocoltests.restjson#RestJson")) - .operation(ShapeId.from("aws.protocoltests.restjson#EndpointOperation")) - .addTestName("RestJsonEndpointTrait") - .build(), - HttpProtocolUnitTestGenerator.SkipTest.builder() - .service(ShapeId.from("aws.protocoltests.restjson#RestJson")) - .operation(ShapeId.from("aws.protocoltests.restjson#EndpointWithHostLabelOperation")) - .addTestName("RestJsonEndpointTraitWithHostLabel") - .build(), - - // Endpoint prefix serialization doesn't work with test runner's handling of request URLs. - // e.g. http://foo.127.0.0.1:59850/ dial fail - HttpProtocolUnitTestGenerator.SkipTest.builder() - .service(ShapeId.from("aws.protocoltests.ec2#AwsEc2")) - .operation(ShapeId.from("aws.protocoltests.ec2#EndpointOperation")) - .addTestName("Ec2QueryEndpointTrait") - .build(), - HttpProtocolUnitTestGenerator.SkipTest.builder() - .service(ShapeId.from("aws.protocoltests.ec2#AwsEc2")) - .operation(ShapeId.from("aws.protocoltests.ec2#EndpointWithHostLabelOperation")) - .addTestName("Ec2QueryEndpointTraitWithHostLabel") - .build(), - - // Endpoint prefix serialization doesn't work with test runner's handling of request URLs. - // e.g. http://foo.127.0.0.1:59850/ dial fail - HttpProtocolUnitTestGenerator.SkipTest.builder() - .service(ShapeId.from("aws.protocoltests.json#JsonProtocol")) - .operation(ShapeId.from("aws.protocoltests.json#EndpointOperation")) - .addTestName("AwsJson11EndpointTrait") - .build(), - HttpProtocolUnitTestGenerator.SkipTest.builder() - .service(ShapeId.from("aws.protocoltests.json#JsonProtocol")) - .operation(ShapeId.from("aws.protocoltests.json#EndpointWithHostLabelOperation")) - .addTestName("AwsJson11EndpointTraitWithHostLabel") - .build(), - - // Endpoint prefix serialization doesn't work with test runner's handling of request URLs. - // e.g. http://foo.127.0.0.1:59850/ dial fail - HttpProtocolUnitTestGenerator.SkipTest.builder() - .service(ShapeId.from("aws.protocoltests.json10#JsonRpc10")) - .operation(ShapeId.from("aws.protocoltests.json10#EndpointOperation")) - .addTestName("AwsJson10EndpointTrait") - .build(), - HttpProtocolUnitTestGenerator.SkipTest.builder() - .service(ShapeId.from("aws.protocoltests.json10#JsonRpc10")) - .operation(ShapeId.from("aws.protocoltests.json10#EndpointWithHostLabelOperation")) - .addTestName("AwsJson10EndpointTraitWithHostLabel") - .build(), - - // Endpoint prefix serialization doesn't work with test runner's handling of request URLs. - // e.g. http://foo.127.0.0.1:59850/ dial fail - HttpProtocolUnitTestGenerator.SkipTest.builder() - .service(ShapeId.from("aws.protocoltests.query#AwsQuery")) - .operation(ShapeId.from("aws.protocoltests.query#EndpointOperation")) - .addTestName("AwsQueryEndpointTrait") - .build(), - HttpProtocolUnitTestGenerator.SkipTest.builder() - .service(ShapeId.from("aws.protocoltests.query#AwsQuery")) - .operation(ShapeId.from("aws.protocoltests.query#EndpointWithHostLabelOperation")) - .addTestName("AwsQueryEndpointTraitWithHostLabel") - .build(), - - // Endpoint prefix serialization doesn't work with test runner's handling of request URLs. - // e.g. http://foo.127.0.0.1:59850/ dial fail - HttpProtocolUnitTestGenerator.SkipTest.builder() - .service(ShapeId.from("aws.protocoltests.restxml#RestXml")) - .operation(ShapeId.from("aws.protocoltests.restxml#EndpointOperation")) - .addTestName("RestXmlEndpointTrait") - .build(), - HttpProtocolUnitTestGenerator.SkipTest.builder() - .service(ShapeId.from("aws.protocoltests.restxml#RestXml")) - .operation(ShapeId.from("aws.protocoltests.restxml#EndpointWithHostLabelHeaderOperation")) - .addTestName("RestXmlEndpointTraitWithHostLabelAndHttpBinding") - .build(), - HttpProtocolUnitTestGenerator.SkipTest.builder() - .service(ShapeId.from("aws.protocoltests.restxml#RestXml")) - .operation(ShapeId.from("aws.protocoltests.restxml#EndpointWithHostLabelOperation")) - .addTestName("RestXmlEndpointTraitWithHostLabel") - .build() - - )); + Set inputSkipTests = new TreeSet<>(SetUtils.of()); Set outputSkipTests = new TreeSet<>(SetUtils.of( // REST-JSON optional (SHOULD) test cases diff --git a/internal/protocoltest/mockHttpClient.go b/internal/protocoltest/mockHttpClient.go new file mode 100644 index 00000000000..ee6f2206d92 --- /dev/null +++ b/internal/protocoltest/mockHttpClient.go @@ -0,0 +1,26 @@ +package protocoltest + +import ( + "io/ioutil" + "net/http" + "strings" +) + +// HTTPClient is a mock http client used by protocol test cases to +// respond success response back +type HTTPClient struct{} + +// Do returns a mock success response to caller +func (*HTTPClient) Do(request *http.Request) (*http.Response, error) { + return &http.Response{ + StatusCode: 200, + Header: request.Header, + Body: ioutil.NopCloser(strings.NewReader("")), + Request: request, + }, nil +} + +// NewClient returns pointer of a new HTTPClient for protocol test client +func NewClient() *HTTPClient { + return &HTTPClient{} +}