feat: error out when post-renderer produces no output

When the templating post-renderer produces no output, something went wrong so we error out.

Signed-off-by: Yarden Shoham <git@yardenshoham.com>
pull/30571/head
Yarden Shoham 7 months ago
parent 2cda65d444
commit f475f3e1fd

@ -64,6 +64,12 @@ func (p *execRender) Run(renderedManifests *bytes.Buffer) (*bytes.Buffer, error)
return nil, errors.Wrapf(err, "error while running command %s. error output:\n%s", p.binaryPath, stderr.String()) return nil, errors.Wrapf(err, "error while running command %s. error output:\n%s", p.binaryPath, stderr.String())
} }
// If the binary returned almost nothing, it's likely that it didn't
// successfully render anything
if len(bytes.TrimSpace(postRendered.Bytes())) == 0 {
return nil, errors.Errorf("post render binary %s did not produce any output %s", p.binaryPath, postRendered.String())
}
return postRendered, nil return postRendered, nil
} }

@ -121,6 +121,21 @@ func TestExecRun(t *testing.T) {
is.Contains(output.String(), "BARTEST") is.Contains(output.String(), "BARTEST")
} }
func TestExecRunWithNoOutput(t *testing.T) {
if runtime.GOOS == "windows" {
// the actual Run test uses a basic sed example, so skip this test on windows
t.Skip("skipping on windows")
}
is := assert.New(t)
testpath := setupTestingScript(t)
renderer, err := NewExec(testpath)
require.NoError(t, err)
_, err = renderer.Run(bytes.NewBufferString(""))
is.Error(err)
}
func TestNewExecWithOneArgsRun(t *testing.T) { func TestNewExecWithOneArgsRun(t *testing.T) {
if runtime.GOOS == "windows" { if runtime.GOOS == "windows" {
// the actual Run test uses a basic sed example, so skip this test on windows // the actual Run test uses a basic sed example, so skip this test on windows

Loading…
Cancel
Save