Skip to content

Commit

Permalink
Merge pull request #309 from adamryman/repeated_string_http_transport…
Browse files Browse the repository at this point in the history
…_tests

Add http transport tests for repeated query params
  • Loading branch information
zaquestion authored Aug 31, 2020
2 parents 314a6f8 + 06a348f commit 798fb2a
Show file tree
Hide file tree
Showing 4 changed files with 119 additions and 20 deletions.
14 changes: 14 additions & 0 deletions cmd/_integration-tests/transport/handlers/handlers.go
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,20 @@ func (s transportpermutationsService) GetWithRepeatedQuery(ctx context.Context,
return &response, nil
}

func (s transportpermutationsService) GetWithRepeatedStringQuery(ctx context.Context, in *pb.GetWithRepeatedStringQueryRequest) (*pb.GetWithRepeatedStringQueryResponse, error) {
var out string

for _, v := range in.A {
out = out + v
}

response := pb.GetWithRepeatedStringQueryResponse{
V: out,
}

return &response, nil
}

// GetWithEnumQuery implements Service.
func (s transportpermutationsService) GetWithEnumQuery(ctx context.Context, in *pb.GetWithEnumQueryRequest) (*pb.GetWithEnumQueryResponse, error) {
response := pb.GetWithEnumQueryResponse{
Expand Down
74 changes: 72 additions & 2 deletions cmd/_integration-tests/transport/http_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -99,17 +99,85 @@ func TestGetWithRepeatedQueryRequest(t *testing.T) {
V: A[0] + A[1],
}

err := testHTTP(t, &resp, &expects, nil, "GET", "getwithrepeatedquery?%s=[%d,%d]", "A", A[0], A[1])
var err error

err = testHTTP(t, &resp, &expects, nil, "GET", "getwithrepeatedquery?%s=[%d,%d]", "A", A[0], A[1])
if err != nil {
t.Fatal(errors.Wrap(err, "cannot make http request"))
}

// csv style
err = testHTTP(t, &resp, &expects, nil, "GET", "getwithrepeatedquery?%s=%d,%d", "A", A[0], A[1])
if err != nil {
t.Fatal(errors.Wrap(err, "cannot make http request"))
}
// multi / golang style
//err := testHTTP(nil, "GET", "getwithrepeatedquery?%s=%d&%s=%d]", "A", A[0], "A", A[1])
// err = testHTTP(t, &resp, &expects, nil, "GET", "getwithrepeatedquery?%s=%d&%s=%d", "A", A[0], "A", A[1])
// if err != nil {
// t.Fatal(errors.Wrap(err, "cannot make http request"))
// }
}

func TestGetWithRepeatedStringQueryClient(t *testing.T) {
var req pb.GetWithRepeatedStringQueryRequest
req.A = []string{"Hello", "truss"}
want := req.A[0] + req.A[1]

svchttp, err := httpclient.New(httpAddr)
if err != nil {
t.Fatalf("failed to create httpclient: %q", err)
}

resp, err := svchttp.GetWithRepeatedStringQuery(context.Background(), &req)
if err != nil {
t.Fatalf("httpclient returned error: %q", err)
}

if resp.V != want {
t.Fatalf("Expect: %s, got %s", want, resp.V)
}
}

func TestGetWithRepeatedStringQueryRequest(t *testing.T) {
resp := pb.GetWithRepeatedStringQueryResponse{}

var A []string
A = []string{"Hello", "truss"}
expects := pb.GetWithRepeatedStringQueryResponse{
V: A[0] + A[1],
}

var err error

err = testHTTP(t, &resp, &expects, nil, "GET", "getwithrepeatedstringquery?%s=[\"%s\",\"%s\"]", "A", A[0], A[1])
if err != nil {
t.Fatal(errors.Wrap(err, "cannot make http request"))
}

// csv style
err = testHTTP(t, &resp, &expects, nil, "GET", "getwithrepeatedstringquery?%s=\"%s\",\"%s\"", "A", A[0], A[1])
if err != nil {
t.Fatal(errors.Wrap(err, "cannot make http request"))
}

// default array, no quotes
// err = testHTTP(t, &resp, &expects, nil, "GET", "getwithrepeatedstringquery?%s=[%s,%s]", "A", A[0], A[1])
// if err != nil {
// t.Fatal(errors.Wrap(err, "cannot make http request"))
// }

// csv style, no quotes
// err = testHTTP(t, &resp, &expects, nil, "GET", "getwithrepeatedstringquery?%s=[%s,%s]", "A", A[0], A[1])
// if err != nil {
// t.Fatal(errors.Wrap(err, "cannot make http request"))
// }

// multi / golang style
// err = testHTTP(t, &resp, &expects, nil, "GET", "getwithrepeatedstringquery?%s=%s&%s=%s", "A", A[0], "A", A[1])
// if err != nil {
// t.Fatal(errors.Wrap(err, "cannot make http request"))
// }

}

func TestGetWithEnumQueryClient(t *testing.T) {
Expand Down Expand Up @@ -748,6 +816,8 @@ func testHTTP(
err = jsonpb.UnmarshalString(string(respBytes), v)
case *pb.GetWithRepeatedQueryResponse:
err = jsonpb.UnmarshalString(string(respBytes), v)
case *pb.GetWithRepeatedStringQueryResponse:
err = jsonpb.UnmarshalString(string(respBytes), v)
case *pb.GetWithEnumQueryResponse:
err = jsonpb.UnmarshalString(string(respBytes), v)
case *pb.PostWithNestedMessageBodyResponse:
Expand Down
13 changes: 13 additions & 0 deletions cmd/_integration-tests/transport/proto/transport-test.proto
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,11 @@ service TransportPermutations {
get: "/getwithrepeatedquery"
};
}
rpc GetWithRepeatedStringQuery (GetWithRepeatedStringQueryRequest) returns (GetWithRepeatedStringQueryResponse) {
option (google.api.http) = {
get: "/getwithrepeatedstringquery"
};
}
rpc GetWithEnumQuery (GetWithEnumQueryRequest) returns (GetWithEnumQueryResponse) {
option (google.api.http) = {
get: "/getwithenumquery"
Expand Down Expand Up @@ -126,6 +131,14 @@ message GetWithRepeatedQueryResponse {
int64 V = 1;
}

message GetWithRepeatedStringQueryRequest {
repeated string A = 1;
}

message GetWithRepeatedStringQueryResponse {
string V = 1;
}

enum TestStatus {
test_failed = 0;
test_passed = 1;
Expand Down
38 changes: 20 additions & 18 deletions cmd/_integration-tests/transport/setup_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ func TestMain(m *testing.M) {
// Endpoint domain.
getWithQueryE := svc.MakeGetWithQueryEndpoint(service)
getWithRepeatedQueryE := svc.MakeGetWithRepeatedQueryEndpoint(service)
getWithRepeatedStringQueryE := svc.MakeGetWithRepeatedStringQueryEndpoint(service)
getWithEnumQueryE := svc.MakeGetWithEnumQueryEndpoint(service)
postWithNestedMessageBodyE := svc.MakePostWithNestedMessageBodyEndpoint(service)
ctxToCtxE := svc.MakeCtxToCtxEndpoint(service)
Expand All @@ -43,24 +44,25 @@ func TestMain(m *testing.M) {
CustomVerbE := svc.MakeCustomVerbEndpoint(service)

endpoints := svc.Endpoints{
GetWithQueryEndpoint: getWithQueryE,
GetWithRepeatedQueryEndpoint: getWithRepeatedQueryE,
GetWithEnumQueryEndpoint: getWithEnumQueryE,
PostWithNestedMessageBodyEndpoint: postWithNestedMessageBodyE,
CtxToCtxEndpoint: ctxToCtxE,
GetWithCapsPathEndpoint: getWithCapsPathE,
GetWithPathParamsEndpoint: getWithPathParamsE,
GetWithEnumPathEndpoint: getWithEnumPathE,
GetWithOneofQueryEndpoint: getWithOneofQueryE,
EchoOddNamesEndpoint: echoOddNamesE,
ErrorRPCEndpoint: errorRPCE,
ErrorRPCNonJSONEndpoint: errorRPCNonJSONE,
ErrorRPCNonJSONLongEndpoint: errorRPCNonJSONLongE,
X2AOddRPCNameEndpoint: X2AOddRPCNameE,
ContentTypeTestEndpoint: contentTypeTestE,
StatusCodeAndNilHeadersEndpoint: StatusCodeAndNilHeadersE,
StatusCodeAndHeadersEndpoint: StatusCodeAndHeadersE,
CustomVerbEndpoint: CustomVerbE,
GetWithQueryEndpoint: getWithQueryE,
GetWithRepeatedQueryEndpoint: getWithRepeatedQueryE,
GetWithRepeatedStringQueryEndpoint: getWithRepeatedStringQueryE,
GetWithEnumQueryEndpoint: getWithEnumQueryE,
PostWithNestedMessageBodyEndpoint: postWithNestedMessageBodyE,
CtxToCtxEndpoint: ctxToCtxE,
GetWithCapsPathEndpoint: getWithCapsPathE,
GetWithPathParamsEndpoint: getWithPathParamsE,
GetWithEnumPathEndpoint: getWithEnumPathE,
GetWithOneofQueryEndpoint: getWithOneofQueryE,
EchoOddNamesEndpoint: echoOddNamesE,
ErrorRPCEndpoint: errorRPCE,
ErrorRPCNonJSONEndpoint: errorRPCNonJSONE,
ErrorRPCNonJSONLongEndpoint: errorRPCNonJSONLongE,
X2AOddRPCNameEndpoint: X2AOddRPCNameE,
ContentTypeTestEndpoint: contentTypeTestE,
StatusCodeAndNilHeadersEndpoint: StatusCodeAndNilHeadersE,
StatusCodeAndHeadersEndpoint: StatusCodeAndHeadersE,
CustomVerbEndpoint: CustomVerbE,
}

// http test server
Expand Down

0 comments on commit 798fb2a

Please sign in to comment.