Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
46 changes: 30 additions & 16 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -4,30 +4,44 @@ on: push

jobs:
test:
runs-on: ubuntu-20.04
runs-on: ubuntu-24.04
name: OTP ${{matrix.otp}} / Elixir ${{matrix.elixir}}
strategy:
fail-fast: false
matrix:
include:
- elixir: 1.12.x
otp: 22
- elixir: 1.12.x
otp: 23
- elixir: 1.12.x
- elixir: 1.12
otp: 24
- elixir: 1.13.x
otp: 22
- elixir: 1.13.x
otp: 23
- elixir: 1.13.x
- elixir: 1.13
otp: 24
- elixir: 1.14.x
otp: 23
- elixir: 1.14.x
- elixir: 1.14
otp: 24
- elixir: 1.14.x
- elixir: 1.14
otp: 25
- elixir: 1.15
otp: 24
- elixir: 1.15
otp: 25
- elixir: 1.15
otp: 26
- elixir: 1.16
otp: 24
- elixir: 1.16
otp: 25
- elixir: 1.16
otp: 26
- elixir: 1.17
otp: 25
- elixir: 1.17
otp: 26
- elixir: 1.17
otp: 27
- elixir: 1.18.4
otp: 25
- elixir: 1.18.4
otp: 26
- elixir: 1.18.4
otp: 27
lint: true
env:
MIX_ENV: test
Expand All @@ -50,7 +64,7 @@ jobs:

- run: mix deps.compile

- run: mix compile --warnings-as-errors
- run: mix compile
Copy link
Copy Markdown
Contributor Author

@guisehn guisehn Jun 26, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

CI in Elixir 1.18.4 won't pass without this change:

warning: using map.field notation (without parentheses) to invoke function TestSupport.GreetService.Service.__rpc_calls__() is deprecated, you must add parentheses instead: remote.function()
Warning:   test/support/greet_service.pb.ex:27: (module)
  (elixir 1.18.4) src/elixir_compiler.erl:77: :elixir_compiler.dispatch/4
  (elixir 1.18.4) src/elixir_compiler.erl:52: :elixir_compiler.compile/4
  (elixir 1.18.4) src/elixir_module.erl:456: :elixir_module.eval_form/7
  (elixir 1.18.4) src/elixir_module.erl:156: :elixir_module.compile/7

This piece of code calling __rpc_calls__ is injected by Protobuf, we have no control over it

if: ${{ matrix.lint }}

- run: mix test
Expand Down
6 changes: 6 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,11 @@
# Changelog for MockGRPC

## v0.2.0

### Added

