Skip to content

Commit

Permalink
Add more tests to cover error cases
Browse files Browse the repository at this point in the history
  • Loading branch information
chrzaszcz committed Nov 14, 2022
1 parent 3a00cce commit ce0c961
Show file tree
Hide file tree
Showing 2 changed files with 37 additions and 7 deletions.
30 changes: 26 additions & 4 deletions big_tests/tests/graphql_domain_SUITE.erl
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@

-import(distributed_helper, [mim/0, require_rpc_nodes/1, rpc/4]).
-import(graphql_helper, [execute_command/4, get_ok_value/2, get_err_msg/1, skip_null_fields/1,
execute_domain_admin_command/4, get_unauthorized/1]).
execute_domain_admin_command/4, get_unauthorized/1, get_coercion_err_msg/1]).

-define(HOST_TYPE, <<"dummy auth">>).
-define(SECOND_HOST_TYPE, <<"test type">>).
Expand Down Expand Up @@ -36,6 +36,7 @@ domain_tests() ->
domain_not_found_error_formatting_after_mutation_enable_domain,
domain_not_found_error_formatting_after_query,
wrong_host_type_error_formatting,
invalid_domain_name_error,
disable_domain,
enable_domain,
get_domains_by_host_type,
Expand All @@ -45,7 +46,8 @@ domain_tests() ->
get_domains_after_deletion,
set_domain_password,
set_nonexistent_domain_password,
delete_domain_password
delete_domain_password,
delete_nonexistent_domain_password
].

domain_admin_tests() ->
Expand Down Expand Up @@ -110,7 +112,9 @@ unknown_host_type_error_formatting(Config) ->
DomainName = ?EXAMPLE_DOMAIN,
HostType = <<"NonExistingHostType">>,
Result = add_domain(DomainName, HostType, Config),
?assertEqual(<<"Unknown host type">>, get_err_msg(Result)).
?assertEqual(<<"Unknown host type">>, get_err_msg(Result)),
Result2 = get_domains_by_host_type(HostType, Config),
?assertEqual(<<"Unknown host type">>, get_err_msg(Result2)).

static_domain_error_formatting(Config) ->
DomainName = <<"localhost">>,
Expand Down Expand Up @@ -141,6 +145,14 @@ wrong_host_type_error_formatting(Config) ->
Result = remove_domain(?EXAMPLE_DOMAIN, ?SECOND_HOST_TYPE, Config),
?assertEqual(<<"Wrong host type was provided">>, get_err_msg(Result)).

invalid_domain_name_error(Config) ->
%% One operation tested, because they all use the DomainName type
Result1 = add_domain(<<>>, ?HOST_TYPE, Config),
get_coercion_err_msg(Result1),
TooLong = binary:copy(<<$a>>, 1024),
Result2 = add_domain(TooLong, ?HOST_TYPE, Config),
get_coercion_err_msg(Result2).

disable_domain(Config) ->
Result = disable_domain(?EXAMPLE_DOMAIN, Config),
ParsedResult = get_ok_value([data, domain, disableDomain], Result),
Expand Down Expand Up @@ -209,7 +221,14 @@ set_nonexistent_domain_password(Config) ->
delete_domain_password(Config) ->
Result = delete_domain_password(domain_helper:domain(), Config),
ParsedResult = get_ok_value([data, domain, deleteDomainPassword], Result),
?assertNotEqual(nomatch, binary:match(ParsedResult, <<"successfully">>)).
?assertNotEqual(nomatch, binary:match(ParsedResult, <<"successfully">>)),
Result2 = delete_domain_password(domain_helper:domain(), Config),
domain_password_not_found_error_formatting(Result2).

delete_nonexistent_domain_password(Config) ->
Domain = <<"unknown-domain.com">>,
Result = delete_domain_password(Domain, Config),
domain_password_not_found_error_formatting(Result).

domain_admin_get_domain_details(Config) ->
Result = get_domain_details(?DOMAIN_ADMIN_EXAMPLE_DOMAIN, Config),
Expand Down Expand Up @@ -297,3 +316,6 @@ delete_domain_password(Domain, Config) ->

domain_not_found_error_formatting(Result) ->
?assertMatch(<<"Given domain does not exist", _/binary>>, get_err_msg(Result)).

domain_password_not_found_error_formatting(Result) ->
?assertEqual(<<"Domain password does not exist">>, get_err_msg(Result)).
14 changes: 11 additions & 3 deletions big_tests/tests/service_domain_db_SUITE.erl
Original file line number Diff line number Diff line change
Expand Up @@ -147,6 +147,7 @@ rest_cases() ->
rest_can_enable_domain,
rest_can_select_domain,
rest_cannot_select_domain_if_domain_not_found,
rest_cannot_select_domain_when_it_is_static,
rest_cannot_put_domain_without_host_type,
rest_cannot_put_domain_without_body,
rest_cannot_put_domain_with_invalid_json,
Expand Down Expand Up @@ -874,7 +875,9 @@ rest_cannot_delete_domain_without_correct_type(Config) ->

rest_cannot_delete_missing_domain(Config) ->
{{<<"404">>, <<"Not Found">>}, <<"Given domain does not exist">>} =
rest_delete_domain(Config, <<"example.db">>, <<"type1">>).
rest_delete_domain(Config, <<"example.db">>, <<"type1">>),
{{<<"404">>, <<"Not Found">>}, <<"Given domain does not exist">>} =
domain_rest_helper:request_delete_domain(Config, <<"example.db">>, <<"type1">>).

rest_cannot_enable_missing_domain(Config) ->
{{<<"404">>, <<"Not Found">>}, <<"Given domain does not exist">>} =
Expand Down Expand Up @@ -956,7 +959,6 @@ rest_cannot_select_domain_without_auth(Config) ->
{{<<"401">>, <<"Unauthorized">>}, _} =
rest_select_domain(set_no_creds(Config), <<"example.db">>).


rest_cannot_disable_missing_domain(Config) ->
{{<<"404">>, <<"Not Found">>}, <<"Given domain does not exist">>} =
rest_patch_enabled(Config, <<"example.db">>, false).
Expand All @@ -978,6 +980,10 @@ rest_cannot_select_domain_if_domain_not_found(Config) ->
{{<<"404">>, <<"Not Found">>}, <<"Given domain does not exist">>} =
rest_select_domain(Config, <<"example.db">>).

rest_cannot_select_domain_when_it_is_static(Config) ->
{{<<"403">>, <<"Forbidden">>}, <<"Domain is static">>} =
rest_select_domain(Config, <<"example.cfg">>).

rest_cannot_put_domain_without_host_type(Config) ->
{{<<"400">>, <<"Bad Request">>}, <<"'host_type' field is missing">>} =
putt_domain_with_custom_body(Config, #{}).
Expand Down Expand Up @@ -1012,7 +1018,9 @@ rest_cannot_delete_domain_with_invalid_json(Config) ->

rest_cannot_delete_domain_when_it_is_static(Config) ->
{{<<"403">>, <<"Forbidden">>}, <<"Domain is static">>} =
rest_delete_domain(Config, <<"example.cfg">>, <<"type1">>).
rest_delete_domain(Config, <<"example.cfg">>, <<"type1">>),
{{<<"403">>, <<"Forbidden">>}, <<"Domain is static">>} =
domain_rest_helper:request_delete_domain(Config, <<"example.cfg">>, <<"type1">>).

rest_cannot_patch_domain_without_enabled_field(Config) ->
{{<<"400">>, <<"Bad Request">>}, <<"'enabled' field is missing">>} =
Expand Down

0 comments on commit ce0c961

Please sign in to comment.