epgsql_pool_SUITE.erl 2.0 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374
  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, init_per_testcase/2, end_per_testcase/2,
  8. start_test/1, stop_test/1, equery_test/1, transaction_test/1, reconnect_test/1
  9. ]).
  10. all() ->
  11. [start_test,
  12. stop_test,
  13. equery_test,
  14. transaction_test,
  15. reconnect_test
  16. ].
  17. init_per_suite(Config) ->
  18. application:ensure_all_started(epgsql_pool),
  19. Config.
  20. end_per_suite(Config) ->
  21. application:stop(epgsql_pool),
  22. Config.
  23. init_per_testcase(_, Config) ->
  24. Params = #epgsql_connection_params{host = "localhost", port = 5432, username = "test", password = "test", database = "testdb"},
  25. {ok, Connection} = epgsql_pool_utils:open_connection(Params),
  26. #epgsql_connection{connection_sock = Sock} = Connection,
  27. epgsql:equery(Sock, "TRUNCATE TABLE item"),
  28. epgsql:equery(Sock, "TRUNCATE TABLE category CASCADE"),
  29. [{connection, Connection} | proplists:delete(connection, Config)].
  30. end_per_testcase(_, Config) ->
  31. Connection = proplists:get_value(connection, Config),
  32. Connection2 = epgsql_pool_utils:close_connection(Connection),
  33. #epgsql_connection{connection_sock = undefined} = Connection2,
  34. [{connection, Connection2} | proplists:delete(connection, Config)].
  35. start_test(Config) ->
  36. ok.
  37. stop_test(Config) ->
  38. ok.
  39. equery_test(Config) ->
  40. Connection = proplists:get_value(connection, Config),
  41. #epgsql_connection{connection_sock = Sock} = Connection,
  42. Res = epgsql:equery(Sock, "SELECT * FROM item"), % TODO epgsql_pool:equery, after start
  43. ct:pal("Res:~p", [Res]),
  44. ok.
  45. transaction_test(Config) ->
  46. Connection = proplists:get_value(connection, Config),
  47. #epgsql_connection{connection_sock = Sock} = Connection,
  48. Res = epgsql:equery(Sock, "SELECT * FROM category"), % TODO epgsql_pool:transaction
  49. ct:pal("Res:~p", [Res]),
  50. ok.
  51. reconnect_test(Config) ->
  52. ok.