From d5e17cb1ee87f51d0fd1b3c40e50791ae40e08a0 Mon Sep 17 00:00:00 2001 From: Dave Henderson Date: Thu, 24 May 2018 07:51:40 -0400 Subject: Adding env datasource Signed-off-by: Dave Henderson --- test/integration/datasources_env_test.go | 57 ++++++++++++++++++++++++++++++++ 1 file changed, 57 insertions(+) create mode 100644 test/integration/datasources_env_test.go (limited to 'test') 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"}) +} -- cgit v1.2.3