You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: Readme.md
+31-27Lines changed: 31 additions & 27 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -1,60 +1,62 @@
1
1
# 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.
3
3
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.
5
5
6
6
---
7
7
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.
10
10
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.
12
16
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.
17
21
18
22
---
19
23
20
24
## 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.
- 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`
30
32
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.
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.
41
43
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.
43
45
44
46
45
47
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.
48
50
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.
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.
58
60
59
61
### Dynamic stubbing
60
62
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
63
65
-`POST /add` Will add stub with provided stub data
64
66
-`POST /find` Find matching stub with provided input. see [Input Matching](#input_matching) below.
65
67
-`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.
66
70
67
71
Stub Format is JSON text format. It has a skeleton as follows:
68
72
```
@@ -118,11 +122,11 @@ Stub will respond with the expected response only if the request matches any rul
118
122
"service":"<service name>",
119
123
"method":"<method name>",
120
124
"data":{
121
-
// input that suppose to match with stored stubs
125
+
// input that is supposed to match with stored stubs
122
126
}
123
127
}
124
128
```
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.
126
130
127
131
### Input Matching Rule
128
132
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
145
149
"turkish": "Merhaba Dünya!"
146
150
},
147
151
"ok": true,
148
-
"numbers": [4, 8, 15, 16, 23, 42]
152
+
"numbers": [4, 8, 15, 16, 23, 42],
149
153
"null": null
150
154
}
151
155
}
@@ -170,7 +174,7 @@ Nested fields are allowed for input matching too for all JSON data types. (`stri
0 commit comments