use fs.Getwd() to get working dir for sub helmfile (#471)
* use fs.Getwd() to get working dir for sub helmfile Signed-off-by: Quan TRAN <itscaro@users.noreply.github.com>
This commit is contained in:
parent
2cf6501d1f
commit
414f899c28
|
|
@ -543,7 +543,12 @@ func (a *App) PrintState(c StateConfigProvider) error {
|
|||
return
|
||||
}
|
||||
|
||||
fmt.Printf("---\n# Source: %s\n\n%+v", run.state.FullFilePath(), stateYaml)
|
||||
sourceFile, err := run.state.FullFilePath()
|
||||
if err != nil {
|
||||
errs = []error{err}
|
||||
return
|
||||
}
|
||||
fmt.Printf("---\n# Source: %s\n\n%+v", sourceFile, stateYaml)
|
||||
|
||||
errs = []error{}
|
||||
})
|
||||
|
|
|
|||
|
|
@ -3357,6 +3357,11 @@ func (st *HelmState) getOCIChart(release *ReleaseSpec, tempDir string, helm helm
|
|||
return &chartPath, nil
|
||||
}
|
||||
|
||||
func (st *HelmState) FullFilePath() string {
|
||||
return filepath.Join(st.basePath, st.FilePath)
|
||||
func (st *HelmState) FullFilePath() (string, error) {
|
||||
var wd string
|
||||
var err error
|
||||
if st.fs != nil {
|
||||
wd, err = st.fs.Getwd()
|
||||
}
|
||||
return filepath.Join(wd, st.basePath, st.FilePath), err
|
||||
}
|
||||
|
|
|
|||
|
|
@ -2694,9 +2694,11 @@ func TestGenerateOutputFilePath(t *testing.T) {
|
|||
}
|
||||
|
||||
func TestFullFilePath(t *testing.T) {
|
||||
fs := testhelper.NewTestFs(map[string]string{})
|
||||
tests := []struct {
|
||||
basePath string
|
||||
filePath string
|
||||
fs *filesystem.FileSystem
|
||||
expected string
|
||||
}{
|
||||
{
|
||||
|
|
@ -2714,6 +2716,18 @@ func TestFullFilePath(t *testing.T) {
|
|||
filePath: "helmfile.yaml",
|
||||
expected: "/test-2/helmfile.yaml",
|
||||
},
|
||||
{
|
||||
basePath: "./test-3/",
|
||||
filePath: "helmfile.yaml",
|
||||
fs: fs.ToFileSystem(),
|
||||
expected: "/path/to/test-3/helmfile.yaml",
|
||||
},
|
||||
{
|
||||
basePath: "/test-4/",
|
||||
filePath: "helmfile.yaml",
|
||||
fs: fs.ToFileSystem(),
|
||||
expected: "/path/to/test-4/helmfile.yaml",
|
||||
},
|
||||
}
|
||||
|
||||
for _, tt := range tests {
|
||||
|
|
@ -2721,9 +2735,11 @@ func TestFullFilePath(t *testing.T) {
|
|||
st := &HelmState{
|
||||
basePath: tt.basePath,
|
||||
FilePath: tt.filePath,
|
||||
fs: tt.fs,
|
||||
}
|
||||
actual := st.FullFilePath()
|
||||
actual, err := st.FullFilePath()
|
||||
require.Equalf(t, actual, tt.expected, "FullFilePath() got = %v, want %v", actual, tt.expected)
|
||||
require.Equalf(t, err, nil, "error %v", err)
|
||||
})
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,5 +1,5 @@
|
|||
---
|
||||
# Source: input.yaml
|
||||
# Source: /home/runner/work/helmfile/helmfile/test/e2e/template/helmfile/testdata/snapshot/issue_2098_release_template_needs/input.yaml
|
||||
|
||||
filepath: input.yaml
|
||||
helmBinary: helm
|
||||
|
|
|
|||
Loading…
Reference in New Issue