Add strict custom field registry
This commit is contained in:
@@ -212,6 +212,74 @@ scan:
|
||||
}
|
||||
}
|
||||
|
||||
func TestValidateCustomFieldsStrict(t *testing.T) {
|
||||
root := t.TempDir()
|
||||
design := filepath.Join(root, "design")
|
||||
if err := os.MkdirAll(design, 0755); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
writeTestFile(t, root, "gsp.manifest", `gspVersion: 0.1
|
||||
customFieldPolicy: strict
|
||||
fieldRegistry: gsp.fields
|
||||
scan:
|
||||
- design
|
||||
`)
|
||||
writeTestFile(t, root, "gsp.fields", `gspFieldsVersion: 0.1
|
||||
fields:
|
||||
rewardTier:
|
||||
type: string
|
||||
allowed:
|
||||
- common
|
||||
- rare
|
||||
scope:
|
||||
type:
|
||||
- mechanic
|
||||
`)
|
||||
writeTestFile(t, design, "mechanic.gsp", `id: mechanic.sample
|
||||
type: mechanic
|
||||
rewardTier: rare
|
||||
`)
|
||||
project, err := LoadProject(root)
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
report := project.Validate("")
|
||||
if !report.OK {
|
||||
t.Fatalf("expected custom field to validate, got %+v", report.Errors)
|
||||
}
|
||||
}
|
||||
|
||||
func TestValidateUnknownCustomFieldFails(t *testing.T) {
|
||||
root := t.TempDir()
|
||||
design := filepath.Join(root, "design")
|
||||
if err := os.MkdirAll(design, 0755); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
writeTestFile(t, root, "gsp.manifest", `gspVersion: 0.1
|
||||
customFieldPolicy: strict
|
||||
fieldRegistry: gsp.fields
|
||||
scan:
|
||||
- design
|
||||
`)
|
||||
writeTestFile(t, root, "gsp.fields", `gspFieldsVersion: 0.1
|
||||
fields: {}
|
||||
`)
|
||||
writeTestFile(t, design, "page.gsp", `id: page.sample
|
||||
unknownMood: exciting
|
||||
`)
|
||||
project, err := LoadProject(root)
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
report := project.Validate("")
|
||||
if report.OK {
|
||||
t.Fatal("expected unknown custom field failure")
|
||||
}
|
||||
if report.Errors[0].Code != "unknown_custom_field" {
|
||||
t.Fatalf("expected unknown_custom_field, got %+v", report.Errors)
|
||||
}
|
||||
}
|
||||
|
||||
func TestInitProjectCreatesManifestAndEntry(t *testing.T) {
|
||||
root := filepath.Join(t.TempDir(), "sample-project")
|
||||
result, err := InitProject(root, InitOptions{
|
||||
@@ -240,6 +308,9 @@ func TestInitProjectCreatesManifestAndEntry(t *testing.T) {
|
||||
if _, ok := project.ByID["page.sample.main"]; !ok {
|
||||
t.Fatal("expected initialized entry GSP")
|
||||
}
|
||||
if _, err := os.Stat(filepath.Join(root, "gsp.fields")); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
report := project.Validate("")
|
||||
if !report.OK {
|
||||
t.Fatalf("expected valid initialized project, got %+v", report.Errors)
|
||||
|
||||
Reference in New Issue
Block a user