| 64 | } |
| 65 | |
| 66 | func testLargeObjects(t *testing.T, ctx context.Context, tx pgx.Tx) { |
| 67 | lo := tx.LargeObjects() |
| 68 | |
| 69 | id, err := lo.Create(ctx, 0) |
| 70 | if err != nil { |
| 71 | t.Fatal(err) |
| 72 | } |
| 73 | |
| 74 | obj, err := lo.Open(ctx, id, pgx.LargeObjectModeRead|pgx.LargeObjectModeWrite) |
| 75 | if err != nil { |
| 76 | t.Fatal(err) |
| 77 | } |
| 78 | |
| 79 | n, err := obj.Write([]byte("testing")) |
| 80 | if err != nil { |
| 81 | t.Fatal(err) |
| 82 | } |
| 83 | if n != 7 { |
| 84 | t.Errorf("Expected n to be 7, got %d", n) |
| 85 | } |
| 86 | |
| 87 | pos, err := obj.Seek(1, 0) |
| 88 | if err != nil { |
| 89 | t.Fatal(err) |
| 90 | } |
| 91 | if pos != 1 { |
| 92 | t.Errorf("Expected pos to be 1, got %d", pos) |
| 93 | } |
| 94 | |
| 95 | res := make([]byte, 6) |
| 96 | n, err = obj.Read(res) |
| 97 | if err != nil { |
| 98 | t.Fatal(err) |
| 99 | } |
| 100 | if string(res) != "esting" { |
| 101 | t.Errorf(`Expected res to be "esting", got %q`, res) |
| 102 | } |
| 103 | if n != 6 { |
| 104 | t.Errorf("Expected n to be 6, got %d", n) |
| 105 | } |
| 106 | |
| 107 | n, err = obj.Read(res) |
| 108 | if err != io.EOF { |
| 109 | t.Error("Expected io.EOF, go nil") |
| 110 | } |
| 111 | if n != 0 { |
| 112 | t.Errorf("Expected n to be 0, got %d", n) |
| 113 | } |
| 114 | |
| 115 | pos, err = obj.Tell() |
| 116 | if err != nil { |
| 117 | t.Fatal(err) |
| 118 | } |
| 119 | if pos != 7 { |
| 120 | t.Errorf("Expected pos to be 7, got %d", pos) |
| 121 | } |
| 122 | |
| 123 | err = obj.Truncate(1) |