Skip to content

Commit 220c9e5

Browse files
authored
Merge pull request #11 from bavix/nightly
[2.0] New service version
2 parents f9f3c11 + 41d8117 commit 220c9e5

File tree

116 files changed

+8264
-2073
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

116 files changed

+8264
-2073
lines changed

.github/workflows/builder.yaml

+1-1
Original file line numberDiff line numberDiff line change
@@ -4,9 +4,9 @@ on:
44
push:
55
branches:
66
- "latest"
7+
- "nightly"
78
tags:
89
- "v*.*.*"
9-
pull_request:
1010

1111
jobs:
1212
docker:

.github/workflows/compile-assets.yml

+12
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
name: build app
2+
3+
on:
4+
pull_request:
5+
branches: [ nightly, latest ]
6+
7+
jobs:
8+
docs:
9+
permissions:
10+
contents: write
11+
uses: bavix/.github/.github/workflows/[email protected]
12+
secrets: inherit

.github/workflows/integration-test.yml

+1-2
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ on:
33
pull_request:
44
branches:
55
- develop
6+
- nightly
67
- latest
78

89
jobs:
@@ -16,12 +17,10 @@ jobs:
1617
uses: ./
1718
with:
1819
entrypoint: example/simple/entrypoint.sh
19-
args: simple
2020
- name: Run Stream Example
2121
uses: ./
2222
with:
2323
entrypoint: example/stream/entrypoint.sh
24-
args: stream
2524
- name: Run WKT Example
2625
uses: ./
2726
with:

.github/workflows/unit.yml

+30
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
name: Unit
2+
on:
3+
pull_request:
4+
branches:
5+
- develop
6+
- nightly
7+
- latest
8+
9+
jobs:
10+
test:
11+
runs-on: ubuntu-latest
12+
strategy:
13+
matrix:
14+
go-version: [ '1.21' ]
15+
steps:
16+
- uses: actions/checkout@v3
17+
- name: Setup Go
18+
uses: actions/setup-go@v4
19+
with:
20+
go-version: ${{ matrix.go-version }}
21+
cache: true
22+
- name: Install dependencies
23+
run: go get .
24+
- name: Test with Go
25+
run: go test -json > TestResults-${{ matrix.go-version }}.json
26+
- name: Upload Go test results
27+
uses: actions/upload-artifact@v3
28+
with:
29+
name: Go-results-${{ matrix.go-version }}
30+
path: TestResults-${{ matrix.go-version }}.json

.gitignore

