fix(jobs): preserve writer and template output options
This commit is contained in:
@@ -666,6 +666,7 @@ jobs:
|
||||
format: dbml
|
||||
template: templates/schema.tmpl
|
||||
output:
|
||||
format: text
|
||||
path: build/schema.txt
|
||||
overwrite: true
|
||||
`)
|
||||
@@ -682,3 +683,61 @@ jobs:
|
||||
t.Fatalf("templ output missing users table: %s", out)
|
||||
}
|
||||
}
|
||||
|
||||
func TestJobRun_BunSqlTypesOption(t *testing.T) {
|
||||
dir := jobFixture(t, `version: 1
|
||||
jobs:
|
||||
models:
|
||||
command: convert
|
||||
inputs:
|
||||
- path: schema/core.dbml
|
||||
format: dbml
|
||||
output:
|
||||
format: bun
|
||||
path: build/models
|
||||
options:
|
||||
package: models
|
||||
types: sqltypes
|
||||
`)
|
||||
set := mustLoadSet(t, filepath.Join(dir, "relspec.yml"))
|
||||
if err := executeJobPlan(set, "models", false, false, &bytes.Buffer{}); err != nil {
|
||||
t.Fatalf("execute Bun job: %v", err)
|
||||
}
|
||||
generated, err := os.ReadFile(filepath.Join(dir, "build", "models"))
|
||||
if err != nil {
|
||||
t.Fatalf("read Bun output: %v", err)
|
||||
}
|
||||
if !strings.Contains(string(generated), "git.warky.dev/wdevs/relspecgo/pkg/sqltypes") {
|
||||
t.Fatalf("Bun output did not preserve options.types: %s", generated)
|
||||
}
|
||||
}
|
||||
|
||||
func TestJobValidation_TemplTextFormat(t *testing.T) {
|
||||
validDir := jobFixture(t, `version: 1
|
||||
jobs:
|
||||
docs:
|
||||
command: templ
|
||||
inputs: [{path: schema/core.dbml, format: dbml}]
|
||||
template: schema.tmpl
|
||||
output: {format: text, path: build/docs.txt}
|
||||
`)
|
||||
valid := mustLoadSet(t, filepath.Join(validDir, "relspec.yml"))
|
||||
if err := valid.Validate(); err != nil {
|
||||
t.Fatalf("text output should be valid for templ: %v", err)
|
||||
}
|
||||
invalidDir := jobFixture(t, `version: 1
|
||||
jobs:
|
||||
docs:
|
||||
command: templ
|
||||
inputs: [{path: schema/core.dbml, format: dbml}]
|
||||
template: schema.tmpl
|
||||
output: {format: json, path: build/docs.txt}
|
||||
`)
|
||||
invalid, err := jobs.Load([]string{filepath.Join(invalidDir, "relspec.yml")})
|
||||
if err != nil {
|
||||
t.Fatalf("load invalid manifest: %v", err)
|
||||
}
|
||||
if err := invalid.Validate(); err == nil || !strings.Contains(err.Error(), "output.format: text") {
|
||||
t.Fatalf("expected templ format rejection, got %v", err)
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user