snapshot of https://github.com/sqlc-dev/sqlc.git (main, 2026-09-16; blobs > 131072B omitted)
Some checks failed
kotlin / test (push) Has been skipped
python / test (push) Has been skipped
typescript / test (push) Has been skipped
go / build darwin/amd64 (push) Has been cancelled
go / build linux/amd64 (push) Has been cancelled
go / build windows/amd64 (push) Has been cancelled
go / build darwin/arm64 (push) Has been cancelled
go / build linux/arm64 (push) Has been cancelled
go / build windows/arm64 (push) Has been cancelled
go / test (push) Has been cancelled
go / vuln_check (push) Has been cancelled
Some checks failed
kotlin / test (push) Has been skipped
python / test (push) Has been skipped
typescript / test (push) Has been skipped
go / build darwin/amd64 (push) Has been cancelled
go / build linux/amd64 (push) Has been cancelled
go / build windows/amd64 (push) Has been cancelled
go / build darwin/arm64 (push) Has been cancelled
go / build linux/arm64 (push) Has been cancelled
go / build windows/arm64 (push) Has been cancelled
go / test (push) Has been cancelled
go / vuln_check (push) Has been cancelled
This commit is contained in:
91
internal/config/config_test.go
Normal file
91
internal/config/config_test.go
Normal file
@@ -0,0 +1,91 @@
|
||||
package config
|
||||
|
||||
import (
|
||||
"strings"
|
||||
"testing"
|
||||
|
||||
"github.com/google/go-cmp/cmp"
|
||||
)
|
||||
|
||||
const missingVersion = `{
|
||||
}`
|
||||
|
||||
const missingPackages = `{
|
||||
"version": "1"
|
||||
}`
|
||||
|
||||
const unknownVersion = `{
|
||||
"version": "foo"
|
||||
}`
|
||||
|
||||
const unknownFields = `{
|
||||
"version": "1",
|
||||
"foo": "bar"
|
||||
}`
|
||||
|
||||
func TestBadConfigs(t *testing.T) {
|
||||
for _, test := range []struct {
|
||||
name string
|
||||
err string
|
||||
json string
|
||||
}{
|
||||
{
|
||||
"missing version",
|
||||
"no version number",
|
||||
missingVersion,
|
||||
},
|
||||
{
|
||||
"missing packages",
|
||||
"no packages",
|
||||
missingPackages,
|
||||
},
|
||||
{
|
||||
"unknown version",
|
||||
"invalid version number",
|
||||
unknownVersion,
|
||||
},
|
||||
{
|
||||
"unknown fields",
|
||||
`yaml: unmarshal errors:
|
||||
line 3: field foo not found in type config.V1GenerateSettings`,
|
||||
unknownFields,
|
||||
},
|
||||
} {
|
||||
tt := test
|
||||
t.Run(tt.name, func(t *testing.T) {
|
||||
_, err := ParseConfig(strings.NewReader(tt.json))
|
||||
if err == nil {
|
||||
t.Fatalf("expected err; got nil")
|
||||
}
|
||||
if diff := cmp.Diff(err.Error(), tt.err); diff != "" {
|
||||
t.Errorf("differed (-want +got):\n%s", diff)
|
||||
}
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
const validConfigOne = `{
|
||||
"version": "1"
|
||||
"packages": []
|
||||
}`
|
||||
|
||||
func FuzzConfig(f *testing.F) {
|
||||
f.Add(validConfigOne)
|
||||
f.Fuzz(func(t *testing.T, orig string) {
|
||||
ParseConfig(strings.NewReader(orig))
|
||||
})
|
||||
}
|
||||
|
||||
func TestInvalidConfig(t *testing.T) {
|
||||
err := Validate(&Config{
|
||||
SQL: []SQL{{
|
||||
Database: &Database{
|
||||
URI: "",
|
||||
Managed: false,
|
||||
},
|
||||
}},
|
||||
})
|
||||
if err == nil {
|
||||
t.Errorf("expected err; got nil")
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user