package main import ( "path/filepath" "strings" "testing" ) func TestCheckSQLCUUIDOverridesFlagsStringTypes(t *testing.T) { root := t.TempDir() writeTestFile(t, filepath.Join(root, "sqlc.yaml"), `version: "2" sql: - engine: "postgresql" gen: go: overrides: - db_type: "uuid" go_type: "string" - db_type: "uuid" nullable: true go_type: type: "string" pointer: true `, 0644) violations := checkSQLCUUIDOverrides(root, true) if len(violations) != 2 { t.Fatalf("checkSQLCUUIDOverrides() returned %d violations, want 2: %#v", len(violations), violations) } rules := []string{violations[0].rule, violations[1].rule} if !strings.Contains(strings.Join(rules, ","), "sqlc-uuid-type") { t.Fatalf("rules = %#v, want sqlc-uuid-type", rules) } if !strings.Contains(strings.Join(rules, ","), "sqlc-null-uuid-type") { t.Fatalf("rules = %#v, want sqlc-null-uuid-type", rules) } } func TestCheckSQLCUUIDOverridesAllowsGoogleUUIDTypes(t *testing.T) { root := t.TempDir() writeTestFile(t, filepath.Join(root, "sqlc.yaml"), `version: "2" sql: - engine: "postgresql" gen: go: overrides: - db_type: "uuid" go_type: import: "github.com/google/uuid" type: "UUID" - db_type: "uuid" nullable: true go_type: import: "github.com/google/uuid" type: "NullUUID" `, 0644) violations := checkSQLCUUIDOverrides(root, true) if len(violations) != 0 { t.Fatalf("checkSQLCUUIDOverrides() returned %d violations, want 0: %#v", len(violations), violations) } } func TestFindSQLCConfigFilesIncludesRootAndCmdConfigs(t *testing.T) { root := t.TempDir() writeTestFile(t, filepath.Join(root, "sqlc.yaml"), `version: "2"`, 0644) writeTestFile(t, filepath.Join(root, "cmd", "tool", "sqlc.yaml"), `version: "2"`, 0644) writeTestFile(t, filepath.Join(root, "internal", "sqlc.yaml"), `version: "2"`, 0644) files := findSQLCConfigFiles(root, true) if len(files) != 2 { t.Fatalf("findSQLCConfigFiles() returned %d files, want 2: %#v", len(files), files) } }