forked from jschaf/pggen
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcodegen_test.go
45 lines (40 loc) · 1.2 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
package enums
import (
"os"
"path/filepath"
"testing"
"github.com/mypricehealth/pggen"
"github.com/mypricehealth/pggen/internal/pgtest"
"github.com/stretchr/testify/assert"
)
func TestGenerate_Go_Example_Enums(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: "enums",
Language: pggen.LangGo,
InlineParamCount: 2,
})
if err != nil {
t.Fatalf("Generate() example/enums: %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)
}