Simplify code

This commit is contained in:
2024-03-28 21:23:51 +01:00
parent 6bf68b74ec
commit 08b5923d52
2 changed files with 26 additions and 24 deletions

View File

@@ -4,7 +4,11 @@ defmodule KafkaexLagExporter.ConsumerOffsetFetcher.Test do
@test_consumer_group_name1 "test_consumer_1"
@test_consumer_group_name2 "test_consumer_2"
@test_lags [{0, 23}, {1, 42}, {2, 666}]
@test_lags1 [{0, 23}, {1, 42}, {2, 666}]
@test_lags2 [{0, 1}, {1, 2}, {2, 3}]
@test_topic1 "test_topic_1"
@test_topic2 "test_topic_2"
@test_topic3 "test_topic_3"
setup do
patch(
@@ -13,15 +17,15 @@ defmodule KafkaexLagExporter.ConsumerOffsetFetcher.Test do
fn _ -> [@test_consumer_group_name1, @test_consumer_group_name2] end
)
patch(KafkaexLagExporter.KafkaUtils, :lag, fn _, _, _ -> @test_lags end)
patch(KafkaexLagExporter.KafkaUtils, :lag, &lag(&1, &2, &3))
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"]}
{@test_consumer_group_name1, [@test_topic1, @test_topic2]},
{@test_consumer_group_name2, [@test_topic3]}
]
end
)
@@ -35,13 +39,18 @@ defmodule KafkaexLagExporter.ConsumerOffsetFetcher.Test do
%{sum: sum, lags: lags} = KafkaexLagExporter.ConsumerOffsetFetcher.get(test_endpoint)
assert sum == [
{@test_consumer_group_name1, 1462},
{@test_consumer_group_name2, 731}
{@test_consumer_group_name1, @test_topic1, 731},
{@test_consumer_group_name1, @test_topic2, 6},
{@test_consumer_group_name2, @test_topic3, 6}
]
assert lags == [
{@test_consumer_group_name1, @test_lags ++ @test_lags},
{@test_consumer_group_name2, @test_lags}
{@test_consumer_group_name1, @test_topic1, @test_lags1},
{@test_consumer_group_name1, @test_topic2, @test_lags2},
{@test_consumer_group_name2, @test_topic3, @test_lags2}
]
end
defp lag(@test_topic1, _, _), do: @test_lags1
defp lag(_, _, _), do: @test_lags2
end