Verify catalog and Audita compatibility offline
This commit is contained in:
@@ -2,6 +2,7 @@ package glossary
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"path/filepath"
|
||||
"sort"
|
||||
|
||||
configkit "go.maximumdirect.net/configkit"
|
||||
@@ -81,7 +82,14 @@ func resolveCollection(name, path string, inline map[string]any) (any, error) {
|
||||
underlays = append(underlays, configkit.Underlay{Inputs: []configkit.Input{{Source: empty}}})
|
||||
}
|
||||
if path != "" {
|
||||
file := configkit.Input{Source: configkit.File(path), Imports: true}
|
||||
absolute, err := filepath.Abs(path)
|
||||
if err != nil {
|
||||
return nil, fmt.Errorf("resolve %s vocabulary path %q: %w", name, path, err)
|
||||
}
|
||||
// Vocabulary files may import sibling fragments relative to their own
|
||||
// locations; let ConfigKit resolve those imports in the host filesystem.
|
||||
root := filepath.VolumeName(absolute) + string(filepath.Separator)
|
||||
file := configkit.Input{Source: configkit.File(absolute), Imports: true, Filesystem: &configkit.FilesystemContext{Root: root}}
|
||||
loaded, err := configkit.LoadLayered(file, configkit.LayeredOptions[map[string]any]{Definition: definition})
|
||||
if err != nil {
|
||||
return nil, fmt.Errorf("load %s vocabulary %q: %w", name, path, err)
|
||||
|
||||
@@ -81,3 +81,26 @@ func TestResolveHandlesInheritancePartialAndFailures(t *testing.T) {
|
||||
t.Fatal("missing file accepted")
|
||||
}
|
||||
}
|
||||
|
||||
func TestResolveImportsSiblingVocabularyFragments(t *testing.T) {
|
||||
dir := t.TempDir()
|
||||
for name, content := range map[string]string{
|
||||
"settings/coast.yml": "config:\n imports: [{path: ../fragments/places.yml}]\nsetting: {entries: [{id: coast, name: Coast, category: place}]}\n",
|
||||
"fragments/places.yml": "setting: {entries: [{id: harbor, name: Harbor, category: place}]}\n",
|
||||
} {
|
||||
path := filepath.Join(dir, name)
|
||||
if err := os.MkdirAll(filepath.Dir(path), 0755); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
if err := os.WriteFile(path, []byte(content), 0600); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
}
|
||||
docs, err := Resolve(Sources{SettingFile: filepath.Join(dir, "settings", "coast.yml")}, nil)
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
if !strings.Contains(string(docs["setting"]), "Harbor") || !strings.Contains(string(docs["setting"]), "Coast") {
|
||||
t.Fatalf("setting: %s", docs["setting"])
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user