- Support for `grpc` 0.10 (there was a breaking change on https://github.com/elixir-grpc/grpc/pull/395)

## v0.1.0

### Added
Expand Down
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ Add `mock_grpc` to your list of dependencies:
```elixir
def deps do
[
{:mock_grpc, "~> 0.1"},
{:mock_grpc, "~> 0.2"},

# You also need to have gRPC Elixir installed
{:grpc, "~> 0.6"}
Expand Down
2 changes: 1 addition & 1 deletion lib/mock_grpc.ex
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,7 @@ defmodule MockGRPC do
@doc false
def setup(context) do
if Process.get(MockGRPC) do
Logger.warn("Attempted to set up MockGRPC twice. Skipping...")
Logger.warning("Attempted to set up MockGRPC twice. Skipping...")
else
do_setup(context)
end
Expand Down
5 changes: 4 additions & 1 deletion lib/mock_grpc/adapter.ex
Original file line number Diff line number Diff line change
Expand Up @@ -26,10 +26,13 @@ defmodule MockGRPC.Adapter do

@impl true
def send_request(%Stream{request_mod: request_mod} = stream, content, _opts) do
input = request_mod.decode(content)
input = content |> to_binary() |> request_mod.decode()
Stream.put_payload(stream, :input, input)
end

defp to_binary(content) when is_binary(content), do: content
defp to_binary(content) when is_list(content), do: IO.iodata_to_binary(content)

@impl true
def receive_data(
%Stream{rpc: rpc, service_name: service_name, payload: %{input: input}},
Expand Down
4 changes: 2 additions & 2 deletions mix.exs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ defmodule MockGRPC.MixProject do
use Mix.Project

@source_url "https://github.com/TheRealReal/mock_grpc"
@version "0.1.0"
@version "0.2.0"

def project do
[
Expand Down Expand Up @@ -32,7 +32,7 @@ defmodule MockGRPC.MixProject do
defp deps do
[
{:grpc, "~> 0.6"},
{:protobuf, "~> 0.11", only: :test},
{:protobuf, "~> 0.14.1", only: :test},
{:ex_doc, ">= 0.0.0", only: :dev, runtime: false}
]
end
Expand Down
2 changes: 1 addition & 1 deletion mix.lock
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
"makeup_erlang": {:hex, :makeup_erlang, "0.1.2", "ad87296a092a46e03b7e9b0be7631ddcf64c790fa68a9ef5323b6cbb36affc72", [:mix], [{:makeup, "~> 1.0", [hex: :makeup, repo: "hexpm", optional: false]}], "hexpm", "f3f5a1ca93ce6e092d92b6d9c049bcda58a3b617a8d888f8e7231c85630e8108"},
"mint": {:hex, :mint, "1.4.2", "50330223429a6e1260b2ca5415f69b0ab086141bc76dc2fbf34d7c389a6675b2", [:mix], [{:castore, "~> 0.1.0", [hex: :castore, repo: "hexpm", optional: true]}, {:hpax, "~> 0.1.1", [hex: :hpax, repo: "hexpm", optional: false]}], "hexpm", "ce75a5bbcc59b4d7d8d70f8b2fc284b1751ffb35c7b6a6302b5192f8ab4ddd80"},
"nimble_parsec": {:hex, :nimble_parsec, "1.3.1", "2c54013ecf170e249e9291ed0a62e5832f70a476c61da16f6aac6dca0189f2af", [:mix], [], "hexpm", "2682e3c0b2eb58d90c6375fc0cc30bc7be06f365bf72608804fb9cffa5e1b167"},
"protobuf": {:hex, :protobuf, "0.12.0", "58c0dfea5f929b96b5aa54ec02b7130688f09d2de5ddc521d696eec2a015b223", [:mix], [{:jason, "~> 1.2", [hex: :jason, repo: "hexpm", optional: true]}], "hexpm", "75fa6cbf262062073dd51be44dd0ab940500e18386a6c4e87d5819a58964dc45"},
"protobuf": {:hex, :protobuf, "0.14.1", "9ac0582170df27669ccb2ef6cb0a3d55020d58896edbba330f20d0748881530a", [:mix], [{:jason, "~> 1.2", [hex: :jason, repo: "hexpm", optional: true]}], "hexpm", "39a9d49d346e3ed597e5ae3168a43d9603870fc159419617f584cdf6071f0e25"},
"ranch": {:hex, :ranch, "1.8.0", "8c7a100a139fd57f17327b6413e4167ac559fbc04ca7448e9be9057311597a1d", [:make, :rebar3], [], "hexpm", "49fbcfd3682fab1f5d109351b61257676da1a2fdbe295904176d5e521a2ddfe5"},
"telemetry": {:hex, :telemetry, "1.2.1", "68fdfe8d8f05a8428483a97d7aab2f268aaff24b49e0f599faa091f1d4e7f61c", [:rebar3], [], "hexpm", "dad9ce9d8effc621708f99eac538ef1cbe05d6a874dd741de2e689c47feafed5"},
}
19 changes: 19 additions & 0 deletions test/mock_grpc/adapter_test.exs
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
defmodule MockGRPC.AdapterTest do
use ExUnit.Case

describe "send_request/3" do
test "works with binary (elixir-grpc < 0.10.0)" do
stream = %GRPC.Client.Stream{request_mod: TestSupport.SayHelloRequest}
struct = %TestSupport.SayHelloRequest{first_name: "John", last_name: "Doe"}
content = Protobuf.Encoder.encode(struct)
assert MockGRPC.Adapter.send_request(stream, content, []).payload.input == struct
end

test "works with iodata (elixir-grpc >= 0.10.0)" do
stream = %GRPC.Client.Stream{request_mod: TestSupport.SayHelloRequest}
struct = %TestSupport.SayHelloRequest{first_name: "John", last_name: "Doe"}
content = Protobuf.Encoder.encode_to_iodata(struct)
assert MockGRPC.Adapter.send_request(stream, content, []).payload.input == struct
end
end
end
Loading