diff --git a/pkg/app/app.go b/pkg/app/app.go index b64cb568..3edf12c0 100644 --- a/pkg/app/app.go +++ b/pkg/app/app.go @@ -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{} }) diff --git a/pkg/state/state.go b/pkg/state/state.go index 15a2faf5..9d9da74c 100644 --- a/pkg/state/state.go +++ b/pkg/state/state.go @@ -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) +} diff --git a/pkg/state/state_test.go b/pkg/state/state_test.go index 36a166d9..375f4ff0 100644 --- a/pkg/state/state_test.go +++ b/pkg/state/state_test.go @@ -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) + }) + } +}