summaryrefslogtreecommitdiff
path: root/test
diff options
context:
space:
mode:
authorDave Henderson <dhenderson@gmail.com>2018-05-24 07:51:40 -0400
committerDave Henderson <dhenderson@gmail.com>2018-05-26 13:06:52 -0400
commitd5e17cb1ee87f51d0fd1b3c40e50791ae40e08a0 (patch)
tree994baf2d2ebefeb445b6d99fe2bea305233f4c03 /test
parent8c1aa365be022c0c0c33cee8f2dfb9532442d522 (diff)
Adding env datasource
Signed-off-by: Dave Henderson <dhenderson@gmail.com>
Diffstat (limited to 'test')
-rw-r--r--test/integration/datasources_env_test.go57
1 files changed, 57 insertions, 0 deletions
diff --git a/test/integration/datasources_env_test.go b/test/integration/datasources_env_test.go
new file mode 100644
index 00000000..3b53c1e6
--- /dev/null
+++ b/test/integration/datasources_env_test.go
@@ -0,0 +1,57 @@
+//+build integration
+//+build !windows
+
+package integration
+
+import (
+ "os"
+
+ . "gopkg.in/check.v1"
+
+ "github.com/gotestyourself/gotestyourself/fs"
+ "github.com/gotestyourself/gotestyourself/icmd"
+)
+
+type EnvDatasourcesSuite struct {
+ tmpDir *fs.Dir
+}
+
+var _ = Suite(&EnvDatasourcesSuite{})
+
+func (s *EnvDatasourcesSuite) SetUpSuite(c *C) {
+ os.Setenv("HELLO_WORLD", "hello world")
+ os.Setenv("HELLO_UNIVERSE", "hello universe")
+ os.Setenv("FOO", "bar")
+ os.Setenv("foo", "baz")
+}
+
+func (s *EnvDatasourcesSuite) TearDownSuite(c *C) {
+ os.Unsetenv("HELLO_WORLD")
+ os.Unsetenv("HELLO_UNIVERSE")
+ os.Unsetenv("FOO")
+ os.Unsetenv("foo")
+}
+
+func (s *EnvDatasourcesSuite) TestEnvDatasources(c *C) {
+ result := icmd.RunCommand(GomplateBin,
+ "-d", "foo=env:FOO",
+ "-i", `{{ ds "foo" }}`,
+ )
+ result.Assert(c, icmd.Expected{ExitCode: 0, Out: "bar"})
+
+ result = icmd.RunCommand(GomplateBin,
+ "-d", "foo=env:///foo",
+ "-i", `{{ ds "foo" }}`,
+ )
+ result.Assert(c, icmd.Expected{ExitCode: 0, Out: "baz"})
+
+ result = icmd.RunCmd(icmd.Command(GomplateBin,
+ "-d", "e=env:json_value?type=application/json",
+ "-i", `{{ (ds "e").value}}`,
+ ), func(c *icmd.Cmd) {
+ c.Env = []string{
+ `json_value={"value":"corge"}`,
+ }
+ })
+ result.Assert(c, icmd.Expected{ExitCode: 0, Out: "corge"})
+}