-
Notifications
You must be signed in to change notification settings - Fork 61
/
Copy pathpostgres_test.go
61 lines (49 loc) · 1.63 KB
/
postgres_test.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
package pgvector
import (
"context"
"errors"
"io"
"strings"
"testing"
"gotest.tools/v3/assert"
)
func TestEnableInPostgreSQL(t *testing.T) {
expected := errors.New("whoops")
exec := func(
_ context.Context, stdin io.Reader, stdout, stderr io.Writer, command ...string,
) error {
assert.Assert(t, stdout != nil, "should capture stdout")
assert.Assert(t, stderr != nil, "should capture stderr")
assert.Assert(t, strings.Contains(strings.Join(command, "\n"),
`SELECT datname FROM pg_catalog.pg_database`,
), "expected all databases and templates")
b, err := io.ReadAll(stdin)
assert.NilError(t, err)
assert.Equal(t, string(b), strings.Trim(`
SET client_min_messages = WARNING; CREATE EXTENSION IF NOT EXISTS vector; ALTER EXTENSION vector UPDATE;
`, "\t\n"))
return expected
}
ctx := context.Background()
assert.Equal(t, expected, EnableInPostgreSQL(ctx, exec))
}
func TestDisableInPostgreSQL(t *testing.T) {
expected := errors.New("whoops")
exec := func(
_ context.Context, stdin io.Reader, stdout, stderr io.Writer, command ...string,
) error {
assert.Assert(t, stdout != nil, "should capture stdout")
assert.Assert(t, stderr != nil, "should capture stderr")
assert.Assert(t, strings.Contains(strings.Join(command, "\n"),
`SELECT datname FROM pg_catalog.pg_database`,
), "expected all databases and templates")
b, err := io.ReadAll(stdin)
assert.NilError(t, err)
assert.Equal(t, string(b), strings.Trim(`
SET client_min_messages = WARNING; DROP EXTENSION IF EXISTS vector;
`, "\t\n"))
return expected
}
ctx := context.Background()
assert.Equal(t, expected, DisableInPostgreSQL(ctx, exec))
}