mirror of
https://github.com/lukaszraczylo/harness-sync.git
synced 2026-10-14 00:57:49 +00:00
test(apply): cover symlinks, force, dry-run, merge, errors, state round-trip
This commit is contained in:
@@ -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
|
||||
}
|
||||
|
||||
@@ -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")
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user