test: make schema test happy

This commit is contained in:
Zhongwen Deng 2023-03-13 14:33:51 +08:00
parent 5be4d97c42
commit ee2847dcd9
4 changed files with 8 additions and 7 deletions

View File

@ -2664,7 +2664,7 @@ servers_validator(Opts, Required) ->
case str(Str0) of case str(Str0) of
"" -> "" ->
%% Empty string is not allowed even if the field is not required %% Empty string is not allowed even if the field is not required
%% remove field from config if it's empty %% we should remove field from config if it's empty
throw("cannot_be_empty"); throw("cannot_be_empty");
"undefined" when Required -> "undefined" when Required ->
%% when the filed is not set in config file %% when the filed is not set in config file

View File

@ -1243,8 +1243,8 @@ session(InitFields) when is_map(InitFields) ->
), ),
Session = emqx_session:init(Conf), Session = emqx_session:init(Conf),
maps:fold( maps:fold(
fun(Field, Value, Session) -> fun(Field, Value, SessionAcc) ->
emqx_session:set_field(Field, Value, Session) emqx_session:set_field(Field, Value, SessionAcc)
end, end,
Session, Session,
InitFields InitFields

View File

@ -455,10 +455,11 @@ servers_validator_test() ->
NotRequired = emqx_schema:servers_validator(#{}, false), NotRequired = emqx_schema:servers_validator(#{}, false),
?assertThrow("cannot_be_empty", Required("")), ?assertThrow("cannot_be_empty", Required("")),
?assertThrow("cannot_be_empty", Required(<<>>)), ?assertThrow("cannot_be_empty", Required(<<>>)),
?assertThrow("cannot_be_empty", NotRequired("")),
?assertThrow("cannot_be_empty", NotRequired(<<>>)),
?assertThrow("cannot_be_empty", Required(undefined)), ?assertThrow("cannot_be_empty", Required(undefined)),
?assertEqual(ok, NotRequired("")),
?assertEqual(ok, NotRequired(<<>>)),
?assertEqual(ok, NotRequired(undefined)), ?assertEqual(ok, NotRequired(undefined)),
?assertEqual(ok, NotRequired("undefined")),
ok. ok.
converter_invalid_input_test() -> converter_invalid_input_test() ->

View File

@ -471,8 +471,8 @@ session(InitFields) when is_map(InitFields) ->
), ),
Session = emqx_session:init(Conf), Session = emqx_session:init(Conf),
maps:fold( maps:fold(
fun(Field, Value, Session) -> fun(Field, Value, SessionAcc) ->
emqx_session:set_field(Field, Value, Session) emqx_session:set_field(Field, Value, SessionAcc)
end, end,
Session, Session,
InitFields InitFields