Skip to content

Commit

Permalink
Respect filemarks for Starlark files
Browse files Browse the repository at this point in the history
Fixes #786

Signed-off-by: John Ryan <jtigger@pm.me>
  • Loading branch information
jtigger committed Jan 26, 2023
1 parent d77882f commit 63f4092
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 63f4092

Please sign in to comment.