Added project schema feature
This commit is contained in:
71
test/validator_project_schema_test.go
Normal file
71
test/validator_project_schema_test.go
Normal file
@@ -0,0 +1,71 @@
|
||||
package integration
|
||||
|
||||
import (
|
||||
"os"
|
||||
"path/filepath"
|
||||
"strings"
|
||||
"testing"
|
||||
|
||||
"github.com/marte-dev/marte-dev-tools/internal/index"
|
||||
"github.com/marte-dev/marte-dev-tools/internal/parser"
|
||||
"github.com/marte-dev/marte-dev-tools/internal/validator"
|
||||
)
|
||||
|
||||
func TestProjectSpecificSchema(t *testing.T) {
|
||||
// Create temp dir
|
||||
tmpDir, err := os.MkdirTemp("", "mdt_test")
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
defer os.RemoveAll(tmpDir)
|
||||
|
||||
// Define project schema
|
||||
schemaContent := `
|
||||
{
|
||||
"classes": {
|
||||
"ProjectClass": {
|
||||
"fields": [
|
||||
{"name": "CustomField", "type": "int", "mandatory": true}
|
||||
]
|
||||
}
|
||||
}
|
||||
}
|
||||
`
|
||||
err = os.WriteFile(filepath.Join(tmpDir, ".marte_schema.json"), []byte(schemaContent), 0644)
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
|
||||
// Define MARTe file using ProjectClass
|
||||
marteContent := `
|
||||
+Obj = {
|
||||
Class = ProjectClass
|
||||
// Missing CustomField
|
||||
}
|
||||
`
|
||||
// We parse the content in memory, but we need the validator to look in tmpDir
|
||||
p := parser.NewParser(marteContent)
|
||||
config, err := p.Parse()
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
|
||||
idx := index.NewProjectTree()
|
||||
idx.AddFile("project.marte", config)
|
||||
|
||||
// Pass tmpDir as projectRoot
|
||||
v := validator.NewValidator(idx, tmpDir)
|
||||
v.ValidateProject()
|
||||
|
||||
found := false
|
||||
for _, d := range v.Diagnostics {
|
||||
if strings.Contains(d.Message, "Missing mandatory field 'CustomField'") {
|
||||
found = true
|
||||
break
|
||||
}
|
||||
}
|
||||
|
||||
if !found {
|
||||
t.Error("Expected error for missing 'CustomField' defined in project schema")
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user