Skip to content

Commit d8d6b95

Browse files
author
jackie muzakki
committed
docs(readme): update contribution guidelines and add stub server features
1 parent aa7b1cf commit d8d6b95

1 file changed

Lines changed: 31 additions & 27 deletions

File tree

Readme.md

Lines changed: 31 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -1,60 +1,62 @@
11
# GripMock
2-
GripMock is a **mock server** for **GRPC** services. It's using a `.proto` file to generate implementation of gRPC service for you.
2+
GripMock is a **mock server** for **gRPC** services. It uses a `.proto` file to generate implementation of gRPC service for you.
33
You can use gripmock for setting up end-to-end testing or as a dummy server in a software development phase.
4-
The server implementation is in GoLang but the client can be any programming language that support gRPC.
4+
The server implementation is in GoLang but the client can be in any programming language that supports gRPC.
55

66
---
77

8-
### Announcement:
9-
The latest [version (v1.10)](https://github.com/tokopedia/gripmock/releases/tag/v1.10) of gripmock is requiring `go_package` declaration in the `.proto` file. This is due to the latest update of `protoc` plugin that being used by gripmock is making the `go_package` declaration mandatory.
8+
### Note from the author
9+
Hi all, Jackie here. First of all, I would like to thank you for all those who have contributed to this project. This project has been and will be maintained in my free time, and I maintain it basically by myself, so I apologize for any extremely delayed responses from my side.
1010

11-
**Update Feb 2022:**
11+
Regarding contribution:
12+
- Please raise a PR with a detailed description and state a clear motivation.
13+
- The code implementation should meet the standards that have been set in this repo.
14+
- Only well-demanded features will be accepted, so if you think a feature is uniquely suited to your use case, you can keep it to yourself.
15+
- Tests are mandatory, both unit tests and integration tests whenever applicable.
1216

13-
[Version 1.11-beta](https://github.com/tokopedia/gripmock/releases/tag/v1.11-beta) release is available.
14-
It supports **NO** declaration of `go_package`, please download and test before it can be tagged as stable.
15-
16-
you can get the docker image using `docker pull tkpd/gripmock:v1.11-beta`.
17+
Regarding roadmap:
18+
- I would like to keep gripmock as simple as possible. I want this tool to be as reliable as possible and easy to maintain.
19+
- My priority is to keep up with the latest updates from the frameworks (go, grpc, protoc, etc.) so that this tool can be used with the latest proto.
20+
- Once in a while, I'll check the issues and PR list to see what features are worth adding to gripmock.
1721

1822
---
1923

2024
## Quick Usage
21-
First, prepare your `.proto` file. Or you can use `hello.proto` in `example/simple/` folder. Suppose you put it in `/mypath/hello.proto`. We are gonna use Docker image for easier example test.
22-
basic syntax to run GripMock is
23-
`gripmock <protofile>`
25+
First, prepare your `.proto` file. Or you can use `hello.proto` in `example/simple/` folder. Suppose you put it in `/mypath/hello.proto`. We will use Docker image for easier example test.
2426

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

31-
Check [`example`](https://github.com/tokopedia/gripmock/tree/master/example) folder for various usecase of gripmock.
33+
Check [`example`](https://github.com/tokopedia/gripmock/tree/master/example) folder for various use cases of gripmock.
3234

3335
---
3436

3537
## How It Works
3638
![Running Gripmock](/assets/images/gripmock_readme-running%20system.png)
3739

3840
From client perspective, GripMock has 2 main components:
39-
1. GRPC server that serves on `tcp://localhost:4770`. Its main job is to serve incoming rpc call from client and then parse the input so that it can be posted to Stub service to find the perfect stub match.
40-
2. Stub server that serves on `http://localhost:4771`. Its main job is to store all the stub mapping. We can add a new stub or list existing stub using http request.
41+
1. GRPC server that serves on `tcp://localhost:4770`. Its main job is to serve incoming RPC calls from client and then parse the input so that it can be posted to Stub service to find the perfect stub match.
42+
2. Stub server that serves on `http://localhost:4771`. Its main job is to store all the stub mappings. We can add a new stub or list existing stubs using http request.
4143

42-
Matched stub will be returned to GRPC service then further parse it to response the rpc call.
44+
Matched stub will be returned to GRPC service then further parse it to respond to the RPC call.
4345

4446

4547
From technical perspective, GripMock consists of 2 binaries.
46-
The first binary is the gripmock itself, when it will generate the gRPC server using the plugin installed in the system (see [Dockerfile](Dockerfile)).
47-
When the server sucessfully generated, it will be invoked in parallel with stub server which ends up opening 2 ports for client to use.
48+
The first binary is the gripmock itself, which will generate the gRPC server using the plugin installed in the system (see [Dockerfile](Dockerfile)).
49+
When the server successfully generated, it will be invoked in parallel with stub server which ends up opening 2 ports for client to use.
4850

49-
The second binary is the protoc plugin which located in folder [protoc-gen-gripmock](/protoc-gen-gripmock). This plugin is the one who translates protobuf declaration into a gRPC server in Go programming language.
51+
The second binary is the protoc plugin which is located in the folder [protoc-gen-gripmock](/protoc-gen-gripmock). This plugin is the one who translates protobuf declaration into a gRPC server in Go programming language.
5052

5153
![Inside GripMock](/assets/images/gripmock_readme-inside.png)
5254

5355
---
5456

5557
## Stubbing
5658

57-
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
59+
Stubbing is the essential mocking feature of GripMock. It will match and return the expected result into GRPC service. This is where you put all your request expectations and responses.
5860

5961
### Dynamic stubbing
6062
You could add stubbing on the fly with a simple REST API. HTTP stub server is running on port `:4771`
@@ -63,6 +65,8 @@ You could add stubbing on the fly with a simple REST API. HTTP stub server is ru
6365
- `POST /add` Will add stub with provided stub data
6466
- `POST /find` Find matching stub with provided input. see [Input Matching](#input_matching) below.
6567
- `GET /clear` Clear stub mappings.
68+
- `POST /reset` Reset stub mappings by clearing all stubs and reloading them from the configured stub file path (if provided).
69+
- `GET /requests` List all recorded requests that have been made to the stub server.
6670

6771
Stub Format is JSON text format. It has a skeleton as follows:
6872
```
@@ -118,11 +122,11 @@ Stub will respond with the expected response only if the request matches any rul
118122
"service":"<service name>",
119123
"method":"<method name>",
120124
"data":{
121-
// input that suppose to match with stored stubs
125+
// input that is supposed to match with stored stubs
122126
}
123127
}
124128
```
125-
So if you do a `curl -X POST -d '{"service":"Greeter","method":"SayHello","data":{"name":"gripmock"}}' localhost:4771/find` stub service will find a match from listed stubs stored there.
129+
So if you do a `curl -X POST -d '{"service":"Greeter","method":"SayHello","data":{"name":"gripmock"}}' localhost:4771/find` stub service will find a match from listed stubs.
126130

127131
### Input Matching Rule
128132
Input matching has 4 rules to match an input: **equals**, **equals_unordered**, **contains** and **regex**
@@ -145,7 +149,7 @@ Nested fields are allowed for input matching too for all JSON data types. (`stri
145149
"turkish": "Merhaba Dünya!"
146150
},
147151
"ok": true,
148-
"numbers": [4, 8, 15, 16, 23, 42]
152+
"numbers": [4, 8, 15, 16, 23, 42],
149153
"null": null
150154
}
151155
}
@@ -170,7 +174,7 @@ Nested fields are allowed for input matching too for all JSON data types. (`stri
170174
"turkish": "Merhaba Dünya!"
171175
},
172176
"ok": true,
173-
"numbers": [4, 8, 15, 16, 23, 42]
177+
"numbers": [4, 8, 15, 16, 23, 42],
174178
"null": null
175179
}
176180
}

0 commit comments

Comments
 (0)