escalus icon indicating copy to clipboard operation
escalus copied to clipboard

Elixir support?

Open brbrr opened this issue 8 years ago • 6 comments

Hi, Im new to erlang and elixir, so sorry for (maybe) obvious question.

Is it possible to use Escalus on elixir project? Im planning to write some tests for custom functionality in MongooseIM, but I prefer Elixir over Erlang because of the ruby like syntax etc.

Im kinda stuck on getting config file:

:application.set_env :escalus, :config_file, "test/test.config"
:escalus.create_users(:alice)
** (MatchError) no match of right hand side value: {:error, :enoent}

Escalus will look in to wrong dir(I insert erlang:display(Path) in to escalus_ct.erl:50): /Users/brbrr/Development/Vega/eliTests/_build/test/lib/escalus/test/test.config instead of /Users/brbrr/Development/Vega/eliTests/test/test.config

brbrr avatar Nov 16 '16 18:11 brbrr

Hi @brbrr,

Did you have a chance to read this [1] part of README file? Hope the information there will help you.

[1]. https://github.com/esl/escalus#escalus-as-a-standalone-application

michalwski avatar Nov 21 '16 10:11 michalwski

ok, thanks! I'll try to use it. btw, is it correct place to ask questions? So if im not using Common test, how can I pass config in to escalus? I need to define custom user_db module: {escalus_user_db, {module, custom_users, []}}.

brbrr avatar Nov 21 '16 10:11 brbrr

This is the right place to ask questions.

You can use function escalus_users:create_users/2 https://github.com/esl/escalus/blob/master/src/escalus_users.erl#L89. The first arg is list of opts where you can put your custom module for creating users.

Getting back to your initial problem. You basically would like to add a new test suite but write it in Elixir instead of Erlang?

michalwski avatar Nov 21 '16 11:11 michalwski

Yeah, I wanted to use Elixir to write some tests for custom mongoose server(custom registration, message delivery etc). I was thinking about Elixir just because im new for both elixir and erlang, and elixir looks kinda easier to get in to. But if I want to use custom modules - I need to use erlang...

So I started to use erlang, and make gears to spin a little, but now Im stuck on other problem. My registration process is OTP based, so password comes from server. I need to store these passwords, and update/modify CT config somehow for further use in story function. but im not sure how to do this.

brbrr avatar Nov 21 '16 12:11 brbrr

So I started to use erlang, and make gears to spin a little, but now Im stuck on other problem. My registration process is OTP based, so password comes from server. I need to store these passwords, and update/modify CT config somehow for further use in story function. but im not sure how to do this.

I think ets [1] will help you here. Just create an public, named ets table. Store the password there and read it later when you need.

[1]. http://erlang.org/doc/man/ets.html

michalwski avatar Nov 21 '16 12:11 michalwski

UPD: ah, its because init_per_group uses different process than test cases itself. was managed to workaround with: http://stackoverflow.com/a/15634582/3078381

Thanks! ets is working, but only when I use it inside same test case.

This will work:

messages_story_test(Config) ->
    escalus:create_users(Config), % inside my #create_user inserting passwords
    erlang:display(ets:tab2list(passwords)),
    escalus:story(Config, [{alice, 1}, {bob, 1}], fun(Alice, Bob) ->
......
end).

This wont:

init_per_group(_GroupName, Config) ->
    escalus:create_users(Config).

messages_story_test(Config) ->
    erlang:display(ets:tab2list(passwords)),
    escalus:story(Config, [{alice, 1}, {bob, 1}], fun(Alice, Bob) ->
    ......
end).

brbrr avatar Nov 23 '16 12:11 brbrr