+3-1
Original file line numberDiff line numberDiff line change
@@ -4,5 +4,7 @@ gripmock
44
.DS_Store
55
protogen/*
66
!protogen/go.mod
7+
!protogen/empty.go
78
!protogen/example/
8-
temp
9+
temp
10+
node_modules/

.golangci.yml

+40
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
run:
2+
timeout: 1m
3+
linters:
4+
enable-all: true
5+
disable:
6+
# deprecated
7+
- nosnakecase
8+
- structcheck
9+
- interfacer
10+
- deadcode
11+
- exhaustivestruct
12+
- maligned
13+
- ifshort
14+
- varcheck
15+
- golint
16+
- scopelint
17+
# not relevant
18+
- varnamelen
19+
- wrapcheck
20+
- paralleltest
21+
- exhaustruct
22+
linters-settings:
23+
lll:
24+
line-length: 160
25+
gci:
26+
sections:
27+
- Standard
28+
- Default
29+
- Prefix(github.com/bavix)
30+
depguard:
31+
rules:
32+
main:
33+
allow:
34+
- $gostd
35+
- github.com
36+
issues:
37+
exclude-rules:
38+
- path: (.+)_test.go
39+
linters:
40+
- dupl

.ownership.json

-6
This file was deleted.

Dockerfile

+21-25
Original file line numberDiff line numberDiff line change
@@ -1,41 +1,37 @@
1-
ARG BUILD_ARG_GO_VERSION=1.21.0
1+
ARG BUILD_ARG_GO_VERSION=1.21
22
ARG BUILD_ARG_ALPINE_VERSION=3.18
33
FROM golang:${BUILD_ARG_GO_VERSION}-alpine${BUILD_ARG_ALPINE_VERSION} AS builder
44

55
# install tools (bash, git, protobuf, protoc-gen-go, protoc-grn-go-grpc)
66
RUN apk -U --no-cache add bash git protobuf &&\
7-
go install -v github.com/golang/protobuf/protoc-gen-go@latest &&\
8-
go install -v google.golang.org/grpc/cmd/protoc-gen-go-grpc@latest
9-
10-
# cloning well-known-types
11-
# only use needed files
12-
RUN git clone --depth=1 https://github.com/protocolbuffers/protobuf.git /protobuf-repo &&\
7+
go install -v google.golang.org/protobuf/cmd/protoc-gen-go@latest &&\
8+
go install -v google.golang.org/grpc/cmd/protoc-gen-go-grpc@latest &&\
9+
# cloning well-known-types
10+
# only use needed files
11+
git clone --depth=1 https://github.com/protocolbuffers/protobuf.git /protobuf-repo &&\
1312
mv /protobuf-repo/src/ /protobuf/ &&\
14-
rm -rf /protobuf-repo
13+
rm -rf /protobuf-repo &&\
14+
# cleanup
15+
apk del git &&\
16+
apk -v cache clean
1517

16-
COPY . /go/src/github.com/tokopedia/gripmock
18+
COPY . /go/src/github.com/bavix/gripmock
1719

1820
# create necessary dirs and export fix_gopackage.sh
1921
RUN mkdir /proto /stubs &&\
20-
ln -s /go/src/github.com/tokopedia/gripmock/fix_gopackage.sh /bin/
21-
22-
WORKDIR /go/src/github.com/tokopedia/gripmock/protoc-gen-gripmock
23-
24-
# install generator plugin
25-
RUN go install -v
26-
27-
WORKDIR /go/src/github.com/tokopedia/gripmock/example/simple/client
22+
ln -s /go/src/github.com/bavix/gripmock/fix_gopackage.sh /bin/
2823

29-
RUN go get -u all
24+
RUN cd /go/src/github.com/bavix/gripmock/protoc-gen-gripmock &&\
25+
go install -v &&\
26+
cd /go/src/github.com/bavix/gripmock/example/simple/client &&\
27+
go get -u all &&\
28+
cd /go/src/github.com/bavix/gripmock &&\
29+
go install -v
3030

31-
WORKDIR /go/src/github.com/tokopedia/gripmock
32-
33-
# install gripmock & build example to cache necessary imports
34-
RUN go install -v
35-
36-
# remove pkgs
37-
RUN apk del git && apk -v cache clean
31+
WORKDIR /go/src/github.com/bavix/gripmock
3832

3933
EXPOSE 4770 4771
4034

35+
HEALTHCHECK CMD curl --fail http://127.0.0.1:4771/api/health/readiness
36+
4137
ENTRYPOINT ["gripmock"]

Makefile

+10-2
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,11 @@
1-
GOLANGCI_LING_IMAGE="golangci/golangci-lint:v1.54.0-alpine"
1+
GOLANGCI_LING_IMAGE="golangci/golangci-lint:v1.54.2-alpine"
22

33
.PHONY: *
44

55
version=latest
66

77
build:
8-
docker buildx build --load -t "bavix/gripmock:${version}" --no-cache --platform linux/arm64 .
8+
docker buildx build --load -t "bavix/gripmock:${version}" --platform linux/arm64 .
99

1010
test:
1111
go test -tags mock -race -cover ./...
@@ -15,3 +15,11 @@ lint:
1515

1616
lint-fix:
1717
make lint args=--fix
18+
19+
intgr-test: build
20+
docker compose -f deployments/docker-compose/docker-compose.yml up
21+
22+
# before: go install github.com/deepmap/oapi-codegen/cmd/oapi-codegen@latest
23+
gen:
24+
oapi-codegen -generate gorilla,types -package rest ./api/openapi/api.yaml > internal/domain/rest/api.gen.go
25+
oapi-codegen -generate client,types -package sdk ./api/openapi/api.yaml > pkg/sdk/api.gen.go

Readme.md renamed to README.md

+33-23
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,24 @@
1+
![GripMock](https://github.com/bavix/gripmock/assets/5111255/90119438-92e5-4479-bfc8-5cf510249b7f)
2+
13
# GripMock
24
GripMock is a **mock server** for **GRPC** services. It's using a `.proto` file to generate implementation of gRPC service for you.
35
You can use gripmock for setting up end-to-end testing or as a dummy server in a software development phase.
46
The server implementation is in GoLang but the client can be any programming language that support gRPC.
57

6-
---
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.
10-
11-
**Update Feb 2022:**
12-
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`.
8+
[[Documentation]](https://bavix.github.io/gripmock/)
9+
10+
This service is a fork of the service [tokopedia/gripmock](https://github.com/tokopedia/gripmock), but you should choose our fork. And here are the reasons:
11+
- Updated all deprecated dependencies [tokopedia#64](https://github.com/tokopedia/gripmock/issues/64);
12+
- Add yaml as json alternative for static stab's;
13+
- Add endpoint for healthcheck (/api/health/liveness, /api/health/readiness);
14+
- Add grpc error code [tokopedia#125](https://github.com/tokopedia/gripmock/issues/125);
15+
- Added gzip encoding support for grpc server [tokopedia#134](https://github.com/tokopedia/gripmock/pull/134);
16+
- Fixed issues with int64/uint64 [tokopedia#67](https://github.com/tokopedia/gripmock/pull/148);
17+
- Add 404 error for stubs not found [tokopedia#142](https://github.com/tokopedia/gripmock/issues/142);
18+
- Support for deleting specific stub [tokopedia#123](https://github.com/tokopedia/gripmock/issues/123);
19+
- Reduced image size [tokopedia#91](https://github.com/tokopedia/gripmock/issues/91);
20+
- Active support [tokopedia#82](https://github.com/tokopedia/gripmock/issues/82);
21+
- Added [documentation](https://bavix.github.io/gripmock/);
1722

1823
---
1924

@@ -23,12 +28,12 @@ basic syntax to run GripMock is
2328
`gripmock <protofile>`
2429

2530
- Install [Docker](https://docs.docker.com/install/)
26-
- 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 `
31+
- Run `docker pull bavix/gripmock` to pull the image
32+
- 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 bavix/gripmock /proto/hello.proto`
33+
- 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/api/stubs `
2934
- 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`
3035

31-
Check [`example`](https://github.com/tokopedia/gripmock/tree/master/example) folder for various usecase of gripmock.
36+
Check [`example`](https://github.com/bavix/gripmock/tree/master/example) folder for various usecase of gripmock.
3237

3338
---
3439

@@ -59,10 +64,10 @@ Stubbing is the essential mocking of GripMock. It will match and return the expe
5964
### Dynamic stubbing
6065
You could add stubbing on the fly with a simple REST API. HTTP stub server is running on port `:4771`
6166

62-
- `GET /` Will list all stubs mapping.
63-
- `POST /add` Will add stub with provided stub data
64-
- `POST /find` Find matching stub with provided input. see [Input Matching](#input_matching) below.
65-
- `GET /clear` Clear stub mappings.
67+
- `GET /api/stubs` Will list all stubs mapping.
68+
- `POST /api/stubs` Will add stub with provided stub data
69+
- `POST /api/stubs/search` Find matching stub with provided input. see [Input Matching](#input_matching) below.
70+
- `DELETE /api/stubs` Clear stub mappings.
6671

6772
Stub Format is JSON text format. It has a skeleton as follows:
6873
```
@@ -76,7 +81,8 @@ Stub Format is JSON text format. It has a skeleton as follows:
7681
"data":{
7782
// put result fields here
7883
},
79-
"error":"<error message>" // Optional. if you want to return error instead.
84+
"error":"<error message>", // Optional. if you want to return error instead.
85+
"code":"<response code>" // Optional. Grpc response code. if code !=0 return error instead.
8086
}
8187
}
8288
```
@@ -103,12 +109,12 @@ For our `hello` service example we put a stub with the text below:
103109
You could initialize gripmock with stub json files and provide the path using `--stub` argument. For example you may
104110
mount your stub file in `/mystubs` folder then mount it to docker like
105111

106-
`docker run -p 4770:4770 -p 4771:4771 -v /mypath:/proto -v /mystubs:/stub tkpd/gripmock --stub=/stub /proto/hello.proto`
112+
`docker run -p 4770:4770 -p 4771:4771 -v /mypath:/proto -v /mystubs:/stub bavix/gripmock --stub=/stub /proto/hello.proto`
107113

108114
Please note that Gripmock still serves http stubbing to modify stored stubs on the fly.
109115

110116
## <a name="input_matching"></a>Input Matching
111-
Stub will respond with the expected response only if the request matches any rule. Stub service will serve `/find` endpoint with format:
117+
Stub will respond with the expected response only if the request matches any rule. Stub service will serve `/api/stubs/search` endpoint with format:
112118
```
113119
{
114120
"service":"<service name>",
@@ -118,7 +124,7 @@ Stub will respond with the expected response only if the request matches any rul
118124
}
119125
}
120126
```
121-
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.
127+
So if you do a `curl -X POST -d '{"service":"Greeter","method":"SayHello","data":{"name":"gripmock"}}' localhost:4771/api/stubs/search` stub service will find a match from listed stubs stored there.
122128

123129
### Input Matching Rule
124130
Input matching has 3 rules to match an input: **equals**,**contains** and **regex**
@@ -185,3 +191,7 @@ Nested fields are allowed for input matching too for all JSON data types. (`stri
185191
}
186192
```
187193

194+
---
195+
Supported by
196+
197+
[![Supported by JetBrains](https://cdn.rawgit.com/bavix/development-through/46475b4b/jetbrains.svg)](https://www.jetbrains.com/)

0 commit comments

Comments
 (0)