Replace Mox with Patch

This commit is contained in:
2024-03-27 22:19:32 +01:00
parent 207926ed83
commit 7b40cbedd1
11 changed files with 66 additions and 111 deletions

View File

@@ -0,0 +1,47 @@
defmodule KafkaexLagExporter.ConsumerOffsetFetcher.Test do
use ExUnit.Case, async: true
use Patch
@test_consumer_group_name1 "test_consumer_1"
@test_consumer_group_name2 "test_consumer_2"
@test_lags [{0, 23}, {1, 42}, {2, 666}]
setup do
patch(
KafkaexLagExporter.KafkaUtils,
:get_consumer_group_names,
fn _ -> [@test_consumer_group_name1, @test_consumer_group_name2] end
)
patch(KafkaexLagExporter.KafkaUtils, :lag, fn _, _, _ -> @test_lags end)
patch(
KafkaexLagExporter.KafkaUtils,
:topic_names_for_consumer_groups,
fn _, _, _ ->
[
{@test_consumer_group_name1, ["test_topic_1", "test_topic_2"]},
{@test_consumer_group_name2, ["test_topic_3"]}
]
end
)
:ok
end
test "should return the calculated lags" do
test_endpoint = {"test endpoint", 666}
%{sum: sum, lags: lags} = KafkaexLagExporter.ConsumerOffsetFetcher.get(test_endpoint)
assert sum == [
{@test_consumer_group_name1, 1462},
{@test_consumer_group_name2, 731}
]
assert lags == [
{@test_consumer_group_name1, @test_lags ++ @test_lags},
{@test_consumer_group_name2, @test_lags}
]
end
end