diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 5ace867..53c2cef 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -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 @@ -50,7 +64,7 @@ jobs: - run: mix deps.compile - - run: mix compile --warnings-as-errors + - run: mix compile if: ${{ matrix.lint }} - run: mix test diff --git a/CHANGELOG.md b/CHANGELOG.md index e3bfb32..3fba81b 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -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 diff --git a/README.md b/README.md index f35b588..c1aacd0 100644 --- a/README.md +++ b/README.md @@ -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"} diff --git a/lib/mock_grpc.ex b/lib/mock_grpc.ex index e039e5f..1b15502 100644 --- a/lib/mock_grpc.ex +++ b/lib/mock_grpc.ex @@ -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 diff --git a/lib/mock_grpc/adapter.ex b/lib/mock_grpc/adapter.ex index a680e35..4ab4ebe 100644 --- a/lib/mock_grpc/adapter.ex +++ b/lib/mock_grpc/adapter.ex @@ -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}}, diff --git a/mix.exs b/mix.exs index e075c85..e22dcc7 100644 --- a/mix.exs +++ b/mix.exs @@ -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 [ @@ -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 diff --git a/mix.lock b/mix.lock index c193a0b..3a1f226 100644 --- a/mix.lock +++ b/mix.lock @@ -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"}, } diff --git a/test/mock_grpc/adapter_test.exs b/test/mock_grpc/adapter_test.exs new file mode 100644 index 0000000..6bad3f0 --- /dev/null +++ b/test/mock_grpc/adapter_test.exs @@ -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