All Projects → tokopedia → Gripmock

tokopedia / Gripmock

Licence: apache-2.0
gRPC Mock Server

Programming Languages

go
31211 projects - #10 most used programming language

Labels

Projects that are alternatives of or similar to Gripmock

Mockiato
A strict, yet friendly mocking library for Rust 2018
Stars: ✭ 229 (-7.66%)
Mutual labels:  mock
Yivnet
Yivnet is a microservice game server base on go-kit
Stars: ✭ 237 (-4.44%)
Mutual labels:  grpc
Shallow Render
Angular testing made easy with shallow rendering and easy mocking. https://getsaf.github.io/shallow-render
Stars: ✭ 242 (-2.42%)
Mutual labels:  mock
Mockito Scala
Mockito for Scala language
Stars: ✭ 231 (-6.85%)
Mutual labels:  mock
Homo
An open source natural interaction system based on offline wake-up, natural language understanding and sentiment analysis
Stars: ✭ 233 (-6.05%)
Mutual labels:  grpc
Ttrpc
GRPC for low-memory environments
Stars: ✭ 236 (-4.84%)
Mutual labels:  grpc
Node Mock Server
File based Node REST API mock server
Stars: ✭ 225 (-9.27%)
Mutual labels:  mock
Netcorekit
💗 A crafted toolkit for building cloud-native apps on the .NET platform
Stars: ✭ 248 (+0%)
Mutual labels:  grpc
Tensorrt Laboratory
Explore the Capabilities of the TensorRT Platform
Stars: ✭ 236 (-4.84%)
Mutual labels:  grpc
Grpc Swagger
Debugging gRPC application with swagger-ui.
Stars: ✭ 242 (-2.42%)
Mutual labels:  grpc
Okhttp Json Mock
Mock your datas for Okhttp and Retrofit in json format in just a few moves
Stars: ✭ 231 (-6.85%)
Mutual labels:  mock
Faker
Provides fake data to your Android apps :)
Stars: ✭ 234 (-5.65%)
Mutual labels:  mock
Adlik
Adlik: Toolkit for Accelerating Deep Learning Inference
Stars: ✭ 237 (-4.44%)
Mutual labels:  grpc
Axios Mock Adapter
Axios adapter that allows to easily mock requests
Stars: ✭ 2,832 (+1041.94%)
Mutual labels:  mock
Vuex Mock Store
✅Simple and straightforward Vuex Store mock for vue-test-utils
Stars: ✭ 246 (-0.81%)
Mutual labels:  mock
Jest Mock Extended
Type safe mocking extensions for Jest https://www.npmjs.com/package/jest-mock-extended
Stars: ✭ 224 (-9.68%)
Mutual labels:  mock
Mockoon
Mockoon is the easiest and quickest way to run mock APIs locally. No remote deployment, no account required, open source.
Stars: ✭ 3,448 (+1290.32%)
Mutual labels:  mock
Go Grpc Http Rest Microservice Tutorial
Source code for tutorial "How to develop Go gRPC microservice with HTTP/REST endpoint, middleware, Kubernetes deployment, etc."
Stars: ✭ 250 (+0.81%)
Mutual labels:  grpc
Jest Localstorage Mock
A module to mock window.localStorage and window.sessionStorage in Jest
Stars: ✭ 247 (-0.4%)
Mutual labels:  mock
Kuberesolver
Grpc Load Balancer with Kubernetes resolver
Stars: ✭ 241 (-2.82%)
Mutual labels:  grpc

GripMock

GripMock is a mock server for GRPC services. It's using a .proto file to generate implementation of gRPC service for you. If you are already familiar with Apiary or WireMock for mocking API service and looking for similiar thing for GRPC then this is the perfect fit for that.

How It Works

GripMock has 2 main components:

  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.
  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.

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 are gonna use Docker image for easier example test. basic syntax to run GripMock is gripmock <protofile>

  • Install Docker
  • Run docker pull tkpd/gripmock to pull the image
  • 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
  • On a separate terminal we are gonna add a stub into the 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 a client example file under example/simple/client/. Execute one of your preferred language. Example for go: go run example/simple/client/go/*.go

Check 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

Dynamic stubbing

You could add stubbing on the fly with a simple REST API. HTTP stub server is running on port :4771

  • GET / Will list all stubs mapping.
  • POST /add Will add stub with provided stub data
  • POST /find Find matching stub with provided input. see Input Matching below.
  • GET /clear Clear stub mappings.

Stub Format is JSON text format. It has a skeleton as follows:

{
  "service":"<servicename>", // name of service defined in proto
  "method":"<methodname>", // name of method that we want to mock
  "input":{ // input matching rule. see Input Matching Rule section below
    // put rule here
  },
  "output":{ // output json if input were matched
    "data":{
      // put result fields here
    },
    "error":"<error message>" // Optional. if you want to return error instead.
  }
}

For our hello service example we put a stub with the text below:

  {
    "service":"Greeter",
    "method":"SayHello",
    "input":{
      "equals":{
        "name":"gripmock"
      }
    },
    "output":{
      "data":{
        "message":"Hello GripMock"
      }
    }
  }

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 serves http stubbing to modify stored stubs on the fly.

Input Matching

Stub will respond with the expected response only if the request matches any rule. Stub service will serve /find endpoint with format:

{
  "service":"<service name>",
  "method":"<method name>",
  "data":{
    // input that suppose to match with stored stubs
  }
}

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.

Input Matching Rule

Input matching has 3 rules to match an input. which is equals,contains and regex
equals will match the exact field name and value of input into expected stub. example stub JSON:

{
  .
  .
  "input":{
    "equals":{
      "name":"gripmock"
    }
  }
  .
  .
}

contains will match input that has the value declared expected fields. example stub JSON:

{
  .
  .
  "input":{
    "contains":{
      "field2":"hello"
    }
  }
  .
  .
}

matches using regex for matching fields expectation. example:

{
  .
  .
  "input":{
    "matches":{
      "name":"^grip.*$"
    }
  }
  .
  .
}
Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].