Skip to content

Commit

Permalink
Add intergration tests for HTTP Patch
Browse files Browse the repository at this point in the history
  • Loading branch information
atreya2011 committed Apr 12, 2021
1 parent fc0e67a commit fdc3168
Show file tree
Hide file tree
Showing 4 changed files with 42 additions and 14 deletions.
12 changes: 8 additions & 4 deletions integration_tests/integration_test.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,7 @@
import {CounterService} from "./service.pb";
import _ from './empty.pb';
import { expect } from 'chai';
import camelCase from 'lodash.camelcase';
import { pathOr } from 'ramda'
import {expect} from 'chai'
import { pathOr } from 'ramda';
import { CounterService } from "./service.pb";

function getFieldName(name: string) {
const useCamelCase = pathOr(false, ['__karma__', 'config', 'useProtoNames'], window) === false
Expand Down Expand Up @@ -48,5 +47,10 @@ describe("test grpc-gateway-ts communication", () => {
expect(getField(result, 'result')).to.equal("hello!!")
})

it('http patch request with star in path', async () => {
const result = await CounterService.HTTPPatch({a: 10, c: 23}, {pathPrefix: "http://localhost:8081"})
expect(getField(result, 'patch_result')).to.equal(33)
})


})
7 changes: 4 additions & 3 deletions integration_tests/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,12 @@ package main
import (
"context"
"flag"
"github.com/grpc-ecosystem/grpc-gateway/runtime"
"google.golang.org/grpc"
"net"
"net/http"
"strings"

"github.com/grpc-ecosystem/grpc-gateway/runtime"
"google.golang.org/grpc"
)

// preflightHandler adds the necessary headers in order to serve
Expand All @@ -16,7 +17,7 @@ import (
func preflightHandler(w http.ResponseWriter, r *http.Request) {
headers := []string{"Content-Type", "Accept", "Authorization"}
w.Header().Set("Access-Control-Allow-Headers", strings.Join(headers, ","))
methods := []string{"GET", "HEAD", "POST", "PUT", "DELETE"}
methods := []string{"GET", "HEAD", "POST", "PUT", "PATCH", "DELETE"}
w.Header().Set("Access-Control-Allow-Methods", strings.Join(methods, ","))
}

Expand Down
6 changes: 6 additions & 0 deletions integration_tests/service.go
Original file line number Diff line number Diff line change
Expand Up @@ -55,3 +55,9 @@ func (r *RealCounterService) HTTPPostWithStarBodyPath(ctx context.Context, in *H
PostResult: in.A + in.Req.B + in.C,
}, nil
}

func (r *RealCounterService) HTTPPatch(ctx context.Context, in *HttpPatchRequest) (*HttpPatchResponse, error) {
return &HttpPatchResponse{
Patch: in.A + in.C,
}, nil
}
31 changes: 24 additions & 7 deletions integration_tests/service.proto
Original file line number Diff line number Diff line change
Expand Up @@ -43,23 +43,40 @@ message HttpPostResponse {
int32 post_result = 1;
}

message HttpPatchRequest {
int32 a = 1;
int32 c = 2;
}

message HttpPatchResponse {
int32 patch_result = 2;
}

service CounterService {
rpc Increment (UnaryRequest) returns (UnaryResponse);
rpc StreamingIncrements (StreamingRequest) returns (stream StreamingResponse);
rpc HTTPGet (HttpGetRequest) returns(HttpGetResponse) {
option (google.api.http) = { get: "/api/{num_to_increase}" };
rpc Increment(UnaryRequest) returns (UnaryResponse);
rpc StreamingIncrements(StreamingRequest) returns (stream StreamingResponse);
rpc HTTPGet(HttpGetRequest) returns (HttpGetResponse) {
option (google.api.http) = {
get: "/api/{num_to_increase}"
};
}
rpc HTTPPostWithNestedBodyPath (HttpPostRequest) returns(HttpPostResponse) {
rpc HTTPPostWithNestedBodyPath(HttpPostRequest) returns (HttpPostResponse) {
option (google.api.http) = {
post: "/post/{a}"
body: "req"
};
}
rpc HTTPPostWithStarBodyPath (HttpPostRequest) returns(HttpPostResponse) {
rpc HTTPPostWithStarBodyPath(HttpPostRequest) returns (HttpPostResponse) {
option (google.api.http) = {
post: "/post/{a}/{c}"
body: "*"
};
}
rpc ExternalMessage (ExternalRequest) returns (ExternalResponse);
rpc HTTPPatch(HttpPatchRequest) returns (HttpPatchResponse) {
option (google.api.http) = {
patch: "/patch"
body: "*"
};
}
rpc ExternalMessage(ExternalRequest) returns (ExternalResponse);
}

0 comments on commit fdc3168

Please sign in to comment.