epgsql_copy_SUITE.erl 1.7 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859
  1. -module(epgsql_copy_SUITE).
  2. -include_lib("common_test/include/ct.hrl").
  3. -include_lib("stdlib/include/assert.hrl").
  4. -include("epgsql.hrl").
  5. -export([
  6. init_per_suite/1,
  7. all/0,
  8. end_per_suite/1,
  9. from_stdin_text/1
  10. ]).
  11. init_per_suite(Config) ->
  12. [{module, epgsql}|Config].
  13. end_per_suite(_Config) ->
  14. ok.
  15. all() ->
  16. [
  17. from_stdin_text%% ,
  18. %% from_stdin_csv,
  19. %% from_stdin_io_apis,
  20. %% from_stdin_fragmented,
  21. %% from_stdin_with_terminator,
  22. %% from_stdin_corrupt_data
  23. ].
  24. from_stdin_text(Config) ->
  25. Module = ?config(module, Config),
  26. epgsql_ct:with_connection(
  27. Config,
  28. fun(C) ->
  29. ?assertEqual(
  30. {ok, [text, text]},
  31. Module:copy_from_stdin(
  32. C, "COPY test_table1 (id, value) FROM STDIN WITH (FORMAT text)")),
  33. ?assertEqual(
  34. ok,
  35. io:put_chars(C,
  36. "10\thello world\n"
  37. "11\t\\N\n"
  38. "12\tline 12\n")),
  39. ?assertEqual(
  40. ok,
  41. io:put_chars(C, "13\tline 13\n")),
  42. ?assertEqual(
  43. {ok, 4},
  44. Module:copy_done(C)),
  45. ?assertMatch(
  46. {ok, _, [{10, <<"hello world">>},
  47. {11, null},
  48. {12, <<"line 12">>},
  49. {13, <<"line 13">>}]},
  50. Module:equery(C,
  51. "SELECT id, value FROM test_table1"
  52. " WHERE id IN (10, 11, 12, 13) ORDER BY id"))
  53. end).