Skip to content
This repository has been archived by the owner on Oct 2, 2024. It is now read-only.

Commit

Permalink
refactor(cmd): improve error message when resource file is not refere…
Browse files Browse the repository at this point in the history
…nced

Signed-off-by: Xavier Coulon <[email protected]>
  • Loading branch information
xcoulon committed May 30, 2024
1 parent 9f4cf32 commit dac777b
Show file tree
Hide file tree
Showing 3 changed files with 4 additions and 5 deletions.
5 changes: 2 additions & 3 deletions pkg/validation/components.go
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
package validation

import (
"fmt"
"io/fs"
"path/filepath"

Expand Down Expand Up @@ -31,12 +30,12 @@ func CheckComponents(logger Logger, afs afero.Afero, baseDir string, components
// look for a Kustomization file in the directory
if kp, found := lookupKustomizationFile(logger, afs, path); found {
if err := checkKustomizeResources(logger, afs, kp); err != nil {
return fmt.Errorf("invalid resources at %s: %w", path, err)
return err
}
if d.Name() != "base" {
logger.Debug("checking Kustomization build ", "path", path)
if err := checkBuild(logger, fsys, path); err != nil {
return fmt.Errorf("invalid resources at %s: %w", path, err)
return err
}
}
}
Expand Down
2 changes: 1 addition & 1 deletion pkg/validation/components_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -330,7 +330,7 @@ data:
err = validation.CheckComponents(logger, afs, "/path/to", "components")

// then
require.Error(t, err, "resource is not referenced: /path/to/components/configmap2.yaml")
require.EqualError(t, err, "resource is not referenced in /path/to/components/kustomization.yaml: configmap2.yaml")
assert.Empty(t, logger.Errors())
assert.Empty(t, logger.Warnings())
})
Expand Down
2 changes: 1 addition & 1 deletion pkg/validation/resources.go
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,7 @@ entries:
continue entries
}
}
return fmt.Errorf("resource is not referenced: %s", filepath.Join(path, e.Name()))
return fmt.Errorf("resource is not referenced in %s: %s", path, e.Name())
}
return nil
}

0 comments on commit dac777b

Please sign in to comment.