From 62b642aa9f7736bd18d2bf10974806550fbdca97 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=C5=81ukasz=20Jan=20Niemier?= Date: Wed, 13 Nov 2024 15:00:37 +0100 Subject: [PATCH] test: move HandlerHelpers tests to their module (#480) --- test/supavisor/client_handler_test.exs | 47 ---------------------- test/supavisor/handler_helpers_test.exs | 52 ++++++++++++++++++++++++- 2 files changed, 50 insertions(+), 49 deletions(-) diff --git a/test/supavisor/client_handler_test.exs b/test/supavisor/client_handler_test.exs index 86314d18..37de47db 100644 --- a/test/supavisor/client_handler_test.exs +++ b/test/supavisor/client_handler_test.exs @@ -1,50 +1,3 @@ defmodule Supavisor.ClientHandlerTest do use ExUnit.Case, async: true - - alias Supavisor.HandlerHelpers, as: HH - - describe "parse_user_info/1" do - test "extracts the external_id from the username" do - payload = %{"user" => "test.user.external_id"} - {:single, {name, external_id, nil}} = HH.parse_user_info(payload) - assert name == "test.user" - assert external_id == "external_id" - end - - test "username consists only of username" do - username = "username" - payload = %{"user" => username} - {:single, {user, nil, nil}} = HH.parse_user_info(payload) - assert username == user - end - - test "consist cluster" do - username = "some.user.cluster.alias" - {t, {u, a, nil}} = HH.parse_user_info(%{"user" => username}) - assert {t, {u, a, nil}} == {:cluster, {"some.user", "alias", nil}} - end - - test "external_id in options" do - user = "test.user" - external_id = "external_id" - payload = %{"options" => %{"reference" => external_id}, "user" => user} - {:single, {user1, external_id1, nil}} = HH.parse_user_info(payload) - assert user1 == user - assert external_id1 == external_id - end - - test "unicode in username" do - payload = %{"user" => "тестовe.імʼя.external_id"} - {:single, {name, external_id, nil}} = HH.parse_user_info(payload) - assert name == "тестовe.імʼя" - assert external_id == "external_id" - end - - test "extracts db_name" do - payload = %{"user" => "user", "database" => "postgres_test"} - {:single, {name, nil, db_name}} = HH.parse_user_info(payload) - assert name == "user" - assert db_name == "postgres_test" - end - end end diff --git a/test/supavisor/handler_helpers_test.exs b/test/supavisor/handler_helpers_test.exs index 28a3512b..e1a1e090 100644 --- a/test/supavisor/handler_helpers_test.exs +++ b/test/supavisor/handler_helpers_test.exs @@ -1,4 +1,52 @@ defmodule Supavisor.HandlerHelpersTest do - use ExUnit.Case - doctest Supavisor.HandlerHelpers + use ExUnit.Case, async: true + + @subject Supavisor.HandlerHelpers + + doctest @subject + + describe "parse_user_info/1" do + test "extracts the external_id from the username" do + payload = %{"user" => "test.user.external_id"} + {:single, {name, external_id, nil}} = @subject.parse_user_info(payload) + assert name == "test.user" + assert external_id == "external_id" + end + + test "username consists only of username" do + username = "username" + payload = %{"user" => username} + {:single, {user, nil, nil}} = @subject.parse_user_info(payload) + assert username == user + end + + test "consist cluster" do + username = "some.user.cluster.alias" + {t, {u, a, nil}} = @subject.parse_user_info(%{"user" => username}) + assert {t, {u, a, nil}} == {:cluster, {"some.user", "alias", nil}} + end + + test "external_id in options" do + user = "test.user" + external_id = "external_id" + payload = %{"options" => %{"reference" => external_id}, "user" => user} + {:single, {user1, external_id1, nil}} = @subject.parse_user_info(payload) + assert user1 == user + assert external_id1 == external_id + end + + test "unicode in username" do + payload = %{"user" => "тестовe.імʼя.external_id"} + {:single, {name, external_id, nil}} = @subject.parse_user_info(payload) + assert name == "тестовe.імʼя" + assert external_id == "external_id" + end + + test "extracts db_name" do + payload = %{"user" => "user", "database" => "postgres_test"} + {:single, {name, nil, db_name}} = @subject.parse_user_info(payload) + assert name == "user" + assert db_name == "postgres_test" + end + end end