Extend discovery coverage across consumer workflows
This commit is contained in:
45
examples/consumers/discovery_test.go
Normal file
45
examples/consumers/discovery_test.go
Normal file
@@ -0,0 +1,45 @@
|
||||
package consumers_test
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"os"
|
||||
"path/filepath"
|
||||
|
||||
configkit "gitea.maximumdirect.net/eric/ConfigKit"
|
||||
)
|
||||
|
||||
type workingDirectoryPresetConfig struct {
|
||||
Name string `yaml:"name"`
|
||||
}
|
||||
|
||||
func Example_workingDirectoryPreset() {
|
||||
original, err := os.Getwd()
|
||||
if err != nil {
|
||||
fmt.Println(err)
|
||||
return
|
||||
}
|
||||
defer func() { _ = os.Chdir(original) }()
|
||||
root, err := os.MkdirTemp("", "configkit-working-search-")
|
||||
if err != nil {
|
||||
fmt.Println(err)
|
||||
return
|
||||
}
|
||||
defer os.RemoveAll(root)
|
||||
if err := os.Chdir(root); err != nil {
|
||||
fmt.Println(err)
|
||||
return
|
||||
}
|
||||
if err := os.WriteFile(filepath.Join(root, "service.yml"), []byte("name: example\n"), 0o600); err != nil {
|
||||
fmt.Println(err)
|
||||
return
|
||||
}
|
||||
result, err := configkit.Load[workingDirectoryPresetConfig](
|
||||
configkit.SearchConfig("service", configkit.WorkingDirectory()),
|
||||
)
|
||||
if err != nil {
|
||||
fmt.Println(err)
|
||||
return
|
||||
}
|
||||
fmt.Println(result.Config.Name, filepath.Base(result.Sources()[0].Path))
|
||||
// Output: example service.yml
|
||||
}
|
||||
@@ -31,13 +31,23 @@ type SequenceCatalogEntry struct {
|
||||
Credential configkit.Secret `yaml:"credential"`
|
||||
}
|
||||
|
||||
// LoadSequenceCatalog assembles imported main fragments over a file-backed
|
||||
// underlay, applies one selected collection overlay, then resolves and validates
|
||||
// the resulting application configuration.
|
||||
// LoadSequenceCatalog searches its caller-selected main path before a custom
|
||||
// fallback directory, assembles imported fragments over a file-backed underlay,
|
||||
// applies one selected collection overlay, then resolves and validates once.
|
||||
func LoadSequenceCatalog(mainPath, overlayName, runLabel string) (*configkit.Result[SequenceCatalogConfig], error) {
|
||||
root := filepath.Dir(mainPath)
|
||||
absoluteMain, err := filepath.Abs(mainPath)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
root := filepath.Dir(absoluteMain)
|
||||
filesystem := configkit.NewFilesystem("sequence catalog", os.DirFS(root))
|
||||
filesystemContext := &configkit.FilesystemContext{BaseDir: ".", Root: ".", FS: &filesystem}
|
||||
mainSearch := configkit.SearchConfig("", configkit.Searches(
|
||||
configkit.Paths(absoluteMain),
|
||||
configkit.SearchDirectory(filepath.Join(root, "fallback"), configkit.DirectorySearchOptions{
|
||||
Filenames: []configkit.FilenameGroup{configkit.CustomFilenames(filepath.Base(absoluteMain))},
|
||||
}),
|
||||
), configkit.SearchOptions{Required: true})
|
||||
definition := configkit.Definition[SequenceCatalogConfig]{
|
||||
SequenceIdentities: []configkit.SequenceIdentity{
|
||||
configkit.SequenceIdentityAt(configkit.Keys("prompts"), "id"),
|
||||
@@ -51,8 +61,9 @@ func LoadSequenceCatalog(mainPath, overlayName, runLabel string) (*configkit.Res
|
||||
Validate: validateSequenceCatalog,
|
||||
}
|
||||
return configkit.LoadLayered(configkit.Input{
|
||||
Source: filesystem.File(filepath.Base(mainPath)),
|
||||
Imports: true,
|
||||
Source: mainSearch,
|
||||
Imports: true,
|
||||
Filesystem: &configkit.FilesystemContext{Root: root},
|
||||
}, configkit.LayeredOptions[SequenceCatalogConfig]{
|
||||
Underlays: []configkit.Underlay{{Inputs: []configkit.Input{{
|
||||
Source: filesystem.File("underlay.yml"),
|
||||
|
||||
Reference in New Issue
Block a user