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

Function TestJsonSchema

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

Source from the content-addressed store, hash-verified

31}
32
33func TestJsonSchema(t *testing.T) {
34 t.Parallel()
35
36 schemaOne := loadSchema(t, filepath.Join("..", "config", "v_one.json"))
37 schemaTwo := loadSchema(t, filepath.Join("..", "config", "v_two.json"))
38
39 srcs := []string{
40 filepath.Join("..", "..", "examples"),
41 filepath.Join("testdata"),
42 }
43
44 for _, dir := range srcs {
45 err := filepath.WalkDir(dir, func(path string, d fs.DirEntry, err error) error {
46 if err != nil {
47 return err
48 }
49 if filepath.Base(path) != "sqlc.json" {
50 return nil
51 }
52 t.Run(path, func(t *testing.T) {
53 t.Parallel()
54 contents, err := os.ReadFile(path)
55 if err != nil {
56 t.Fatal(err)
57 }
58 var c conf
59 if err := json.Unmarshal(contents, &c); err != nil {
60 t.Fatal(err)
61 }
62 l := gojsonschema.NewStringLoader(string(contents))
63 switch c.Version {
64 case "1":
65 if _, err := schemaOne.Validate(l); err != nil {
66 t.Fatal(err)
67 }
68 case "2":
69 if _, err := schemaTwo.Validate(l); err != nil {
70 t.Fatal(err)
71 }
72 default:
73 t.Fatalf("unknown schema version: %s", c.Version)
74 }
75 })
76 return nil
77 })
78 if err != nil {
79 t.Error(err)
80 }
81 }
82}

Callers

nothing calls this directly

Calls 4

loadSchemaFunction · 0.85
JoinMethod · 0.45
ValidateMethod · 0.45
ErrorMethod · 0.45

Tested by

no test coverage detected