Skip to content

Commit

Permalink
Merge pull request #797 from carvel-dev/fix-starlark-filemark
Browse files Browse the repository at this point in the history
Respect filemarks for Starlark files
  • Loading branch information
jtigger authored Jan 26, 2023
2 parents d77882f + 63f4092 commit 6dbc837
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 2 deletions.
19 changes: 19 additions & 0 deletions pkg/cmd/template/regular_input_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ import (
"os"
"testing"

"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/require"
"github.com/vmware-tanzu/carvel-ytt/pkg/cmd/template"
cmdtpl "github.com/vmware-tanzu/carvel-ytt/pkg/cmd/template"
Expand Down Expand Up @@ -87,6 +88,24 @@ organization=Acme Widgets Inc.`)
assertStdoutAndStderr(t, stdout, stderr, expectedStdOut, expectedStdErr)
}

func Test_Input_Marked_As_Starlark_Is_Evaluated_As_Starlark(t *testing.T) {
starlarkData := []byte(`fail("hello")`)

filesToProcess := []*files.File{
files.MustNewFileFromSource(files.NewBytesSource("print.star1", starlarkData)),
}

stdout := bytes.NewBufferString("")
stderr := bytes.NewBufferString("")
testUI := ui.NewCustomWriterTTY(false, stdout, stderr)
opts := cmdtpl.NewOptions()
opts.FileMarksOpts.FileMarks = []string{"print.star1:type=starlark"}

out := opts.RunWithFiles(cmdtpl.Input{Files: filesToProcess}, testUI)
require.Error(t, out.Err)
assert.ErrorContains(t, out.Err, "fail: hello")
}

func Test_FileMark_YAML_Shows_No_Warning(t *testing.T) {
yamlData := []byte(`foo: bar`)

Expand Down
4 changes: 2 additions & 2 deletions pkg/files/file.go
Original file line number Diff line number Diff line change
Expand Up @@ -246,8 +246,8 @@ func (r *File) IsLibrary() bool {
return true
}

// make exception for starlark files as they are just pure code
return r.matchesExt(starlarkExts)
// Starlark files are always libraries
return r.Type() == TypeStarlark
}

func (r *File) matchesExt(exts []string) bool {
Expand Down

0 comments on commit 6dbc837

Please sign in to comment.