-
-
Notifications
You must be signed in to change notification settings - Fork 57
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
test: move HandlerHelpers tests to their module (#480)
- Loading branch information
Showing
2 changed files
with
50 additions
and
49 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |