MCPcopy
hub / github.com/jackc/pgx / testLargeObjects

Function testLargeObjects

large_objects_test.go:66–162  ·  view source on GitHub ↗
(t *testing.T, ctx context.Context, tx pgx.Tx)

Source from the content-addressed store, hash-verified

64}
65
66func 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)

Callers 2

TestLargeObjectsFunction · 0.85

Calls 11

CreateMethod · 0.80
SeekMethod · 0.80
TellMethod · 0.80
TruncateMethod · 0.80
UnlinkMethod · 0.80
LargeObjectsMethod · 0.65
CloseMethod · 0.65
OpenMethod · 0.45
WriteMethod · 0.45
ReadMethod · 0.45
ErrorMethod · 0.45

Tested by

no test coverage detected