test(apply): cover symlinks, force, dry-run, merge, errors, state round-trip

This commit is contained in:
2026-05-23 11:55:01 +01:00
parent dd990cf25b
commit 5e35dc47fe
4 changed files with 541 additions and 4 deletions
+5 -2
View File
@@ -31,7 +31,10 @@ func Load(root string) (*Bundle, error) {
profPath := filepath.Join(root, "profiles", b.Config.ActiveProfile+".yaml")
err = loadYAML(profPath, &b.Profile)
if err != nil {
return nil, err
return nil, fmt.Errorf("profile %q: %w", b.Config.ActiveProfile, err)
}
if b.Profile.Name == "" {
return nil, fmt.Errorf("profile %q (%s): name is required (expected key 'name' with a string value)", b.Config.ActiveProfile, profPath)
}
mcpPath := filepath.Join(root, "mcp.yaml")
@@ -152,7 +155,7 @@ func loadYAML(path string, out interface{}) error {
return fmt.Errorf("read %s: %w", path, err)
}
if err := yaml.Unmarshal(b, out); err != nil {
return fmt.Errorf("parse %s: %w", path, err)
return fmt.Errorf("parse %s: %w (check YAML syntax and field names)", path, err)
}
return nil
}
+28
View File
@@ -33,3 +33,31 @@ func TestLoadMissingProfile(t *testing.T) {
_, err := Load("testdata/missing")
assert.Error(t, err)
}
func TestLoadMissingConfigYAML(t *testing.T) {
// testdata/missing_config has no config.yaml — only an empty profiles dir.
_, err := Load("testdata/missing_config")
require.Error(t, err)
assert.Contains(t, err.Error(), "config.yaml")
}
func TestLoadMalformedConfigYAML(t *testing.T) {
_, err := Load("testdata/malformed_config")
require.Error(t, err)
assert.Contains(t, err.Error(), "parse")
assert.Contains(t, err.Error(), "config.yaml")
}
func TestLoadMissingActiveProfile(t *testing.T) {
// config.yaml references "nonexistent" profile which has no file.
_, err := Load("testdata/missing_active_profile")
require.Error(t, err)
assert.Contains(t, err.Error(), "nonexistent")
}
func TestLoadProfileMissingName(t *testing.T) {
// profile YAML exists but has no 'name' field.
_, err := Load("testdata/profile_no_name")
require.Error(t, err)
assert.Contains(t, err.Error(), "profile")
assert.Contains(t, err.Error(), "name")
}