Replace Mox with Patch
This commit is contained in:
47
test/consumer_offset_fetcher_test.exs
Normal file
47
test/consumer_offset_fetcher_test.exs
Normal 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
|
||||
Reference in New Issue
Block a user