MCPcopy
hub / github.com/sqlc-dev/sqlc / TestExamplesVet

Function TestExamplesVet

internal/endtoend/vet_test.go:31–82  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

29}
30
31func TestExamplesVet(t *testing.T) {
32 t.Parallel()
33 ctx := context.Background()
34
35 examples, err := filepath.Abs(filepath.Join("..", "..", "examples"))
36 if err != nil {
37 t.Fatal(err)
38 }
39
40 files, err := os.ReadDir(examples)
41 if err != nil {
42 t.Fatal(err)
43 }
44
45 for _, replay := range files {
46 if !replay.IsDir() {
47 continue
48 }
49 tc := replay.Name()
50 t.Run(tc, func(t *testing.T) {
51 t.Parallel()
52 path := filepath.Join(examples, tc)
53
54 if tc != "kotlin" && tc != "python" {
55 if s, found := findSchema(t, filepath.Join(path, "sqlite")); found {
56 dsn := fmt.Sprintf("file:%s?mode=memory&cache=shared", tc)
57 db, cleanup := sqltest.CreateSQLiteDatabase(t, dsn, []string{s})
58 defer db.Close()
59 defer cleanup()
60 }
61 if s, found := findSchema(t, filepath.Join(path, "mysql")); found {
62 uri := local.MySQL(t, []string{s})
63 os.Setenv(fmt.Sprintf("VET_TEST_EXAMPLES_MYSQL_%s", strings.ToUpper(tc)), uri)
64 }
65 if s, found := findSchema(t, filepath.Join(path, "postgresql")); found {
66 uri := local.PostgreSQL(t, []string{s})
67 os.Setenv(fmt.Sprintf("VET_TEST_EXAMPLES_POSTGRES_%s", strings.ToUpper(tc)), uri)
68 }
69 }
70
71 var stderr bytes.Buffer
72 opts := &cmd.Options{
73 Stderr: &stderr,
74 Env: cmd.Env{},
75 }
76 err := cmd.Vet(ctx, path, "", opts)
77 if err != nil {
78 t.Fatalf("sqlc vet failed: %s %s", err, stderr.String())
79 }
80 })
81 }
82}

Callers

nothing calls this directly

Calls 10

CreateSQLiteDatabaseFunction · 0.92
MySQLFunction · 0.92
PostgreSQLFunction · 0.92
VetFunction · 0.92
findSchemaFunction · 0.85
AbsMethod · 0.80
NameMethod · 0.65
CloseMethod · 0.65
JoinMethod · 0.45
StringMethod · 0.45

Tested by

no test coverage detected