-
-
Notifications
You must be signed in to change notification settings - Fork 190
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Signed-off-by: Dave Henderson <[email protected]>
- Loading branch information
1 parent
955fc69
commit 15cd750
Showing
8 changed files
with
320 additions
and
3 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,65 @@ | ||
package funcs | ||
|
||
import ( | ||
"testing" | ||
|
||
"github.com/stretchr/testify/assert" | ||
) | ||
|
||
func TestAssert(t *testing.T) { | ||
f := TestNS() | ||
_, err := f.Assert(false) | ||
assert.Error(t, err) | ||
|
||
_, err = f.Assert(true) | ||
assert.NoError(t, err) | ||
|
||
_, err = f.Assert("foo", true) | ||
assert.NoError(t, err) | ||
|
||
_, err = f.Assert("foo", "false") | ||
assert.EqualError(t, err, "assertion failed: foo") | ||
} | ||
|
||
func TestRequired(t *testing.T) { | ||
f := TestNS() | ||
errMsg := "can not render template: a required value was not set" | ||
v, err := f.Required("") | ||
assert.Error(t, err) | ||
assert.EqualError(t, err, errMsg) | ||
assert.Nil(t, v) | ||
|
||
v, err = f.Required(nil) | ||
assert.Error(t, err) | ||
assert.EqualError(t, err, errMsg) | ||
assert.Nil(t, v) | ||
|
||
errMsg = "hello world" | ||
v, err = f.Required(errMsg, nil) | ||
assert.Error(t, err) | ||
assert.EqualError(t, err, errMsg) | ||
assert.Nil(t, v) | ||
|
||
v, err = f.Required(42, nil) | ||
assert.Error(t, err) | ||
assert.EqualError(t, err, "at <1>: expected string; found int") | ||
assert.Nil(t, v) | ||
|
||
v, err = f.Required() | ||
assert.Error(t, err) | ||
assert.EqualError(t, err, "wrong number of args: want 1 or 2, got 0") | ||
assert.Nil(t, v) | ||
|
||
v, err = f.Required("", 2, 3) | ||
assert.Error(t, err) | ||
assert.EqualError(t, err, "wrong number of args: want 1 or 2, got 3") | ||
assert.Nil(t, v) | ||
|
||
v, err = f.Required(0) | ||
assert.NoError(t, err) | ||
assert.Equal(t, v, 0) | ||
|
||
v, err = f.Required("foo") | ||
assert.NoError(t, err) | ||
assert.Equal(t, v, "foo") | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,105 @@ | ||
//+build integration | ||
//+build !windows | ||
|
||
package integration | ||
|
||
import ( | ||
"bytes" | ||
|
||
. "gopkg.in/check.v1" | ||
|
||
"github.com/gotestyourself/gotestyourself/icmd" | ||
) | ||
|
||
type TestSuite struct { | ||
} | ||
|
||
var _ = Suite(&TestSuite{}) | ||
|
||
func (s *TestSuite) SetUpTest(c *C) { | ||
} | ||
|
||
func (s *TestSuite) TearDownTest(c *C) { | ||
} | ||
|
||
func (s *TestSuite) TestFail(c *C) { | ||
result := icmd.RunCommand(GomplateBin, "-i", "{{ fail }}") | ||
result.Assert(c, icmd.Expected{ExitCode: 1, Err: `template generation failed`}) | ||
|
||
result = icmd.RunCommand(GomplateBin, "-i", "{{ fail `some message` }}") | ||
result.Assert(c, icmd.Expected{ExitCode: 1, Err: `some message`}) | ||
} | ||
|
||
func (s *TestSuite) TestRequired(c *C) { | ||
result := icmd.RunCmd(icmd.Command(GomplateBin, | ||
"-i", `{{getenv "FOO" | required "FOO missing" }}`)) | ||
result.Assert(c, icmd.Expected{ | ||
ExitCode: 1, | ||
Err: "FOO missing", | ||
}) | ||
|
||
result = icmd.RunCmd(icmd.Command(GomplateBin, | ||
"-i", `{{getenv "FOO" | required "FOO missing" }}`), | ||
func(c *icmd.Cmd) { | ||
c.Env = []string{"FOO=bar"} | ||
}) | ||
result.Assert(c, icmd.Expected{ | ||
ExitCode: 0, | ||
Out: "bar", | ||
}) | ||
|
||
result = icmd.RunCmd(icmd.Command(GomplateBin, | ||
"-d", "in=stdin:///?type=application/yaml", | ||
"-i", `{{ (ds "in").foo | required "foo should not be null" }}`), | ||
func(c *icmd.Cmd) { | ||
c.Stdin = bytes.NewBufferString(`foo: null`) | ||
}) | ||
result.Assert(c, icmd.Expected{ | ||
ExitCode: 1, | ||
Err: "foo should not be null", | ||
}) | ||
|
||
result = icmd.RunCmd(icmd.Command(GomplateBin, | ||
"-d", "in=stdin:///?type=application/yaml", | ||
"-i", `{{ (ds "in").foo | required }}`), | ||
func(c *icmd.Cmd) { | ||
c.Stdin = bytes.NewBufferString(`foo: []`) | ||
}) | ||
result.Assert(c, icmd.Expected{ | ||
ExitCode: 0, | ||
Out: "[]", | ||
}) | ||
|
||
result = icmd.RunCmd(icmd.Command(GomplateBin, | ||
"-d", "in=stdin:///?type=application/yaml", | ||
"-i", `{{ (ds "in").foo | required }}`), | ||
func(c *icmd.Cmd) { | ||
c.Stdin = bytes.NewBufferString(`foo: {}`) | ||
}) | ||
result.Assert(c, icmd.Expected{ | ||
ExitCode: 0, | ||
Out: "map[]", | ||
}) | ||
|
||
result = icmd.RunCmd(icmd.Command(GomplateBin, | ||
"-d", "in=stdin:///?type=application/yaml", | ||
"-i", `{{ (ds "in").foo | required }}`), | ||
func(c *icmd.Cmd) { | ||
c.Stdin = bytes.NewBufferString(`foo: 0`) | ||
}) | ||
result.Assert(c, icmd.Expected{ | ||
ExitCode: 0, | ||
Out: "0", | ||
}) | ||
|
||
result = icmd.RunCmd(icmd.Command(GomplateBin, | ||
"-d", "in=stdin:///?type=application/yaml", | ||
"-i", `{{ (ds "in").foo | required }}`), | ||
func(c *icmd.Cmd) { | ||
c.Stdin = bytes.NewBufferString(`foo: false`) | ||
}) | ||
result.Assert(c, icmd.Expected{ | ||
ExitCode: 0, | ||
Out: "false", | ||
}) | ||
} |