github.com/wuhuizuo/gomplate@v3.5.0+incompatible/tests/integration/datasources_env_test.go (about) 1 //+build integration 2 3 package integration 4 5 import ( 6 "os" 7 "runtime" 8 9 . "gopkg.in/check.v1" 10 11 "github.com/gotestyourself/gotestyourself/icmd" 12 ) 13 14 type EnvDatasourcesSuite struct { 15 } 16 17 var _ = Suite(&EnvDatasourcesSuite{}) 18 19 func (s *EnvDatasourcesSuite) SetUpSuite(c *C) { 20 os.Setenv("HELLO_WORLD", "hello world") 21 os.Setenv("HELLO_UNIVERSE", "hello universe") 22 os.Setenv("FOO", "bar") 23 os.Setenv("foo", "baz") 24 } 25 26 func (s *EnvDatasourcesSuite) TearDownSuite(c *C) { 27 os.Unsetenv("HELLO_WORLD") 28 os.Unsetenv("HELLO_UNIVERSE") 29 os.Unsetenv("FOO") 30 os.Unsetenv("foo") 31 } 32 33 func (s *EnvDatasourcesSuite) TestEnvDatasources(c *C) { 34 result := icmd.RunCommand(GomplateBin, 35 "-d", "foo=env:FOO", 36 "-i", `{{ ds "foo" }}`, 37 ) 38 // Windows envvars are case-insensitive 39 if runtime.GOOS == "windows" { 40 result.Assert(c, icmd.Expected{ExitCode: 0, Out: "baz"}) 41 } else { 42 result.Assert(c, icmd.Expected{ExitCode: 0, Out: "bar"}) 43 } 44 45 result = icmd.RunCommand(GomplateBin, 46 "-d", "foo=env:///foo", 47 "-i", `{{ ds "foo" }}`, 48 ) 49 result.Assert(c, icmd.Expected{ExitCode: 0, Out: "baz"}) 50 51 result = icmd.RunCmd(icmd.Command(GomplateBin, 52 "-d", "e=env:json_value?type=application/json", 53 "-i", `{{ (ds "e").value}}`, 54 ), func(c *icmd.Cmd) { 55 c.Env = []string{ 56 `json_value={"value":"corge"}`, 57 } 58 }) 59 result.Assert(c, icmd.Expected{ExitCode: 0, Out: "corge"}) 60 }