epgsql_pool_SUITE.erl 1.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051
  1. -module(epgsql_pool_SUITE).
  2. %% test needs connection to database
  3. %% and database should be inited with ./testdb_schema.sql
  4. -include("epgsql_pool.hrl").
  5. -include_lib("common_test/include/ct.hrl").
  6. -export([all/0,
  7. init_per_suite/1, end_per_suite/1,
  8. init_per_testcase/2, end_per_testcase/2,
  9. test_1/1
  10. ]).
  11. all() -> [
  12. test_1
  13. ].
  14. init_per_suite(Config) ->
  15. application:ensure_all_started(epgsql_pool),
  16. Config.
  17. end_per_suite(Config) ->
  18. application:stop(epgsql_pool),
  19. Config.
  20. init_per_testcase(_, Config) ->
  21. Params = #epgsql_connection_params{host = "localhost", port = 5432, username = "test", password = "test", database = "testdb"},
  22. {ok, Connection} = epgsql_pool_utils:open_connection(Params),
  23. #epgsql_connection{connection_sock = Sock} = Connection,
  24. epgsql:equery(Sock, "TRUNCATE TABLE item"),
  25. epgsql:equery(Sock, "TRUNCATE TABLE category CASCADE"),
  26. [{connection, Connection}].
  27. end_per_testcase(_, Config) ->
  28. Connection = proplists:get_value(connection, Config),
  29. epgsql_pool_utils:close_connection(Connection),
  30. Config.
  31. test_1(Config) ->
  32. Connection = proplists:get_value(connection, Config),
  33. #epgsql_connection{connection_sock = Sock} = Connection,
  34. Res = epgsql:equery(Sock, "SELECT * FROM item"),
  35. ct:pal("Res:~p", [Res]),
  36. ok.