Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

test: move HandlerHelpers tests to their module #480

Merged
merged 1 commit into from
Nov 13, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
47 changes: 0 additions & 47 deletions test/supavisor/client_handler_test.exs
Original file line number Diff line number Diff line change
@@ -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
52 changes: 50 additions & 2 deletions test/supavisor/handler_helpers_test.exs
Original file line number Diff line number Diff line change
@@ -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
Loading