Compare commits

..

2 Commits

Author SHA1 Message Date
29c032cb16 Add license 2024-06-01 12:02:18 +02:00
a34e91770f Simplify test code 2024-04-16 22:33:28 +02:00
3 changed files with 37 additions and 46 deletions

12
LICENSE Normal file
View File

@@ -0,0 +1,12 @@
ISC License
Copyright 2024 Pascal Schmid
Permission to use, copy, modify, and/or distribute this software for any purpose with or without fee is hereby
granted, provided that the above copyright notice and this permission notice appear in all copies.
THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE INCLUDING ALL
IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT,
INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE
OF THIS SOFTWARE.

View File

@@ -40,9 +40,7 @@ defmodule KafkaexLagExporter.ConsumerOffsetFetcher.Test do
end end
test "should return the calculated lags" do test "should return the calculated lags" do
test_endpoint = {"test endpoint", 666} %{sum: sum, lags: lags} = KafkaexLagExporter.ConsumerOffsetFetcher.get({"test endpoint", 666})
%{sum: sum, lags: lags} = KafkaexLagExporter.ConsumerOffsetFetcher.get(test_endpoint)
assert sum == [ assert sum == [
%ConsumerOffset{ %ConsumerOffset{

View File

@@ -5,9 +5,7 @@ defmodule KafkaexLagExporter.KafkaUtils.Test do
alias KafkaexLagExporter.KafkaWrapper.Behaviour, as: KafkaWrapper alias KafkaexLagExporter.KafkaWrapper.Behaviour, as: KafkaWrapper
alias KafkaexLagExporter.KafkaUtils alias KafkaexLagExporter.KafkaUtils
@test_host "test_host" @test_endpoint {"test_host", "1234"}
@test_port "1234"
@test_endpoint {@test_host, @test_port}
@test_sock_opts [ssl: []] @test_sock_opts [ssl: []]
@test_group_name1 "test-consumer_group1" @test_group_name1 "test-consumer_group1"
@test_group_name2 "test-consumer_group" @test_group_name2 "test-consumer_group"
@@ -28,18 +26,9 @@ defmodule KafkaexLagExporter.KafkaUtils.Test do
consumer_info1 = {:a, @test_group_name1, "consumer"} consumer_info1 = {:a, @test_group_name1, "consumer"}
consumer_info2 = {:b, @test_group_name2, "something-other"} consumer_info2 = {:b, @test_group_name2, "something-other"}
patch( patch(KafkaWrapper, :list_all_groups, fn _, _ ->
KafkaWrapper, [{@test_endpoint, [consumer_info1, consumer_info2]}]
:list_all_groups, end)
fn _, _ ->
[
{
@test_endpoint,
[consumer_info1, consumer_info2]
}
]
end
)
group_names = KafkaUtils.get_consumer_group_names(@test_endpoint) group_names = KafkaUtils.get_consumer_group_names(@test_endpoint)
@@ -63,27 +52,23 @@ defmodule KafkaexLagExporter.KafkaUtils.Test do
consumer_id = "test_consumer_id" consumer_id = "test_consumer_id"
member_host = "test_member_host" member_host = "test_member_host"
patch( patch(KafkaWrapper, :describe_groups, fn _, _, _ ->
KafkaWrapper, {
:describe_groups, :ok,
fn _, _, _ -> [
{ %{
:ok, group_id: consumer_group_name,
[ members: [
%{ %{
group_id: consumer_group_name, client_host: member_host,
members: [ member_assignment: member_assignment,
%{ member_id: consumer_id
client_host: member_host, }
member_assignment: member_assignment, ]
member_id: consumer_id }
} ]
] }
} end)
]
}
end
)
patch(KafkaexLagExporter.TopicNameParser, :parse_topic_names, fn _ -> [@test_topic_name] end) patch(KafkaexLagExporter.TopicNameParser, :parse_topic_names, fn _ -> [@test_topic_name] end)
@@ -147,13 +132,9 @@ defmodule KafkaexLagExporter.KafkaUtils.Test do
patch(KafkaWrapper, :resolve_offset, fn _, _, _, _, _ -> {:ok, resolved_offset} end) patch(KafkaWrapper, :resolve_offset, fn _, _, _, _, _ -> {:ok, resolved_offset} end)
patch( patch(KafkaWrapper, :fetch_committed_offsets, fn _, _, _ ->
KafkaWrapper, {:ok, [%{name: "test name", partitions: [partition_info1, partition_info2]}]}
:fetch_committed_offsets, end)
fn _, _, _ ->
{:ok, [%{name: "test name", partitions: [partition_info1, partition_info2]}]}
end
)
lag = KafkaUtils.lag(@test_topic_name, consumer_group, client) lag = KafkaUtils.lag(@test_topic_name, consumer_group, client)