Giter VIP home page Giter VIP logo

grpc_mox's Introduction

GrpcMox

GrpcMox is a library for defining concurrent mocks for grpc library.

Installation

Just add grpc_mox to your list of dependencies in mix.exs:

def deps do
  [
      {:grpc_mox, git: "https://github.com/avillen/grpc_mox", tag: "v0.2.0"},
  ]
end

Basic usage

0) Read the Mox documentation.

1) Define the mock in your test or in your test/support/mocks.exs file

...

Mox.defmock(GRPCClientMock, for: GRPC.Client.Adapter)

2) Use the mock adapter creating the connection:

You would want to use the mock or the real adapter based on a application environment variable, this example is to simplify the code.

connect_opts = [
  adapter: GRPCClientMock
]

GRPC.Stub.connect(base_url, connect_opts)

3) Add the expectation in your test:

req = Helloworld.HelloRequest.new(name: "Álvaro")
res = Helloworld.HelloResponse.new(message: "Hola")

GrpcMox.expect_grpc(GRPCClientMock, req, res)

{:ok, conn} = GRPC.Stub.connect("localhost:0", adapter: GRPCClientMock)

assert {:ok, res} == Helloworld.Stub.say_hello(conn, req)

GRPC.Stub.disconnect(conn)

grpc_mox's People

Contributors

avillen avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.