Skip to content

Commit

Permalink
Merge remote-tracking branch 'tokopedia/master'
Browse files Browse the repository at this point in the history
* tokopedia/master:
  change renstrom/fuzzysearch to lithammer/fuzzysearch. (tokopedia#37)
  Support multi proto files with the same package (tokopedia#31)
  update readme
  Multi package example (tokopedia#29)
  add imports args (tokopedia#28)
  Split examples & Integration Test (tokopedia#27)
  • Loading branch information
lucamilanesio committed Feb 14, 2020
2 parents b29437b + e21a586 commit c090b92
Show file tree
Hide file tree
Showing 36 changed files with 910 additions and 709 deletions.
33 changes: 33 additions & 0 deletions .github/workflows/integration-test.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
name: Integration test
on:
pull_request:
branches:
master


jobs:
build:
name: Run example
runs-on: ubuntu-latest
steps:
- name: Checkout
uses: actions/checkout@master
- name: Run Simple Example
uses: ./
with:
entrypoint: example/simple/entrypoint.sh
args: simple
- name: Run Stream Example
uses: ./
with:
entrypoint: example/stream/entrypoint.sh
args: stream
- name: Run WKT Example
uses: ./
with:
entrypoint: example/well_known_types/entrypoint.sh
- name: Run Multi Package Example
uses: ./
with:
entrypoint: example/multi-package/entrypoint.sh

4 changes: 1 addition & 3 deletions Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ RUN go get -u -v github.com/golang/protobuf/protoc-gen-go \
google.golang.org/grpc/reflection \
golang.org/x/net/context \
github.com/go-chi/chi \
github.com/renstrom/fuzzysearch/fuzzy \
github.com/lithammer/fuzzysearch/fuzzy \
golang.org/x/tools/imports

RUN go get -u -v github.com/gobuffalo/packr/v2/... \
Expand All @@ -28,8 +28,6 @@ RUN mv /protobuf-repo/src/ /protobuf/

RUN rm -rf /protobuf-repo

RUN apk del git

RUN mkdir -p /go/src/github.com/tokopedia/gripmock

COPY . /go/src/github.com/tokopedia/gripmock
Expand Down
2 changes: 1 addition & 1 deletion Gopkg.toml
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@
version = "1.0.0"

[[constraint]]
name = "github.com/renstrom/fuzzysearch"
name = "github.com/lithammer/fuzzysearch"
version = "1.0.0"

[[constraint]]
Expand Down
18 changes: 14 additions & 4 deletions Readme.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,23 +10,25 @@ GripMock has 2 main components:

Matched stub will be returned to GRPC service then further parse it to response the rpc call.


## Quick Usage
First, prepare your `.proto` file. or you can use `hello.proto` in `example/pb/` folder. Suppose you put it in `/mypath/hello.proto`. We gonna use Docker image for easier example test.
basic syntax to run GripMock is
`gripmock <protofile>`

- Install [Docker](https://docs.docker.com/install/)
- Run `docker pull ahmadmuzakki/gripmock` to pull the image
- We gonna mount `/mypath/hello.proto` (it must a fullpath) into container and also we expose ports needed. Run `docker run -p 4770:4770 -p 4771:4771 -v /mypath:/proto ahmadmuzakki/gripmock /proto/hello.proto`
- Run `docker pull tkpd/gripmock` to pull the image
- We gonna mount `/mypath/hello.proto` (it must a fullpath) into container and also we expose ports needed. Run `docker run -p 4770:4770 -p 4771:4771 -v /mypath:/proto tkpd/gripmock /proto/hello.proto`
- On separate terminal we gonna add stub into stub service. Run `curl -X POST -d '{"service":"Greeter","method":"SayHello","input":{"equals":{"name":"gripmock"}},"output":{"data":{"message":"Hello GripMock"}}}' localhost:4771/add `
- Now we are ready to test it with our client. you can find client example file under `example/client/`. Execute one of your preferred language. Example for go: `go run example/client/go/*.go`

Check [`example`](https://github.com/tokopedia/gripmock/tree/master/example) folder for various usecase of gripmock.

## Stubbing

Stubbing is the essential mocking of GripMock. It will match and return the expected result into GRPC service. This is where you put all your request expectation and response

Stub Server running on `http://localhost:4771`
### Dynamic stubbing
You could add stubbing on the fly with simple REST. HTTP stub server running on port `:4771`

- `GET /` Will list all stubs mapping.
- `POST /add` Will add stub with provided stub data
Expand Down Expand Up @@ -68,6 +70,14 @@ For our `hello` service example we put stub with below text:
}
```

### Static stubbing
You could initialize gripmock with stub json files and provide the path using `--stub` argument. For example you may
mount your stub file in `/mystubs` folder then mount it to docker like

`docker run -p 4770:4770 -p 4771:4771 -v /mypath:/proto -v /mystubs:/stub tkpd/gripmock --stub=/stub /proto/hello.proto`

Please note that Gripmock still serve http stubbing to modify stored stubs on the fly.

## <a name="input_matching"></a>Input Matching
Stub will responding the expected response if only requested with matching rule of input. Stub service will serve `/find` endpoint with format:
```
Expand Down
2 changes: 1 addition & 1 deletion build.sh
Original file line number Diff line number Diff line change
Expand Up @@ -7,4 +7,4 @@ fi

go build ../.

docker build -t "ahmadmuzakki/gripmock:$1" .
docker build -t "tkpd/gripmock:$1" .
Loading

0 comments on commit c090b92

Please sign in to comment.