Skip to content

Commit

Permalink
Fix CI and update Elixir and OTP versions (#136)
Browse files Browse the repository at this point in the history
  • Loading branch information
whatyouhide authored Nov 13, 2024
1 parent 7c290df commit 26c1552
Show file tree
Hide file tree
Showing 5 changed files with 44 additions and 49 deletions.
32 changes: 16 additions & 16 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -16,37 +16,40 @@ jobs:
fail-fast: false
matrix:
include:
- pair:
elixir: "1.8.2"
otp: "21.3.8.17"
- pair:
elixir: "1.15.0"
otp: "25.3"
# Hard to test the oldest-supported version because rabbit_common and friends
# are a bit hard to get compatibility right for. However, we don't really need
# to do that here.
- elixir: "1.16"
otp: "26.2"

# Latest-supported Elixir/OTP versions.
- elixir: "1.17.3"
otp: "27.1"
lint: lint
coverage: coverage
steps:
- name: Clone the repository
uses: actions/checkout@v3
uses: actions/checkout@v4

- name: Start Docker
run: docker-compose up --detach
run: docker compose up --detach

- name: Install Erlang/OTP and Elixir
uses: erlef/setup-beam@v1
with:
otp-version: ${{ matrix.pair.otp }}
elixir-version: ${{ matrix.pair.elixir }}
otp-version: ${{ matrix.otp }}
elixir-version: ${{ matrix.elixir }}

- name: Cache Mix dependencies
uses: actions/cache@v3
uses: actions/cache@v4
with:
path: |
deps
_build
key: |
${{ runner.os }}-mix-${{ matrix.pair.elixir }}-${{ matrix.pair.otp }}-${{ hashFiles('**/mix.lock') }}
${{ runner.os }}-mix-${{ matrix.elixir }}-${{ matrix.otp }}-${{ hashFiles('**/mix.lock') }}
restore-keys: |
${{ runner.os }}-mix-${{ matrix.pair.elixir }}-${{ matrix.pair.otp }}-
${{ runner.os }}-mix-${{ matrix.elixir }}-${{ matrix.otp }}-
- name: Fetch Mix dependencies
run: mix deps.get
Expand All @@ -59,9 +62,6 @@ jobs:
run: mix deps.unlock --check-unused
if: ${{ matrix.lint }}

- name: Compile Mix dependencies
run: mix deps.compile

- name: Compile code and check for warnings
run: mix compile --warnings-as-errors
if: ${{ matrix.lint }}
Expand Down
2 changes: 0 additions & 2 deletions docker-compose.yml
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
version: '3'

services:
rabbitmq:
image: "rabbitmq:3.11.9-alpine"
Expand Down
2 changes: 1 addition & 1 deletion mix.exs
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ defmodule BroadwayRabbitMQ.MixProject do
[
app: :broadway_rabbitmq,
version: @version,
elixir: "~> 1.8",
elixir: "~> 1.13",
name: "BroadwayRabbitMQ",
description: @description,
start_permanent: Mix.env() == :prod,
Expand Down
27 changes: 15 additions & 12 deletions test/broadway_rabbitmq/ampq_client_test.exs
Original file line number Diff line number Diff line change
Expand Up @@ -138,15 +138,15 @@ defmodule BroadwayRabbitMQ.AmqpClientTest do

test ":queue is required" do
assert AmqpClient.init([]) ==
{:error, "required option :queue not found, received options: []"}
{:error, "required :queue option not found, received options: []"}

assert AmqpClient.init(queue: nil) ==
{:error, "expected :queue to be a string, got: nil"}
{:error, "invalid value for :queue option: expected string, got: nil"}
end

test ":queue should be a string" do
assert AmqpClient.init(queue: :an_atom) ==
{:error, "expected :queue to be a string, got: :an_atom"}
{:error, "invalid value for :queue option: expected string, got: :an_atom"}

{:ok, config} = AmqpClient.init(queue: "my_queue")
assert config.queue == "my_queue"
Expand All @@ -165,9 +165,10 @@ defmodule BroadwayRabbitMQ.AmqpClientTest do
{:ok, opts} = AmqpClient.init(queue: "queue", metadata: [:routing_key, :headers])
assert opts[:metadata] == [:routing_key, :headers]

message =
~s(list element at position 0 in :metadata failed validation: expected "list element" ) <>
~s(to be an atom, got: "routing_key")
message = """
invalid list in :metadata option: invalid value for list element at position 0: expected \
atom, got: "routing_key"\
"""

assert AmqpClient.init(queue: "queue", metadata: ["routing_key", :headers]) ==
{:error, message}
Expand All @@ -177,18 +178,20 @@ defmodule BroadwayRabbitMQ.AmqpClientTest do
{:ok, opts} = AmqpClient.init(queue: "queue", bindings: [{"my-exchange", [arguments: []]}])
assert opts[:bindings] == [{"my-exchange", [arguments: []]}]

message =
~s(list element at position 0 in :bindings failed validation: expected binding to be ) <>
~s(a {exchange, opts} tuple, got: :something)
message = """
invalid list in :bindings option: invalid value for list element at position 0: \
expected binding to be a {exchange, opts} tuple, got: :something\
"""

assert AmqpClient.init(queue: "queue", bindings: [:something, :else]) ==
{:error, message}
end

test ":bindings with invalid binding options" do
message =
"list element at position 0 in :bindings failed validation: unknown options " <>
"[:invalid], valid options are: [:routing_key, :arguments]"
message = """
invalid list in :bindings option: invalid value for list element at position 0: \
unknown options [:invalid], valid options are: [:routing_key, :arguments]\
"""

assert AmqpClient.init(queue: "queue", bindings: [{"my-exchange", [invalid: true]}]) ==
{:error, message}
Expand Down
30 changes: 12 additions & 18 deletions test/broadway_rabbitmq/producer_test.exs
Original file line number Diff line number Diff line change
Expand Up @@ -230,27 +230,21 @@ defmodule BroadwayRabbitMQ.ProducerTest do
end

test "raise an ArgumentError with proper message when client options are invalid" do
assert_raise(
ArgumentError,
"invalid options given to BroadwayRabbitMQ.AmqpClient.init/1, expected :queue to be a string, got: nil",
fn ->
BroadwayRabbitMQ.Producer.init(queue: nil, on_failure: :reject_and_requeue)
end
)
message = ~r/invalid value for :queue option: expected string, got: nil/

assert_raise ArgumentError, message, fn ->
BroadwayRabbitMQ.Producer.init(queue: nil, on_failure: :reject_and_requeue)
end
end

test "raise an ArgumentError with proper message when backoff options are invalid" do
assert_raise(
ArgumentError,
~r/expected :backoff_type to be one of/,
fn ->
BroadwayRabbitMQ.Producer.init(
queue: "test",
backoff_type: :unknown_type,
on_failure: :reject_and_requeue
)
end
)
assert_raise ArgumentError, ~r/invalid value for :backoff_type/, fn ->
BroadwayRabbitMQ.Producer.init(
queue: "test",
backoff_type: :unknown_type,
on_failure: :reject_and_requeue
)
end
end

test "prints a deprecation warning when :on_failure is not specified" do
Expand Down

0 comments on commit 26c1552

Please sign in to comment.