MCPcopy Create free account
hub / github.com/CrunchyData/postgres-operator / TestExecutorExec

Function TestExecutorExec

internal/postgres/exec_test.go:34–67  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

32}
33
34func TestExecutorExec(t *testing.T) {
35 expected := errors.New("pass-through")
36 fn := func(
37 _ context.Context, stdin io.Reader, stdout, stderr io.Writer, command ...string,
38 ) error {
39 b, err := io.ReadAll(stdin)
40 assert.NilError(t, err)
41 assert.Equal(t, string(b), `statements; to run;`)
42
43 assert.DeepEqual(t, command, []string{
44 "psql", "-Xw", "--file=-",
45 "--set=CASE=sEnSiTiVe",
46 "--set=different=vars",
47 "--set=lots=of",
48 })
49
50 _, _ = io.WriteString(stdout, "some stdout")
51 _, _ = io.WriteString(stderr, "and stderr")
52 return expected
53 }
54
55 stdout, stderr, err := Executor(fn).Exec(
56 context.Background(),
57 strings.NewReader(`statements; to run;`),
58 map[string]string{
59 "lots": "of",
60 "different": "vars",
61 "CASE": "sEnSiTiVe",
62 })
63
64 assert.Equal(t, expected, err, "expected function to be called")
65 assert.Equal(t, stdout, "some stdout")
66 assert.Equal(t, stderr, "and stderr")
67}
68
69func TestExecutorExecInAllDatabases(t *testing.T) {
70 expected := errors.New("exact")

Callers

nothing calls this directly

Calls 3

ExecutorFuncType · 0.70
EqualMethod · 0.45
ExecMethod · 0.45

Tested by

no test coverage detected