-
Notifications
You must be signed in to change notification settings - Fork 27
/
codegen_test.go
48 lines (44 loc) · 1.27 KB
/
codegen_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
package nested
import (
"github.com/jschaf/pggen"
"github.com/jschaf/pggen/internal/pgtest"
"github.com/stretchr/testify/assert"
"os"
"path/filepath"
"testing"
)
func TestGenerate_Go_Example_nested(t *testing.T) {
conn, cleanupFunc := pgtest.NewPostgresSchema(t, []string{"schema.sql"})
defer cleanupFunc()
tmpDir := t.TempDir()
err := pggen.Generate(
pggen.GenerateOptions{
ConnString: conn.Config().ConnString(),
QueryFiles: []string{"query.sql"},
OutputDir: tmpDir,
GoPackage: "nested",
Language: pggen.LangGo,
InlineParamCount: 2,
TypeOverrides: map[string]string{
"int4": "int",
"text": "string",
},
})
if err != nil {
t.Fatalf("Generate() example/nested: %s", err)
}
wantQueryFile := "query.sql.go"
gotQueryFile := filepath.Join(tmpDir, "query.sql.go")
assert.FileExists(t, gotQueryFile, "Generate() should emit query.sql.go")
wantQueries, err := os.ReadFile(wantQueryFile)
if err != nil {
t.Fatalf("read wanted query.go.sql: %s", err)
}
gotQueries, err := os.ReadFile(gotQueryFile)
if err != nil {
t.Fatalf("read generated query.go.sql: %s", err)
}
assert.Equalf(t, string(wantQueries), string(gotQueries),
"Got file %s; does not match contents of %s",
gotQueryFile, wantQueryFile)
}