add basepath along with filepath into yaml comment (#460)

* add basepath along with filepath into yaml comment

Signed-off-by: Quan TRAN <itscaro@users.noreply.github.com>
This commit is contained in:
Quan TRAN 2022-10-25 11:44:28 +02:00 committed by GitHub
parent 4a5928e269
commit 2702161e74
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 40 additions and 1 deletions

View File

@ -543,7 +543,7 @@ func (a *App) PrintState(c StateConfigProvider) error {
return
}
fmt.Printf("---\n# Source: %s\n\n%+v", run.state.FilePath, stateYaml)
fmt.Printf("---\n# Source: %s\n\n%+v", run.state.FullFilePath(), stateYaml)
errs = []error{}
})

View File

@ -3356,3 +3356,7 @@ 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)
}

View File

@ -2692,3 +2692,38 @@ func TestGenerateOutputFilePath(t *testing.T) {
})
}
}
func TestFullFilePath(t *testing.T) {
tests := []struct {
basePath string
filePath string
expected string
}{
{
basePath: ".",
filePath: "helmfile.yaml",
expected: "helmfile.yaml",
},
{
basePath: "./test-1/",
filePath: "helmfile.yaml",
expected: "test-1/helmfile.yaml",
},
{
basePath: "/test-2/",
filePath: "helmfile.yaml",
expected: "/test-2/helmfile.yaml",
},
}
for _, tt := range tests {
t.Run(tt.expected, func(t *testing.T) {
st := &HelmState{
basePath: tt.basePath,
FilePath: tt.filePath,
}
actual := st.FullFilePath()
require.Equalf(t, actual, tt.expected, "FullFilePath() got = %v, want %v", actual, tt.expected)
})
}
}