Skip to content

Commit

Permalink
Merge pull request #903 from ernstvonoelsen/issue-895
Browse files Browse the repository at this point in the history
Print full path rather than RelativePath only.
  • Loading branch information
joaopapereira authored Jun 7, 2024
2 parents 8f101fd + c33ee2f commit 91690b6
Show file tree
Hide file tree
Showing 4 changed files with 19 additions and 3 deletions.
2 changes: 1 addition & 1 deletion pkg/cmd/template/data_values_flags.go
Original file line number Diff line number Diff line change
Expand Up @@ -168,7 +168,7 @@ func (s *DataValuesFlags) file(fullPath string, strict bool) ([]*datavalues.Enve
}
docSet, err := yamlmeta.NewDocumentSetFromBytes(contents, docSetOpts)
if err != nil {
return nil, fmt.Errorf("Unmarshaling YAML data values file '%s': %s", dvFile.RelativePath(), err)
return nil, fmt.Errorf("Unmarshaling YAML data values file '%s': %s", dvFile.Description(), err)
}

for _, doc := range docSet.Items {
Expand Down
3 changes: 2 additions & 1 deletion pkg/files/sources.go
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,8 @@ type LocalSource struct {

func NewLocalSource(path, dir string) LocalSource { return LocalSource{path, dir} }

func (s LocalSource) Description() string { return fmt.Sprintf("file '%s'", s.path) }
// Description return LocalSource's (i.e. file's) path
func (s LocalSource) Description() string { return fmt.Sprintf("file %s", s.path) }

func (s LocalSource) RelativePath() (string, error) {
if s.dir == "" {
Expand Down
2 changes: 1 addition & 1 deletion pkg/workspace/template_loader.go
Original file line number Diff line number Diff line change
Expand Up @@ -149,7 +149,7 @@ func (l *TemplateLoader) EvalPlainYAML(file *files.File) (*yamlmeta.DocumentSet,

docSet, err := yamlmeta.NewDocumentSetFromBytes(fileBs, docSetOpts)
if err != nil {
return nil, fmt.Errorf("Unmarshaling YAML template '%s': %s", file.RelativePath(), err)
return nil, fmt.Errorf("Unmarshaling YAML template '%s': %s", file.Description(), err)
}

return docSet, nil
Expand Down
15 changes: 15 additions & 0 deletions test/e2e/e2e_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -292,6 +292,21 @@ new_thing: new
})
}

func TestProcessingFileWithError(t *testing.T) {
t.Run("invalidYamlFile", func(t *testing.T) {
tempInputDir, err := os.MkdirTemp(os.TempDir(), "ytt-check-dir")
require.NoError(t, err)
err = os.WriteFile(tempInputDir+"/config.yaml", []byte(`apiVersion: "v1"
key value`), 0666)
require.NoError(t, err)
defer os.Remove(tempInputDir)

actualOutput := runYttExpectingError(t, testInputFiles{tempInputDir + "/config.yaml"}, nil, nil)
expectedOutput := "ytt: Error: Unmarshaling YAML template 'file " + tempInputDir + "/config.yaml': yaml: line 3: could not find expected ':'\n"
require.Equal(t, expectedOutput, actualOutput)
})
}

func TestCheckDirectoryOutput(t *testing.T) {
tempOutputDir, err := os.MkdirTemp(os.TempDir(), "ytt-check-dir")
require.NoError(t, err)
Expand Down

0 comments on commit 91690b6

Please sign in to comment.