@@ -13,6 +13,24 @@ defmodule PgLargeObjects.RepoTest do
1313
1414 assert data == get_large_object! ( oid )
1515 end
16+
17+ test "can import from enumerable" do
18+ data = :crypto . strong_rand_bytes ( Enum . random ( 0 .. 1024 ) )
19+
20+ { :ok , pid } = StringIO . open ( data , encoding: :latin1 )
21+
22+ stream = IO . binstream ( pid , 3 )
23+
24+ { :ok , oid } =
25+ TestRepo . transaction ( fn ->
26+ { :ok , oid } = TestRepo . import_large_object ( stream )
27+ oid
28+ end )
29+
30+ assert data == get_large_object! ( oid )
31+
32+ { :ok , _output } = StringIO . close ( pid )
33+ end
1634 end
1735
1836 describe "export_large_object/1" do
@@ -27,5 +45,20 @@ defmodule PgLargeObjects.RepoTest do
2745 data
2846 end )
2947 end
48+
49+ test "can export data to collectable" do
50+ data = :crypto . strong_rand_bytes ( Enum . random ( 0 .. 1024 ) )
51+
52+ oid = put_large_object! ( data )
53+
54+ { :ok , pid } = StringIO . open ( "" , encoding: :latin1 )
55+ stream = IO . binstream ( pid , 3 )
56+
57+ TestRepo . transaction ( fn ->
58+ assert :ok == TestRepo . export_large_object ( oid , into: stream )
59+ end )
60+
61+ assert { "" , ^ data } = StringIO . contents ( pid )
62+ end
3063 end
3164end
0 commit comments