Demonstrate main-relative companion loading
This commit is contained in:
46
examples/consumers/main_relative_test.go
Normal file
46
examples/consumers/main_relative_test.go
Normal file
@@ -0,0 +1,46 @@
|
||||
package consumers_test
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"os"
|
||||
"path/filepath"
|
||||
"testing"
|
||||
|
||||
configkit "go.maximumdirect.net/configkit"
|
||||
"go.maximumdirect.net/configkit/examples/consumers"
|
||||
)
|
||||
|
||||
func Example_mainRelativeCompanions() {
|
||||
result, err := consumers.LoadCompanionConfig(fixture("main-relative", "main.yml"), "live")
|
||||
if err != nil {
|
||||
fmt.Println(err)
|
||||
return
|
||||
}
|
||||
fmt.Println(result.Config.Mode, result.Config.Prompts)
|
||||
// Output: overlay [{shared operator replacement } {bundled bundled text } {local local text transitive detail}]
|
||||
}
|
||||
|
||||
func TestMainRelativeStrictPeers(t *testing.T) {
|
||||
root := t.TempDir()
|
||||
for name, contents := range map[string]string{
|
||||
"main.yml": "mode: main\n", "prompts.yml": "id: duplicate\ntext: first\n", "operator/second.yml": "id: duplicate\ntext: second\n",
|
||||
} {
|
||||
file := filepath.Join(root, name)
|
||||
if err := os.MkdirAll(filepath.Dir(file), 0700); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
if err := os.WriteFile(file, []byte(contents), 0600); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
}
|
||||
_, err := consumers.LoadCompanionConfig(filepath.Join(root, "main.yml"), "")
|
||||
if err == nil {
|
||||
t.Fatal("duplicate peer identities succeeded")
|
||||
}
|
||||
for _, d := range err.(*configkit.LoadError).Diagnostics() {
|
||||
if d.Code == configkit.CodeComposeConflict {
|
||||
return
|
||||
}
|
||||
}
|
||||
t.Fatalf("diagnostics = %#v", err.(*configkit.LoadError).Diagnostics())
|
||||
}
|
||||
Reference in New Issue
Block a user