diff options
| author | Dave Henderson <dhenderson@gmail.com> | 2018-07-16 23:15:40 -0400 |
|---|---|---|
| committer | Dave Henderson <dhenderson@gmail.com> | 2018-07-16 23:20:52 -0400 |
| commit | 1a7f0e170254b03d3c52d8b891277b78e6a2a901 (patch) | |
| tree | beb9b2550b4c5c636c797ac2af01c981661eb470 /test | |
| parent | 1394001de79f6b24951095bb4831f32d919be9b7 (diff) | |
Move integration tests
Signed-off-by: Dave Henderson <dhenderson@gmail.com>
Diffstat (limited to 'test')
22 files changed, 0 insertions, 2015 deletions
diff --git a/test/integration/base64_test.go b/test/integration/base64_test.go deleted file mode 100644 index 28dddd00..00000000 --- a/test/integration/base64_test.go +++ /dev/null @@ -1,26 +0,0 @@ -//+build integration -//+build !windows - -package integration - -import ( - . "gopkg.in/check.v1" - - "github.com/gotestyourself/gotestyourself/icmd" -) - -type Base64Suite struct{} - -var _ = Suite(&Base64Suite{}) - -func (s *Base64Suite) TestBase64Encode(c *C) { - result := icmd.RunCommand(GomplateBin, "-i", - `{{ "foo" | base64.Encode }}`) - result.Assert(c, icmd.Expected{ExitCode: 0, Out: "Zm9v"}) -} - -func (s *Base64Suite) TestBase64Decode(c *C) { - result := icmd.RunCommand(GomplateBin, "-i", - `{{ "Zm9v" | base64.Decode }}`) - result.Assert(c, icmd.Expected{ExitCode: 0, Out: "foo"}) -} diff --git a/test/integration/basic_test.go b/test/integration/basic_test.go deleted file mode 100644 index 2565341b..00000000 --- a/test/integration/basic_test.go +++ /dev/null @@ -1,166 +0,0 @@ -// +build integration -//+build !windows - -package integration - -import ( - "bytes" - "io/ioutil" - - . "gopkg.in/check.v1" - - "github.com/gotestyourself/gotestyourself/assert" - "github.com/gotestyourself/gotestyourself/assert/cmp" - "github.com/gotestyourself/gotestyourself/fs" - "github.com/gotestyourself/gotestyourself/icmd" -) - -type BasicSuite struct { - tmpDir *fs.Dir -} - -var _ = Suite(&BasicSuite{}) - -func (s *BasicSuite) SetUpSuite(c *C) { - s.tmpDir = fs.NewDir(c, "gomplate-inttests", - fs.WithFile("one", "hi\n"), - fs.WithFile("two", "hello\n")) -} - -func (s *BasicSuite) TearDownSuite(c *C) { - s.tmpDir.Remove() -} - -func (s *BasicSuite) TestReportsVersion(c *C) { - result := icmd.RunCommand(GomplateBin, "-v") - result.Assert(c, icmd.Success) - assert.Assert(c, cmp.Contains(result.Combined(), "gomplate version ")) -} - -func (s *BasicSuite) TestTakesStdinByDefault(c *C) { - result := icmd.RunCmd(icmd.Command(GomplateBin), func(cmd *icmd.Cmd) { - cmd.Stdin = bytes.NewBufferString("hello world") - }) - result.Assert(c, icmd.Expected{ExitCode: 0, Out: "hello world"}) -} - -func (s *BasicSuite) TestTakesStdinWithFileFlag(c *C) { - result := icmd.RunCmd(icmd.Command(GomplateBin, "--file", "-"), func(cmd *icmd.Cmd) { - cmd.Stdin = bytes.NewBufferString("hello world") - }) - result.Assert(c, icmd.Expected{ExitCode: 0, Out: "hello world"}) -} -func (s *BasicSuite) TestWritesToStdoutWithOutFlag(c *C) { - result := icmd.RunCmd(icmd.Command(GomplateBin, "--out", "-"), func(cmd *icmd.Cmd) { - cmd.Stdin = bytes.NewBufferString("hello world") - }) - result.Assert(c, icmd.Expected{ExitCode: 0, Out: "hello world"}) -} - -func (s *BasicSuite) TestIgnoresStdinWithInFlag(c *C) { - result := icmd.RunCmd(icmd.Command(GomplateBin, "--in", "hi"), func(cmd *icmd.Cmd) { - cmd.Stdin = bytes.NewBufferString("hello world") - }) - result.Assert(c, icmd.Expected{ExitCode: 0, Out: "hi"}) -} - -func (s *BasicSuite) TestErrorsWithInputOutputImbalance(c *C) { - result := icmd.RunCmd(icmd.Command(GomplateBin, - "-f", s.tmpDir.Join("one"), - "-f", s.tmpDir.Join("two"), - "-o", s.tmpDir.Join("out")), func(cmd *icmd.Cmd) { - cmd.Stdin = bytes.NewBufferString("hello world") - }) - result.Assert(c, icmd.Expected{ - ExitCode: 1, - Err: "Error: Must provide same number of --out (1) as --file (2) options", - }) -} - -func (s *BasicSuite) TestRoutesInputsToProperOutputs(c *C) { - oneOut := s.tmpDir.Join("one.out") - twoOut := s.tmpDir.Join("two.out") - result := icmd.RunCmd(icmd.Command(GomplateBin, - "-f", s.tmpDir.Join("one"), - "-f", s.tmpDir.Join("two"), - "-o", oneOut, - "-o", twoOut), func(cmd *icmd.Cmd) { - cmd.Stdin = bytes.NewBufferString("hello world") - }) - result.Assert(c, icmd.Success) - - content, err := ioutil.ReadFile(oneOut) - assert.NilError(c, err) - assert.Equal(c, "hi\n", string(content)) - content, err = ioutil.ReadFile(twoOut) - assert.NilError(c, err) - assert.Equal(c, "hello\n", string(content)) -} - -func (s *BasicSuite) TestFlagRules(c *C) { - result := icmd.RunCommand(GomplateBin, "-f", "-", "-i", "HELLO WORLD") - result.Assert(c, icmd.Expected{ - ExitCode: 1, - Out: "--in and --file may not be used together", - }) - - result = icmd.RunCommand(GomplateBin, "--output-dir", ".") - result.Assert(c, icmd.Expected{ - ExitCode: 1, - Out: "--input-dir must be set when --output-dir is set", - }) - - result = icmd.RunCommand(GomplateBin, "--input-dir", ".", "--in", "param") - result.Assert(c, icmd.Expected{ - ExitCode: 1, - Out: "--input-dir can not be used together with --in or --file", - }) - - result = icmd.RunCommand(GomplateBin, "--input-dir", ".", "--file", "input.txt") - result.Assert(c, icmd.Expected{ - ExitCode: 1, - Out: "--input-dir can not be used together with --in or --file", - }) - - result = icmd.RunCommand(GomplateBin, "--output-dir", ".", "--out", "param") - result.Assert(c, icmd.Expected{ - ExitCode: 1, - Out: "--output-dir can not be used together with --out", - }) -} - -func (s *BasicSuite) TestDelimsChangedThroughOpts(c *C) { - result := icmd.RunCommand(GomplateBin, - "--left-delim", "((", - "--right-delim", "))", - "-i", `((print "hi"))`) - result.Assert(c, icmd.Expected{ExitCode: 0, Out: "hi"}) -} - -func (s *BasicSuite) TestDelimsChangedThroughEnvVars(c *C) { - result := icmd.RunCmd(icmd.Command(GomplateBin, "-i", `<<print "hi">>`), - func(cmd *icmd.Cmd) { - cmd.Env = []string{ - "GOMPLATE_LEFT_DELIM=<<", - "GOMPLATE_RIGHT_DELIM=>>", - } - }) - result.Assert(c, icmd.Expected{ExitCode: 0, Out: "hi"}) -} - -func (s *BasicSuite) TestUnknownArgErrors(c *C) { - result := icmd.RunCommand(GomplateBin, "-in", "flibbit") - result.Assert(c, icmd.Expected{ExitCode: 1, Out: `unknown command "flibbit" for "gomplate"`}) -} - -func (s *BasicSuite) TestExecCommand(c *C) { - out := s.tmpDir.Join("out") - result := icmd.RunCmd(icmd.Command(GomplateBin, - "-i", `{{print "hello world"}}`, - "-o", out, - "--", "cat", out)) - result.Assert(c, icmd.Expected{ - ExitCode: 0, - Out: "hello world", - }) -} diff --git a/test/integration/datasources_boltdb_test.go b/test/integration/datasources_boltdb_test.go deleted file mode 100644 index a81e2b20..00000000 --- a/test/integration/datasources_boltdb_test.go +++ /dev/null @@ -1,65 +0,0 @@ -//+build integration -//+build !windows - -package integration - -import ( - . "gopkg.in/check.v1" - - "github.com/boltdb/bolt" - "github.com/gotestyourself/gotestyourself/fs" - "github.com/gotestyourself/gotestyourself/icmd" -) - -type BoltDBDatasourcesSuite struct { - tmpDir *fs.Dir -} - -var _ = Suite(&BoltDBDatasourcesSuite{}) - -func (s *BoltDBDatasourcesSuite) SetUpSuite(c *C) { - s.tmpDir = fs.NewDir(c, "gomplate-inttests") - db, err := bolt.Open(s.tmpDir.Join("config.db"), 0600, nil) - handle(c, err) - defer db.Close() - - err = db.Update(func(tx *bolt.Tx) error { - var b *bolt.Bucket - b, err = tx.CreateBucket([]byte("Bucket1")) - if err != nil { - return err - } - // the first 8 bytes are ignored when read by libkv, so we prefix with gibberish - err = b.Put([]byte("foo"), []byte("00000000bar")) - if err != nil { - return err - } - - b, err = tx.CreateBucket([]byte("Bucket2")) - if err != nil { - return err - } - err = b.Put([]byte("foobar"), []byte("00000000baz")) - return err - }) - handle(c, err) -} - -func (s *BoltDBDatasourcesSuite) TearDownSuite(c *C) { - s.tmpDir.Remove() -} - -func (s *BoltDBDatasourcesSuite) TestBoltDBDatasource(c *C) { - result := icmd.RunCommand(GomplateBin, - "-d", "config=boltdb://"+s.tmpDir.Join("config.db#Bucket1"), - "-i", `{{(ds "config" "foo")}}`, - ) - result.Assert(c, icmd.Expected{ExitCode: 0, Out: "bar"}) - - result = icmd.RunCommand(GomplateBin, - "-d", "config=boltdb://"+s.tmpDir.Join("config.db#Bucket1"), - "-d", "config2=boltdb://"+s.tmpDir.Join("config.db#Bucket2"), - "-i", `{{(ds "config" "foo")}}-{{(ds "config2" "foobar")}}`, - ) - result.Assert(c, icmd.Expected{ExitCode: 0, Out: "bar-baz"}) -} diff --git a/test/integration/datasources_consul_test.go b/test/integration/datasources_consul_test.go deleted file mode 100644 index f0c58f68..00000000 --- a/test/integration/datasources_consul_test.go +++ /dev/null @@ -1,208 +0,0 @@ -//+build integration -//+build !windows - -package integration - -import ( - "encoding/base64" - "io/ioutil" - "os" - "os/user" - "path" - "strconv" - - . "gopkg.in/check.v1" - - "github.com/gotestyourself/gotestyourself/fs" - "github.com/gotestyourself/gotestyourself/icmd" - vaultapi "github.com/hashicorp/vault/api" -) - -type ConsulDatasourcesSuite struct { - tmpDir *fs.Dir - pidDir *fs.Dir - consulAddr string - consulResult *icmd.Result - vaultAddr string - vaultResult *icmd.Result -} - -var _ = Suite(&ConsulDatasourcesSuite{}) - -const consulRootToken = "00000000-1111-2222-3333-444455556666" - -func (s *ConsulDatasourcesSuite) SetUpSuite(c *C) { - s.pidDir = fs.NewDir(c, "gomplate-inttests-pid") - s.tmpDir = fs.NewDir(c, "gomplate-inttests", - fs.WithFile( - "consul.json", - `{"acl_datacenter": "dc1", "acl_master_token": "`+consulRootToken+`"}`, - ), - fs.WithFile("vault.json", `{ - "pid_file": "`+s.pidDir.Join("vault.pid")+`" - }`), - ) - var port int - port, s.consulAddr = freeport() - consul := icmd.Command("consul", "agent", - "-dev", - "-config-file="+s.tmpDir.Join("consul.json"), - "-log-level=err", - "-http-port="+strconv.Itoa(port), - "-pid-file="+s.pidDir.Join("consul.pid"), - ) - s.consulResult = icmd.StartCmd(consul) - - c.Logf("Fired up Consul: %v", consul) - - err := waitForURL(c, "http://"+s.consulAddr+"/v1/status/leader") - handle(c, err) - - s.startVault(c) -} - -func (s *ConsulDatasourcesSuite) startVault(c *C) { - // rename any existing token so it doesn't get overridden - u, _ := user.Current() - homeDir := u.HomeDir - tokenFile := path.Join(homeDir, ".vault-token") - info, err := os.Stat(tokenFile) - if err == nil && info.Mode().IsRegular() { - os.Rename(tokenFile, path.Join(homeDir, ".vault-token.bak")) - } - - _, s.vaultAddr = freeport() - vault := icmd.Command("vault", "server", - "-dev", - "-dev-root-token-id="+vaultRootToken, - "-log-level=err", - "-dev-listen-address="+s.vaultAddr, - "-config="+s.tmpDir.Join("vault.json"), - ) - s.vaultResult = icmd.StartCmd(vault) - - c.Logf("Fired up Vault: %v", vault) - - err = waitForURL(c, "http://"+s.vaultAddr+"/v1/sys/health") - handle(c, err) -} - -func killByPidFile(pidFile string) error { - p, err := ioutil.ReadFile(pidFile) - if err != nil { - return err - } - pid, err := strconv.Atoi(string(p)) - if err != nil { - return err - } - process, err := os.FindProcess(pid) - if err != nil { - return err - } - err = process.Kill() - return err -} - -func (s *ConsulDatasourcesSuite) TearDownSuite(c *C) { - defer s.tmpDir.Remove() - defer s.pidDir.Remove() - - err := killByPidFile(s.pidDir.Join("vault.pid")) - handle(c, err) - - err = killByPidFile(s.pidDir.Join("consul.pid")) - handle(c, err) - - // restore old vault token if it was backed up - u, _ := user.Current() - homeDir := u.HomeDir - tokenFile := path.Join(homeDir, ".vault-token.bak") - info, err := os.Stat(tokenFile) - if err == nil && info.Mode().IsRegular() { - os.Rename(tokenFile, path.Join(homeDir, ".vault-token")) - } -} - -func (s *ConsulDatasourcesSuite) consulPut(c *C, k string, v string) { - result := icmd.RunCmd(icmd.Command("consul", "kv", "put", k, v), - func(c *icmd.Cmd) { - c.Env = []string{"CONSUL_HTTP_ADDR=http://" + s.consulAddr} - }) - result.Assert(c, icmd.Success) -} - -func (s *ConsulDatasourcesSuite) consulDelete(c *C, k string) { - result := icmd.RunCmd(icmd.Command("consul", "kv", "delete", k), - func(c *icmd.Cmd) { - c.Env = []string{"CONSUL_HTTP_ADDR=http://" + s.consulAddr} - }) - result.Assert(c, icmd.Success) -} - -func (s *ConsulDatasourcesSuite) TestConsulDatasource(c *C) { - s.consulPut(c, "foo", "bar") - defer s.consulDelete(c, "foo") - result := icmd.RunCmd(icmd.Command(GomplateBin, - "-d", "consul=consul://", - "-i", `{{(ds "consul" "foo")}}`, - ), func(c *icmd.Cmd) { - c.Env = []string{"CONSUL_HTTP_ADDR=http://" + s.consulAddr} - }) - result.Assert(c, icmd.Expected{ExitCode: 0, Out: "bar"}) - - s.consulPut(c, "foo", `{"bar": "baz"}`) - result = icmd.RunCmd(icmd.Command(GomplateBin, - "-d", "consul=consul://?type=application/json", - "-i", `{{(ds "consul" "foo").bar}}`, - ), func(c *icmd.Cmd) { - c.Env = []string{"CONSUL_HTTP_ADDR=http://" + s.consulAddr} - }) - result.Assert(c, icmd.Expected{ExitCode: 0, Out: "baz"}) - - s.consulPut(c, "foo", `bar`) - result = icmd.RunCmd(icmd.Command(GomplateBin, - "-d", "consul=consul://"+s.consulAddr, - "-i", `{{(ds "consul" "foo")}}`, - )) - result.Assert(c, icmd.Expected{ExitCode: 0, Out: "bar"}) - - s.consulPut(c, "foo", `bar`) - result = icmd.RunCmd(icmd.Command(GomplateBin, - "-d", "consul=consul+http://"+s.consulAddr, - "-i", `{{(ds "consul" "foo")}}`, - )) - result.Assert(c, icmd.Expected{ExitCode: 0, Out: "bar"}) -} - -func (s *ConsulDatasourcesSuite) TestConsulWithVaultAuth(c *C) { - v, err := createVaultClient(s.vaultAddr, vaultRootToken) - handle(c, err) - - err = v.vc.Sys().Mount("consul/", &vaultapi.MountInput{Type: "consul"}) - handle(c, err) - defer v.vc.Sys().Unmount("consul/") - - _, err = v.vc.Logical().Write("consul/config/access", map[string]interface{}{ - "address": s.consulAddr, "token": consulRootToken, - }) - handle(c, err) - policy := base64.StdEncoding.EncodeToString([]byte(`key "" { policy = "read" }`)) - _, err = v.vc.Logical().Write("consul/roles/readonly", map[string]interface{}{"policy": policy}) - handle(c, err) - - s.consulPut(c, "foo", "bar") - defer s.consulDelete(c, "foo") - result := icmd.RunCmd(icmd.Command(GomplateBin, - "-d", "consul=consul://", - "-i", `{{(ds "consul" "foo")}}`, - ), func(c *icmd.Cmd) { - c.Env = []string{ - "VAULT_TOKEN=" + vaultRootToken, - "VAULT_ADDR=http://" + s.vaultAddr, - "CONSUL_VAULT_ROLE=readonly", - "CONSUL_HTTP_ADDR=http://" + s.consulAddr, - } - }) - result.Assert(c, icmd.Expected{ExitCode: 0, Out: "bar"}) -} diff --git a/test/integration/datasources_env_test.go b/test/integration/datasources_env_test.go deleted file mode 100644 index 3b53c1e6..00000000 --- a/test/integration/datasources_env_test.go +++ /dev/null @@ -1,57 +0,0 @@ -//+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"}) -} diff --git a/test/integration/datasources_file_test.go b/test/integration/datasources_file_test.go deleted file mode 100644 index 97840031..00000000 --- a/test/integration/datasources_file_test.go +++ /dev/null @@ -1,87 +0,0 @@ -//+build integration -//+build !windows - -package integration - -import ( - . "gopkg.in/check.v1" - - "github.com/gotestyourself/gotestyourself/fs" - "github.com/gotestyourself/gotestyourself/icmd" -) - -type FileDatasourcesSuite struct { - tmpDir *fs.Dir -} - -var _ = Suite(&FileDatasourcesSuite{}) - -func (s *FileDatasourcesSuite) SetUpSuite(c *C) { - s.tmpDir = fs.NewDir(c, "gomplate-inttests", - fs.WithFile("config.json", `{"foo": {"bar": "baz"}}`), - fs.WithFile("config.yml", "foo:\n bar: baz\n"), - fs.WithFile("config2.yml", "foo: bar\n"), - fs.WithFile("foo.csv", `A,B -A1,B1 -A2,"foo"" -bar" -`), - ) -} - -func (s *FileDatasourcesSuite) TearDownSuite(c *C) { - s.tmpDir.Remove() -} - -func (s *FileDatasourcesSuite) TestFileDatasources(c *C) { - result := icmd.RunCommand(GomplateBin, - "-d", "config="+s.tmpDir.Join("config.json"), - "-i", `{{(datasource "config").foo.bar}}`, - ) - result.Assert(c, icmd.Expected{ExitCode: 0, Out: "baz"}) - - result = icmd.RunCommand(GomplateBin, - "-i", `{{defineDatasource "config" "`+s.tmpDir.Join("config.json")+`"}}{{(datasource "config").foo.bar}}`, - ) - result.Assert(c, icmd.Expected{ExitCode: 0, Out: "baz"}) - - result = icmd.RunCommand(GomplateBin, - "-d", "config="+s.tmpDir.Join("config.yml"), - "-i", `{{(datasource "config").foo.bar}}`, - ) - result.Assert(c, icmd.Expected{ExitCode: 0, Out: "baz"}) - - result = icmd.RunCommand(GomplateBin, - "-d", "config="+s.tmpDir.Join("config2.yml"), - "-i", `{{(ds "config").foo}}`, - ) - result.Assert(c, icmd.Expected{ExitCode: 0, Out: "bar"}) - - result = icmd.RunCommand(GomplateBin, - "-d", "config="+s.tmpDir.Join("config2.yml"), - "-i", `{{ if (datasourceReachable "bogus") }}bogus!{{ end -}} -{{ if (datasourceReachable "config") -}} -{{ (ds "config").foo -}} -{{ end }}`, - ) - result.Assert(c, icmd.Expected{ExitCode: 0, Out: "bar"}) - - result = icmd.RunCommand(GomplateBin, - "-d", "csv="+s.tmpDir.Join("foo.csv"), - "-i", `{{ index (index (ds "csv") 2) 1 }}`, - ) - result.Assert(c, icmd.Expected{ExitCode: 0, Out: `foo" -bar`}) - - result = icmd.RunCommand(GomplateBin, - "-d", "config="+s.tmpDir.Join("config2.yml"), - "-i", `{{ include "config" }}`, - ) - result.Assert(c, icmd.Expected{ExitCode: 0, Out: `foo: bar`}) - - result = icmd.RunCommand(GomplateBin, - "-d", "dir="+s.tmpDir.Path()+"/", - "-i", `{{ range (ds "dir") }}{{ . }} {{ end }}`, - ) - result.Assert(c, icmd.Expected{ExitCode: 0, Out: `config.json config.yml config2.yml foo.csv`}) -} diff --git a/test/integration/datasources_http_test.go b/test/integration/datasources_http_test.go deleted file mode 100644 index 0cfba68d..00000000 --- a/test/integration/datasources_http_test.go +++ /dev/null @@ -1,49 +0,0 @@ -//+build integration -//+build !windows - -package integration - -import ( - "net" - "net/http" - - . "gopkg.in/check.v1" - - "github.com/gotestyourself/gotestyourself/icmd" -) - -type DatasourcesHTTPSuite struct { - l *net.TCPListener -} - -var _ = Suite(&DatasourcesHTTPSuite{}) - -func (s *DatasourcesHTTPSuite) SetUpSuite(c *C) { - var err error - s.l, err = net.ListenTCP("tcp", &net.TCPAddr{IP: net.ParseIP("127.0.0.1")}) - handle(c, err) - - http.HandleFunc("/", mirrorHandler) - go http.Serve(s.l, nil) -} - -func (s *DatasourcesHTTPSuite) TearDownSuite(c *C) { - s.l.Close() -} - -func (s *DatasourcesHTTPSuite) TestReportsVersion(c *C) { - result := icmd.RunCommand(GomplateBin, - "-d", "foo=http://"+s.l.Addr().String()+"/", - "-H", "foo=Foo:bar", - "-i", "{{ index (ds `foo`).headers.Foo 0 }}") - result.Assert(c, icmd.Expected{ExitCode: 0, Out: "bar"}) - - result = icmd.RunCommand(GomplateBin, - "-H", "foo=Foo:bar", - "-i", "{{defineDatasource `foo` `http://"+s.l.Addr().String()+"/`}}{{ index (ds `foo`).headers.Foo 0 }}") - result.Assert(c, icmd.Expected{ExitCode: 0, Out: "bar"}) - - result = icmd.RunCommand(GomplateBin, - "-i", "{{ $d := ds `http://"+s.l.Addr().String()+"/`}}{{ index (index $d.headers `Accept-Encoding`) 0 }}") - result.Assert(c, icmd.Expected{ExitCode: 0, Out: "gzip"}) -} diff --git a/test/integration/datasources_vault_ec2_test.go b/test/integration/datasources_vault_ec2_test.go deleted file mode 100644 index cb7d57b5..00000000 --- a/test/integration/datasources_vault_ec2_test.go +++ /dev/null @@ -1,122 +0,0 @@ -//+build integration -//+build !windows - -package integration - -import ( - "encoding/pem" - "io/ioutil" - "net" - "net/http" - "os" - "os/user" - "path" - "strconv" - - . "gopkg.in/check.v1" - - "github.com/gotestyourself/gotestyourself/fs" - "github.com/gotestyourself/gotestyourself/icmd" -) - -type VaultEc2DatasourcesSuite struct { - tmpDir *fs.Dir - pidDir *fs.Dir - vaultAddr string - vaultResult *icmd.Result - v *vaultClient - l *net.TCPListener - cert []byte -} - -var _ = Suite(&VaultEc2DatasourcesSuite{}) - -func (s *VaultEc2DatasourcesSuite) SetUpSuite(c *C) { - var err error - s.l, err = net.ListenTCP("tcp", &net.TCPAddr{IP: net.ParseIP("127.0.0.1")}) - handle(c, err) - priv, der, _ := certificateGenerate() - s.cert = pem.EncodeToMemory(&pem.Block{Type: "CERTIFICATE", Bytes: der}) - http.HandleFunc("/latest/dynamic/instance-identity/pkcs7", pkcsHandler(priv, der)) - http.HandleFunc("/latest/dynamic/instance-identity/document", instanceDocumentHandler) - http.HandleFunc("/sts/", stsHandler) - http.HandleFunc("/ec2/", ec2Handler) - go http.Serve(s.l, nil) - - s.pidDir, s.tmpDir, s.vaultAddr, s.vaultResult = startVault(c) - - s.v, err = createVaultClient(s.vaultAddr, vaultRootToken) - handle(c, err) - - err = s.v.vc.Sys().PutPolicy("writepol", `path "*" { - policy = "write" -}`) - handle(c, err) - err = s.v.vc.Sys().PutPolicy("readpol", `path "*" { - policy = "read" -}`) - handle(c, err) -} - -func (s *VaultEc2DatasourcesSuite) TearDownSuite(c *C) { - s.l.Close() - - defer s.tmpDir.Remove() - defer s.pidDir.Remove() - - p, err := ioutil.ReadFile(s.pidDir.Join("vault.pid")) - handle(c, err) - pid, err := strconv.Atoi(string(p)) - handle(c, err) - process, err := os.FindProcess(pid) - handle(c, err) - err = process.Kill() - handle(c, err) - - // restore old token if it was backed up - u, _ := user.Current() - homeDir := u.HomeDir - tokenFile := path.Join(homeDir, ".vault-token.bak") - info, err := os.Stat(tokenFile) - if err == nil && info.Mode().IsRegular() { - os.Rename(tokenFile, path.Join(homeDir, ".vault-token")) - } -} - -func (s *VaultEc2DatasourcesSuite) TestEc2Auth(c *C) { - s.v.vc.Logical().Write("secret/foo", map[string]interface{}{"value": "bar"}) - defer s.v.vc.Logical().Delete("secret/foo") - err := s.v.vc.Sys().EnableAuth("aws", "aws", "") - handle(c, err) - defer s.v.vc.Sys().DisableAuth("aws") - _, err = s.v.vc.Logical().Write("auth/aws/config/client", map[string]interface{}{ - "secret_key": "secret", "access_key": "access", - "endpoint": "http://" + s.l.Addr().String() + "/ec2", - "iam_endpoint": "http://" + s.l.Addr().String() + "/iam", - "sts_endpoint": "http://" + s.l.Addr().String() + "/sts", - }) - handle(c, err) - - _, err = s.v.vc.Logical().Write("auth/aws/config/certificate/testcert", map[string]interface{}{ - "type": "pkcs7", "aws_public_cert": string(s.cert), - }) - handle(c, err) - - _, err = s.v.vc.Logical().Write("auth/aws/role/ami-00000000", map[string]interface{}{ - "auth_type": "ec2", "bound_ami_id": "ami-00000000", - "policies": "readpol", - }) - handle(c, err) - - result := icmd.RunCmd(icmd.Command(GomplateBin, - "-d", "vault=vault:///secret", - "-i", `{{(ds "vault" "foo").value}}`, - ), func(c *icmd.Cmd) { - c.Env = []string{ - "HOME=" + s.tmpDir.Join("home"), - "VAULT_ADDR=http://" + s.v.addr, - "AWS_META_ENDPOINT=http://" + s.l.Addr().String(), - } - }) - result.Assert(c, icmd.Expected{ExitCode: 0, Out: "bar"}) -} diff --git a/test/integration/datasources_vault_test.go b/test/integration/datasources_vault_test.go deleted file mode 100644 index ca682228..00000000 --- a/test/integration/datasources_vault_test.go +++ /dev/null @@ -1,395 +0,0 @@ -//+build integration -//+build !windows - -package integration - -import ( - "io/ioutil" - "os" - "os/user" - "path" - "strconv" - - . "gopkg.in/check.v1" - - "github.com/gotestyourself/gotestyourself/fs" - "github.com/gotestyourself/gotestyourself/icmd" - vaultapi "github.com/hashicorp/vault/api" -) - -type VaultDatasourcesSuite struct { - tmpDir *fs.Dir - pidDir *fs.Dir - vaultAddr string - vaultResult *icmd.Result - v *vaultClient -} - -var _ = Suite(&VaultDatasourcesSuite{}) - -const vaultRootToken = "00000000-1111-2222-3333-444455556666" - -func (s *VaultDatasourcesSuite) SetUpSuite(c *C) { - s.pidDir, s.tmpDir, s.vaultAddr, s.vaultResult = startVault(c) - - var err error - s.v, err = createVaultClient(s.vaultAddr, vaultRootToken) - handle(c, err) - - err = s.v.vc.Sys().PutPolicy("writepol", `path "*" { - capabilities = ["create","update","delete"] -}`) - handle(c, err) - err = s.v.vc.Sys().PutPolicy("readpol", `path "*" { - capabilities = ["read","delete"] -}`) - handle(c, err) - err = s.v.vc.Sys().PutPolicy("listPol", `path "*" { - capabilities = ["read","list","delete"] -}`) - handle(c, err) -} - -func startVault(c *C) (pidDir, tmpDir *fs.Dir, vaultAddr string, vaultResult *icmd.Result) { - pidDir = fs.NewDir(c, "gomplate-inttests-vaultpid") - tmpDir = fs.NewDir(c, "gomplate-inttests", - fs.WithFile("config.json", `{ - "pid_file": "`+pidDir.Join("vault.pid")+`" - }`), - ) - - // rename any existing token so it doesn't get overridden - u, _ := user.Current() - homeDir := u.HomeDir - tokenFile := path.Join(homeDir, ".vault-token") - info, err := os.Stat(tokenFile) - if err == nil && info.Mode().IsRegular() { - os.Rename(tokenFile, path.Join(homeDir, ".vault-token.bak")) - } - - _, vaultAddr = freeport() - vault := icmd.Command("vault", "server", - "-dev", - "-dev-root-token-id="+vaultRootToken, - "-dev-leased-kv", - "-log-level=err", - "-dev-listen-address="+vaultAddr, - "-config="+tmpDir.Join("config.json"), - ) - vaultResult = icmd.StartCmd(vault) - - c.Logf("Fired up Vault: %v", vault) - - err = waitForURL(c, "http://"+vaultAddr+"/v1/sys/health") - handle(c, err) - - return pidDir, tmpDir, vaultAddr, vaultResult -} - -func (s *VaultDatasourcesSuite) TearDownSuite(c *C) { - defer s.tmpDir.Remove() - defer s.pidDir.Remove() - - p, err := ioutil.ReadFile(s.pidDir.Join("vault.pid")) - handle(c, err) - pid, err := strconv.Atoi(string(p)) - handle(c, err) - process, err := os.FindProcess(pid) - handle(c, err) - err = process.Kill() - handle(c, err) - - // restore old token if it was backed up - u, _ := user.Current() - homeDir := u.HomeDir - tokenFile := path.Join(homeDir, ".vault-token.bak") - info, err := os.Stat(tokenFile) - if err == nil && info.Mode().IsRegular() { - os.Rename(tokenFile, path.Join(homeDir, ".vault-token")) - } -} - -func (s *VaultDatasourcesSuite) TestTokenAuth(c *C) { - s.v.vc.Logical().Write("secret/foo", map[string]interface{}{"value": "bar"}) - defer s.v.vc.Logical().Delete("secret/foo") - tok, err := s.v.tokenCreate("readpol", 5) - handle(c, err) - - result := icmd.RunCmd(icmd.Command(GomplateBin, - "-d", "vault=vault:///secret", - "-i", `{{(ds "vault" "foo").value}}`, - ), func(c *icmd.Cmd) { - c.Env = []string{ - "VAULT_ADDR=http://" + s.v.addr, - "VAULT_TOKEN=" + tok, - } - }) - result.Assert(c, icmd.Expected{ExitCode: 0, Out: "bar"}) - - result = icmd.RunCmd(icmd.Command(GomplateBin, - "-d", "vault=vault+http://"+s.v.addr+"/secret", - "-i", `{{(ds "vault" "foo").value}}`, - ), func(c *icmd.Cmd) { - c.Env = []string{ - "VAULT_TOKEN=" + tok, - } - }) - result.Assert(c, icmd.Expected{ExitCode: 0, Out: "bar"}) - - result = icmd.RunCmd(icmd.Command(GomplateBin, - "-d", "vault=vault:///secret", - "-i", `{{(ds "vault" "bar").value}}`, - ), func(c *icmd.Cmd) { - c.Env = []string{ - "VAULT_ADDR=http://" + s.v.addr, - "VAULT_TOKEN=" + tok, - } - }) - result.Assert(c, icmd.Expected{ExitCode: 1, Err: "error calling ds: Couldn't read datasource 'vault': no value found for path /secret/bar"}) - - tokFile := fs.NewFile(c, "test-vault-token", fs.WithContent(tok)) - defer tokFile.Remove() - result = icmd.RunCmd(icmd.Command(GomplateBin, - "-d", "vault=vault:///secret", - "-i", `{{(ds "vault" "foo").value}}`, - ), func(c *icmd.Cmd) { - c.Env = []string{ - "VAULT_ADDR=http://" + s.v.addr, - "VAULT_TOKEN_FILE=" + tokFile.Path(), - } - }) - result.Assert(c, icmd.Expected{ExitCode: 0, Out: "bar"}) -} - -func (s *VaultDatasourcesSuite) TestUserPassAuth(c *C) { - s.v.vc.Logical().Write("secret/foo", map[string]interface{}{"value": "bar"}) - defer s.v.vc.Logical().Delete("secret/foo") - err := s.v.vc.Sys().EnableAuth("userpass", "userpass", "") - handle(c, err) - err = s.v.vc.Sys().EnableAuth("userpass2", "userpass", "") - handle(c, err) - defer s.v.vc.Sys().DisableAuth("userpass") - defer s.v.vc.Sys().DisableAuth("userpass2") - _, err = s.v.vc.Logical().Write("auth/userpass/users/dave", map[string]interface{}{ - "password": "foo", "ttl": "10s", "policies": "readpol"}) - handle(c, err) - _, err = s.v.vc.Logical().Write("auth/userpass2/users/dave", map[string]interface{}{ - "password": "bar", "ttl": "10s", "policies": "readpol"}) - handle(c, err) - - result := icmd.RunCmd(icmd.Command(GomplateBin, - "-d", "vault=vault:///secret", - "-i", `{{(ds "vault" "foo").value}}`, - ), func(c *icmd.Cmd) { - c.Env = []string{ - "VAULT_ADDR=http://" + s.v.addr, - "VAULT_AUTH_USERNAME=dave", "VAULT_AUTH_PASSWORD=foo", - } - }) - result.Assert(c, icmd.Expected{ExitCode: 0, Out: "bar"}) - - userFile := fs.NewFile(c, "test-vault-user", fs.WithContent("dave")) - passFile := fs.NewFile(c, "test-vault-pass", fs.WithContent("foo")) - defer userFile.Remove() - defer passFile.Remove() - result = icmd.RunCmd(icmd.Command(GomplateBin, - "-d", "vault=vault:///secret", - "-i", `{{(ds "vault" "foo").value}}`, - ), func(c *icmd.Cmd) { - c.Env = []string{ - "VAULT_ADDR=http://" + s.v.addr, - "VAULT_AUTH_USERNAME_FILE=" + userFile.Path(), - "VAULT_AUTH_PASSWORD_FILE=" + passFile.Path(), - } - }) - result.Assert(c, icmd.Expected{ExitCode: 0, Out: "bar"}) - - result = icmd.RunCmd(icmd.Command(GomplateBin, - "-d", "vault=vault:///secret", - "-i", `{{(ds "vault" "foo").value}}`, - ), func(c *icmd.Cmd) { - c.Env = []string{ - "VAULT_ADDR=http://" + s.v.addr, - "VAULT_AUTH_USERNAME=dave", "VAULT_AUTH_PASSWORD=bar", - "VAULT_AUTH_USERPASS_MOUNT=userpass2", - } - }) - result.Assert(c, icmd.Expected{ExitCode: 0, Out: "bar"}) -} - -func (s *VaultDatasourcesSuite) TestAppRoleAuth(c *C) { - s.v.vc.Logical().Write("secret/foo", map[string]interface{}{"value": "bar"}) - defer s.v.vc.Logical().Delete("secret/foo") - err := s.v.vc.Sys().EnableAuth("approle", "approle", "") - handle(c, err) - err = s.v.vc.Sys().EnableAuth("approle2", "approle", "") - handle(c, err) - defer s.v.vc.Sys().DisableAuth("approle") - defer s.v.vc.Sys().DisableAuth("approle2") - _, err = s.v.vc.Logical().Write("auth/approle/role/testrole", map[string]interface{}{ - "secret_id_ttl": "10s", "token_ttl": "20s", - "secret_id_num_uses": "1", "policies": "readpol", - }) - handle(c, err) - _, err = s.v.vc.Logical().Write("auth/approle2/role/testrole", map[string]interface{}{ - "secret_id_ttl": "10s", "token_ttl": "20s", - "secret_id_num_uses": "1", "policies": "readpol", - }) - handle(c, err) - - rid, _ := s.v.vc.Logical().Read("auth/approle/role/testrole/role-id") - roleID := rid.Data["role_id"].(string) - sid, _ := s.v.vc.Logical().Write("auth/approle/role/testrole/secret-id", nil) - secretID := sid.Data["secret_id"].(string) - result := icmd.RunCmd(icmd.Command(GomplateBin, - "-d", "vault=vault:///secret", - "-i", `{{(ds "vault" "foo").value}}`, - ), func(c *icmd.Cmd) { - c.Env = []string{ - "VAULT_ADDR=http://" + s.v.addr, - "VAULT_ROLE_ID=" + roleID, - "VAULT_SECRET_ID=" + secretID, - } - }) - result.Assert(c, icmd.Expected{ExitCode: 0, Out: "bar"}) - - rid, _ = s.v.vc.Logical().Read("auth/approle2/role/testrole/role-id") - roleID = rid.Data["role_id"].(string) - sid, _ = s.v.vc.Logical().Write("auth/approle2/role/testrole/secret-id", nil) - secretID = sid.Data["secret_id"].(string) - result = icmd.RunCmd(icmd.Command(GomplateBin, - "-d", "vault=vault:///secret", - "-i", `{{(ds "vault" "foo").value}}`, - ), func(c *icmd.Cmd) { - c.Env = []string{ - "VAULT_ADDR=http://" + s.v.addr, - "VAULT_ROLE_ID=" + roleID, - "VAULT_SECRET_ID=" + secretID, - "VAULT_AUTH_APPROLE_MOUNT=approle2", - } - }) - result.Assert(c, icmd.Expected{ExitCode: 0, Out: "bar"}) -} - -func (s *VaultDatasourcesSuite) TestAppIDAuth(c *C) { - s.v.vc.Logical().Write("secret/foo", map[string]interface{}{"value": "bar"}) - defer s.v.vc.Logical().Delete("secret/foo") - err := s.v.vc.Sys().EnableAuth("app-id", "app-id", "") - handle(c, err) - err = s.v.vc.Sys().EnableAuth("app-id2", "app-id", "") - handle(c, err) - defer s.v.vc.Sys().DisableAuth("app-id") - defer s.v.vc.Sys().DisableAuth("app-id2") - _, err = s.v.vc.Logical().Write("auth/app-id/map/app-id/testappid", map[string]interface{}{ - "display_name": "test_app_id", "value": "readpol", - }) - handle(c, err) - _, err = s.v.vc.Logical().Write("auth/app-id/map/user-id/testuserid", map[string]interface{}{ - "value": "testappid", - }) - handle(c, err) - _, err = s.v.vc.Logical().Write("auth/app-id2/map/app-id/testappid", map[string]interface{}{ - "display_name": "test_app_id", "value": "readpol", - }) - handle(c, err) - _, err = s.v.vc.Logical().Write("auth/app-id2/map/user-id/testuserid", map[string]interface{}{ - "value": "testappid", - }) - handle(c, err) - - result := icmd.RunCmd(icmd.Command(GomplateBin, - "-d", "vault=vault:///secret", - "-i", `{{(ds "vault" "foo").value}}`, - ), func(c *icmd.Cmd) { - c.Env = []string{ - "VAULT_ADDR=http://" + s.v.addr, - "VAULT_APP_ID=testappid", - "VAULT_USER_ID=testuserid", - } - }) - result.Assert(c, icmd.Expected{ExitCode: 0, Out: "bar"}) - - result = icmd.RunCmd(icmd.Command(GomplateBin, - "-d", "vault=vault:///secret", - "-i", `{{(ds "vault" "foo").value}}`, - ), func(c *icmd.Cmd) { - c.Env = []string{ - "VAULT_ADDR=http://" + s.v.addr, - "VAULT_APP_ID=testappid", - "VAULT_USER_ID=testuserid", - "VAULT_AUTH_APP_ID_MOUNT=app-id2", - } - }) - result.Assert(c, icmd.Expected{ExitCode: 0, Out: "bar"}) -} - -func (s *VaultDatasourcesSuite) TestDynamicAuth(c *C) { - err := s.v.vc.Sys().Mount("ssh/", &vaultapi.MountInput{Type: "ssh"}) - handle(c, err) - defer s.v.vc.Sys().Unmount("ssh") - - _, err = s.v.vc.Logical().Write("ssh/roles/test", map[string]interface{}{ - "key_type": "otp", "default_user": "user", "cidr_list": "10.0.0.0/8", - }) - handle(c, err) - testCommands := []icmd.Cmd{ - icmd.Command(GomplateBin, - "-d", "vault=vault:///", - "-i", `{{(ds "vault" "ssh/creds/test?ip=10.1.2.3&username=user").ip}}`, - ), - icmd.Command(GomplateBin, - "-d", "vault=vault:///ssh/creds/test", - "-i", `{{(ds "vault" "?ip=10.1.2.3&username=user").ip}}`, - ), - icmd.Command(GomplateBin, - "-d", "vault=vault:///ssh/creds/test?ip=10.1.2.3&username=user", - "-i", `{{(ds "vault").ip}}`, - ), - icmd.Command(GomplateBin, - "-d", "vault=vault:///?ip=10.1.2.3&username=user", - "-i", `{{(ds "vault" "ssh/creds/test").ip}}`, - ), - } - tok, err := s.v.tokenCreate("writepol", len(testCommands)*2) - handle(c, err) - - for _, v := range testCommands { - result := icmd.RunCmd(v, func(c *icmd.Cmd) { - c.Env = []string{ - "VAULT_ADDR=http://" + s.v.addr, - "VAULT_TOKEN=" + tok, - } - }) - result.Assert(c, icmd.Expected{ExitCode: 0, Out: "10.1.2.3"}) - } -} - -func (s *VaultDatasourcesSuite) TestList(c *C) { - s.v.vc.Logical().Write("secret/dir/foo", map[string]interface{}{"value": "one"}) - s.v.vc.Logical().Write("secret/dir/bar", map[string]interface{}{"value": "two"}) - defer s.v.vc.Logical().Delete("secret/dir/foo") - defer s.v.vc.Logical().Delete("secret/dir/bar") - tok, err := s.v.tokenCreate("listpol", 5) - handle(c, err) - - result := icmd.RunCmd(icmd.Command(GomplateBin, - "-d", "vault=vault:///secret/dir/", - "-i", `{{ range (ds "vault" ) }}{{ . }}: {{ (ds "vault" .).value }} {{end}}`, - ), func(c *icmd.Cmd) { - c.Env = []string{ - "VAULT_ADDR=http://" + s.v.addr, - "VAULT_TOKEN=" + tok, - } - }) - result.Assert(c, icmd.Expected{ExitCode: 0, Out: "bar: two foo: one"}) - - result = icmd.RunCmd(icmd.Command(GomplateBin, - "-d", "vault=vault+http://"+s.v.addr+"/secret", - "-i", `{{ range (ds "vault" "dir/" ) }}{{ . }} {{end}}`, - ), func(c *icmd.Cmd) { - c.Env = []string{ - "VAULT_TOKEN=" + tok, - } - }) - result.Assert(c, icmd.Expected{ExitCode: 0, Out: "bar foo"}) -} diff --git a/test/integration/envvars_test.go b/test/integration/envvars_test.go deleted file mode 100644 index 4fae1942..00000000 --- a/test/integration/envvars_test.go +++ /dev/null @@ -1,60 +0,0 @@ -//+build integration -//+build !windows - -package integration - -import ( - . "gopkg.in/check.v1" - - "github.com/gotestyourself/gotestyourself/icmd" -) - -type EnvvarsSuite struct{} - -var _ = Suite(&EnvvarsSuite{}) - -func (s *EnvvarsSuite) TestNonExistantEnvVar(c *C) { - result := icmd.RunCommand(GomplateBin, "-i", - `{{ .Env.FOO }}`) - result.Assert(c, icmd.Expected{ExitCode: 1, Err: "map has no entry for key"}) - - result = icmd.RunCommand(GomplateBin, "-i", - `{{ getenv "FOO" }}`) - result.Assert(c, icmd.Expected{ExitCode: 0, Out: ""}) - - result = icmd.RunCommand(GomplateBin, "-i", - `{{ getenv "FOO" "foo" }}`) - result.Assert(c, icmd.Expected{ExitCode: 0, Out: "foo"}) - - result = icmd.RunCommand(GomplateBin, "-i", - `{{env.ExpandEnv "${BAR}foo"}}`) - result.Assert(c, icmd.Expected{ExitCode: 0, Out: "foo"}) - - result = icmd.RunCmd(icmd.Command(GomplateBin, "-i", `{{ getenv "FOO" "foo" }}`), - func(c *icmd.Cmd) { - c.Env = []string{"FOO="} - }) - result.Assert(c, icmd.Expected{ExitCode: 0, Out: "foo"}) -} - -func (s *EnvvarsSuite) TestExistantEnvVar(c *C) { - setFoo := func(c *icmd.Cmd) { - c.Env = []string{"FOO=foo"} - } - expected := icmd.Expected{ExitCode: 0, Out: "foo"} - result := icmd.RunCmd(icmd.Command(GomplateBin, "-i", - `{{ .Env.FOO }}`), setFoo) - result.Assert(c, expected) - - result = icmd.RunCmd(icmd.Command(GomplateBin, "-i", - `{{ getenv "FOO" }}`), setFoo) - result.Assert(c, expected) - - result = icmd.RunCmd(icmd.Command(GomplateBin, "-i", - `{{ env.Getenv "FOO" }}`), setFoo) - result.Assert(c, expected) - - result = icmd.RunCmd(icmd.Command(GomplateBin, "-i", - `{{env.ExpandEnv "${FOO}"}}`), setFoo) - result.Assert(c, expected) -} diff --git a/test/integration/file_test.go b/test/integration/file_test.go deleted file mode 100644 index 2685df73..00000000 --- a/test/integration/file_test.go +++ /dev/null @@ -1,30 +0,0 @@ -//+build integration -//+build !windows - -package integration - -import ( - . "gopkg.in/check.v1" - - "github.com/gotestyourself/gotestyourself/fs" -) - -type FileSuite struct { - tmpDir *fs.Dir -} - -var _ = Suite(&FileSuite{}) - -func (s *FileSuite) SetUpSuite(c *C) { - s.tmpDir = fs.NewDir(c, "gomplate-inttests", - fs.WithFile("one", "hi\n"), - fs.WithFile("two", "hello\n")) -} - -func (s *FileSuite) TearDownSuite(c *C) { - s.tmpDir.Remove() -} - -func (s *FileSuite) TestReadsFile(c *C) { - inOutTest(c, `{{ file.Read "`+s.tmpDir.Join("one")+`"}}`, "hi") -} diff --git a/test/integration/inputdir_test.go b/test/integration/inputdir_test.go deleted file mode 100644 index 6c0bbf88..00000000 --- a/test/integration/inputdir_test.go +++ /dev/null @@ -1,104 +0,0 @@ -//+build integration -//+build !windows - -package integration - -import ( - "io/ioutil" - - . "gopkg.in/check.v1" - - "github.com/gotestyourself/gotestyourself/assert" - "github.com/gotestyourself/gotestyourself/fs" - "github.com/gotestyourself/gotestyourself/icmd" - tassert "github.com/stretchr/testify/assert" -) - -type InputDirSuite struct { - tmpDir *fs.Dir -} - -var _ = Suite(&InputDirSuite{}) - -func (s *InputDirSuite) SetUpTest(c *C) { - s.tmpDir = fs.NewDir(c, "gomplate-inttests", - fs.WithFile("config.yml", "one: eins\ntwo: deux\n"), - fs.WithDir("in", - fs.WithFile("eins.txt", `{{ (ds "config").one }}`), - fs.WithDir("inner", - fs.WithFile("deux.txt", `{{ (ds "config").two }}`), - ), - ), - fs.WithDir("out"), - fs.WithDir("bad_in", - fs.WithFile("bad.tmpl", "{{end}}"), - ), - ) -} - -func (s *InputDirSuite) TearDownTest(c *C) { - s.tmpDir.Remove() -} - -func (s *InputDirSuite) TestInputDir(c *C) { - result := icmd.RunCommand(GomplateBin, - "--input-dir", s.tmpDir.Join("in"), - "--output-dir", s.tmpDir.Join("out"), - "-d", "config="+s.tmpDir.Join("config.yml"), - ) - result.Assert(c, icmd.Success) - - files, err := ioutil.ReadDir(s.tmpDir.Join("out")) - assert.NilError(c, err) - tassert.Len(c, files, 2) - - files, err = ioutil.ReadDir(s.tmpDir.Join("out", "inner")) - assert.NilError(c, err) - tassert.Len(c, files, 1) - - content, err := ioutil.ReadFile(s.tmpDir.Join("out", "eins.txt")) - assert.NilError(c, err) - assert.Equal(c, "eins", string(content)) - - content, err = ioutil.ReadFile(s.tmpDir.Join("out", "inner", "deux.txt")) - assert.NilError(c, err) - assert.Equal(c, "deux", string(content)) -} - -func (s *InputDirSuite) TestDefaultOutputDir(c *C) { - result := icmd.RunCmd(icmd.Command(GomplateBin, - "--input-dir", s.tmpDir.Join("in"), - "-d", "config="+s.tmpDir.Join("config.yml"), - ), func(c *icmd.Cmd) { - c.Dir = s.tmpDir.Join("out") - }) - result.Assert(c, icmd.Success) - - files, err := ioutil.ReadDir(s.tmpDir.Join("out")) - assert.NilError(c, err) - tassert.Len(c, files, 2) - - files, err = ioutil.ReadDir(s.tmpDir.Join("out", "inner")) - assert.NilError(c, err) - tassert.Len(c, files, 1) - - content, err := ioutil.ReadFile(s.tmpDir.Join("out", "eins.txt")) - assert.NilError(c, err) - assert.Equal(c, "eins", string(content)) - - content, err = ioutil.ReadFile(s.tmpDir.Join("out", "inner", "deux.txt")) - assert.NilError(c, err) - assert.Equal(c, "deux", string(content)) -} - -func (s *InputDirSuite) TestReportsFilenameWithBadInputFile(c *C) { - result := icmd.RunCommand(GomplateBin, - "--input-dir", s.tmpDir.Join("bad_in"), - "--output-dir", s.tmpDir.Join("out"), - "-d", "config="+s.tmpDir.Join("config.yml"), - ) - result.Assert(c, icmd.Expected{ - ExitCode: 1, - Out: "template: " + s.tmpDir.Join("bad_in", "bad.tmpl") + ":1: unexpected {{end}}", - }) -} diff --git a/test/integration/integration.go b/test/integration/integration.go deleted file mode 100644 index 76ab1b72..00000000 --- a/test/integration/integration.go +++ /dev/null @@ -1 +0,0 @@ -package integration diff --git a/test/integration/integration_test.go b/test/integration/integration_test.go deleted file mode 100644 index 5fde906d..00000000 --- a/test/integration/integration_test.go +++ /dev/null @@ -1,122 +0,0 @@ -package integration - -import ( - "encoding/json" - "go/build" - "io/ioutil" - "log" - "net" - "net/http" - "testing" - "time" - - "github.com/gotestyourself/gotestyourself/icmd" - vaultapi "github.com/hashicorp/vault/api" - . "gopkg.in/check.v1" -) - -var ( - GomplateBin = build.Default.GOPATH + "/src/github.com/hairyhenderson/gomplate/bin/gomplate" -) - -// Hook up gocheck into the "go test" runner. -func Test(t *testing.T) { TestingT(t) } - -// a convenience... -func inOutTest(c *C, i string, o string) { - result := icmd.RunCommand(GomplateBin, "-i", i) - result.Assert(c, icmd.Expected{ExitCode: 0, Out: o}) -} - -func handle(c *C, err error) { - if err != nil { - c.Fatal(err) - } -} - -// mirrorHandler - reflects back the HTTP headers from the request -func mirrorHandler(w http.ResponseWriter, r *http.Request) { - type Req struct { - Headers http.Header `json:"headers"` - } - req := Req{r.Header} - b, err := json.Marshal(req) - if err != nil { - log.Println(err) - w.WriteHeader(http.StatusBadRequest) - } - w.Header().Set("Content-Type", "application/json") - w.Write(b) -} - -// freeport - find a free TCP port for immediate use. No guarantees! -func freeport() (port int, addr string) { - l, err := net.ListenTCP("tcp", &net.TCPAddr{IP: net.ParseIP("127.0.0.1")}) - if err != nil { - panic(err) - } - defer l.Close() - a := l.Addr().(*net.TCPAddr) - port = a.Port - return port, a.String() -} - -// waitForURL - waits up to 20s for a given URL to respond with a 200 -func waitForURL(c *C, url string) error { - client := http.DefaultClient - retries := 100 - for retries > 0 { - retries-- - time.Sleep(200 * time.Millisecond) - resp, err := client.Get(url) - if err != nil { - c.Logf("Got error, retries left: %d (error: %v)", retries, err) - continue - } - body, err := ioutil.ReadAll(resp.Body) - c.Logf("Body is: %s", body) - if err != nil { - return err - } - defer resp.Body.Close() - if resp.StatusCode == 200 { - return nil - } - } - return nil -} - -type vaultClient struct { - addr string - rootToken string - vc *vaultapi.Client -} - -func createVaultClient(addr string, rootToken string) (*vaultClient, error) { - config := vaultapi.DefaultConfig() - config.Address = "http://" + addr - client, err := vaultapi.NewClient(config) - if err != nil { - return nil, err - } - v := &vaultClient{ - addr: addr, - rootToken: rootToken, - vc: client, - } - client.SetToken(rootToken) - return v, nil -} - -func (v *vaultClient) tokenCreate(policy string, uses int) (string, error) { - opts := &vaultapi.TokenCreateRequest{ - Policies: []string{policy}, - TTL: "1m", - NumUses: uses, - } - token, err := v.vc.Auth().Token().Create(opts) - if err != nil { - return "", err - } - return token.Auth.ClientToken, nil -} diff --git a/test/integration/math_test.go b/test/integration/math_test.go deleted file mode 100644 index 238993a4..00000000 --- a/test/integration/math_test.go +++ /dev/null @@ -1,27 +0,0 @@ -//+build integration -//+build !windows - -package integration - -import ( - . "gopkg.in/check.v1" -) - -type MathSuite struct{} - -var _ = Suite(&MathSuite{}) - -func (s *MathSuite) TestMath(c *C) { - inOutTest(c, `{{ math.Add 1 2 3 4 }} {{ add -5 5 }}`, "10 0") - inOutTest(c, `{{ math.Sub 10 5 }} {{ sub -5 5 }}`, "5 -10") - inOutTest(c, `{{ math.Mul 1 2 3 4 }} {{ mul -5 5 }}`, "24 -25") - inOutTest(c, `{{ math.Div 5 2 }} {{ div -5 5 }}`, "2.5 -1") - inOutTest(c, `{{ math.Rem 5 3 }} {{ rem 2 2 }}`, "2 0") - inOutTest(c, `{{ math.Pow 8 4 }} {{ pow 2 2 }}`, "4096 4") - inOutTest(c, `{{ math.Seq 0 }}, {{ seq 0 3 }}, {{ seq -5 -10 2 }}`, - `[1 0], [0 1 2 3], [-5 -7 -9]`) - inOutTest(c, `{{ math.Round 0.99 }}, {{ math.Round "foo" }}, {{math.Round 3.5}}`, - `1, 0, 4`) - inOutTest(c, `{{ math.Max -0 "+Inf" "NaN" }}, {{ math.Max 3.4 3.401 3.399 }}`, - `+Inf, 3.401`) -} diff --git a/test/integration/net_test.go b/test/integration/net_test.go deleted file mode 100644 index dc9f1f76..00000000 --- a/test/integration/net_test.go +++ /dev/null @@ -1,19 +0,0 @@ -//+build integration -//+build !windows - -package integration - -import ( - . "gopkg.in/check.v1" - - "github.com/gotestyourself/gotestyourself/icmd" -) - -type NetSuite struct{} - -var _ = Suite(&NetSuite{}) - -func (s *NetSuite) TestLookupIP(c *C) { - result := icmd.RunCommand(GomplateBin, "-i", `{{ net.LookupIP "localhost" }}`) - result.Assert(c, icmd.Expected{ExitCode: 0, Out: "127.0.0.1"}) -} diff --git a/test/integration/regexp_test.go b/test/integration/regexp_test.go deleted file mode 100644 index c476877f..00000000 --- a/test/integration/regexp_test.go +++ /dev/null @@ -1,20 +0,0 @@ -//+build integration -//+build !windows - -package integration - -import ( - . "gopkg.in/check.v1" - - "github.com/gotestyourself/gotestyourself/icmd" -) - -type RegexpSuite struct{} - -var _ = Suite(&RegexpSuite{}) - -func (s *RegexpSuite) TestReplace(c *C) { - result := icmd.RunCommand(GomplateBin, "-i", - `{{ "1.2.3-59" | regexp.Replace "-([0-9]*)" ".$1" }}`) - result.Assert(c, icmd.Expected{ExitCode: 0, Out: "1.2.3.59"}) -} diff --git a/test/integration/sockaddr_test.go b/test/integration/sockaddr_test.go deleted file mode 100644 index f3b2efb9..00000000 --- a/test/integration/sockaddr_test.go +++ /dev/null @@ -1,22 +0,0 @@ -//+build integration -//+build !windows - -package integration - -import ( - . "gopkg.in/check.v1" - - "github.com/gotestyourself/gotestyourself/icmd" -) - -type SockaddrSuite struct{} - -var _ = Suite(&SockaddrSuite{}) - -func (s *SockaddrSuite) TestSockaddr(c *C) { - result := icmd.RunCommand(GomplateBin, "-i", - `{{ range (sockaddr.GetAllInterfaces | sockaddr.Include "type" "ipv4") -}} -{{ . | sockaddr.Attr "address" }} -{{end}}`) - result.Assert(c, icmd.Expected{ExitCode: 0, Out: "127.0.0.1"}) -} diff --git a/test/integration/strings_test.go b/test/integration/strings_test.go deleted file mode 100644 index c8843de5..00000000 --- a/test/integration/strings_test.go +++ /dev/null @@ -1,51 +0,0 @@ -//+build integration -//+build !windows - -package integration - -import ( - . "gopkg.in/check.v1" - - "github.com/gotestyourself/gotestyourself/icmd" -) - -type StringsSuite struct{} - -var _ = Suite(&StringsSuite{}) - -func (s *StringsSuite) TestIndent(c *C) { - result := icmd.RunCommand(GomplateBin, "-i", - `{{ strings.Indent " " "hello world" }} -{{ "hello\nmultiline\nworld" | indent 2 "-" }} -{{ "foo\nbar" | strings.Indent 2 }} - {{"hello\nworld" | strings.Indent 5 | strings.TrimSpace }} -`) - result.Assert(c, icmd.Expected{ExitCode: 0, Out: ` hello world ---hello ---multiline ---world - foo - bar - hello - world`}) -} - -func (s *StringsSuite) TestRepeat(c *C) { - result := icmd.RunCommand(GomplateBin, "-i", - `ba{{ strings.Repeat 2 "na" }}`) - result.Assert(c, icmd.Expected{ExitCode: 0, Out: `banana`}) - - result = icmd.RunCommand(GomplateBin, "-i", - `ba{{ strings.Repeat 9223372036854775807 "na" }}`) - result.Assert(c, icmd.Expected{ExitCode: 1, Out: `too long: causes overflow`}) - - result = icmd.RunCommand(GomplateBin, "-i", - `ba{{ strings.Repeat -1 "na" }}`) - result.Assert(c, icmd.Expected{ExitCode: 1, Out: `negative count`}) -} - -func (s *StringsSuite) TestSlug(c *C) { - result := icmd.RunCommand(GomplateBin, "-i", - `{{ strings.Slug "Hellö, Wôrld! Free @ last..." }}`) - result.Assert(c, icmd.Expected{ExitCode: 0, Out: `hello-world-free-at-last`}) -} diff --git a/test/integration/test_ec2_utils.go b/test/integration/test_ec2_utils.go deleted file mode 100644 index 7ce583de..00000000 --- a/test/integration/test_ec2_utils.go +++ /dev/null @@ -1,248 +0,0 @@ -package integration - -import ( - "bytes" - "crypto/rand" - "crypto/rsa" - "crypto/x509" - "crypto/x509/pkix" - "encoding/pem" - "log" - "math/big" - "net/http" - - "github.com/fullsailor/pkcs7" -) - -const instanceDocument = `{ - "devpayProductCodes" : null, - "availabilityZone" : "xx-test-1b", - "privateIp" : "10.1.2.3", - "version" : "2010-08-31", - "instanceId" : "i-00000000000000000", - "billingProducts" : null, - "instanceType" : "t2.micro", - "accountId" : "1", - "imageId" : "ami-00000000", - "pendingTime" : "2000-00-01T0:00:00Z", - "architecture" : "x86_64", - "kernelId" : null, - "ramdiskId" : null, - "region" : "xx-test-1" -}` - -func instanceDocumentHandler(w http.ResponseWriter, r *http.Request) { - w.Header().Set("Content-Type", "application/json") - _, err := w.Write([]byte(instanceDocument)) - if err != nil { - w.WriteHeader(500) - } -} - -func certificateGenerate() (priv *rsa.PrivateKey, derBytes []byte, err error) { - priv, err = rsa.GenerateKey(rand.Reader, 2048) - if err != nil { - log.Fatalf("failed to generate private key: %s", err) - } - - serialNumberLimit := new(big.Int).Lsh(big.NewInt(1), 128) - serialNumber, err := rand.Int(rand.Reader, serialNumberLimit) - if err != nil { - log.Fatalf("failed to generate serial number: %s", err) - } - - template := x509.Certificate{ - SerialNumber: serialNumber, - Subject: pkix.Name{ - Organization: []string{"Test"}, - }, - } - - derBytes, err = x509.CreateCertificate(rand.Reader, &template, &template, &priv.PublicKey, priv) - if err != nil { - log.Fatalf("Failed to create certificate: %s", err) - } - - return priv, derBytes, err -} - -func pkcsHandler(priv *rsa.PrivateKey, derBytes []byte) func(http.ResponseWriter, *http.Request) { - return func(w http.ResponseWriter, r *http.Request) { - cert, err := x509.ParseCertificate(derBytes) - if err != nil { - log.Fatalf("Cannot decode certificate: %s", err) - } - - // Initialize a SignedData struct with content to be signed - signedData, err := pkcs7.NewSignedData([]byte(instanceDocument)) - if err != nil { - log.Fatalf("Cannot initialize signed data: %s", err) - } - - // Add the signing cert and private key - if err = signedData.AddSigner(cert, priv, pkcs7.SignerInfoConfig{}); err != nil { - log.Fatalf("Cannot add signer: %s", err) - } - - // Finish() to obtain the signature bytes - detachedSignature, err := signedData.Finish() - if err != nil { - log.Fatalf("Cannot finish signing data: %s", err) - } - - encoded := pem.EncodeToMemory(&pem.Block{Type: "PKCS7", Bytes: detachedSignature}) - - encoded = bytes.TrimPrefix(encoded, []byte("-----BEGIN PKCS7-----\n")) - encoded = bytes.TrimSuffix(encoded, []byte("\n-----END PKCS7-----\n")) - - w.Header().Set("Content-Type", "text/plain") - _, err = w.Write(encoded) - if err != nil { - w.WriteHeader(500) - } - } -} - -func stsHandler(w http.ResponseWriter, r *http.Request) { - w.Header().Set("Content-Type", "text/xml") - _, err := w.Write([]byte(`<GetCallerIdentityResponse xmlns="https://sts.amazonaws.com/doc/2011-06-15/"> - <GetCallerIdentityResult> - <Arn>arn:aws:iam::1:user/Test</Arn> - <UserId>AKIAI44QH8DHBEXAMPLE</UserId> - <Account>1</Account> - </GetCallerIdentityResult> - <ResponseMetadata> - <RequestId>01234567-89ab-cdef-0123-456789abcdef</RequestId> - </ResponseMetadata> -</GetCallerIdentityResponse>`)) - if err != nil { - w.WriteHeader(500) - } -} - -func ec2Handler(w http.ResponseWriter, r *http.Request) { - w.Header().Set("Content-Type", "text/xml") - _, err := w.Write([]byte(`<DescribeInstancesResponse xmlns="http://ec2.amazonaws.com/doc/2016-11-15/"> - <requestId>8f7724cf-496f-496e-8fe3-example</requestId> - <reservationSet> - <item> - <reservationId>r-1234567890abcdef0</reservationId> - <ownerId>123456789012</ownerId> - <groupSet/> - <instancesSet> - <item> - <instanceId>i-00000000000000000</instanceId> - <imageId>ami-00000000</imageId> - <instanceState> - <code>16</code> - <name>running</name> - </instanceState> - <privateDnsName>ip-192-168-1-88.eu-west-1.compute.internal</privateDnsName> - <dnsName>ec2-54-194-252-215.eu-west-1.compute.amazonaws.com</dnsName> - <reason/> - <keyName>my_keypair</keyName> - <amiLaunchIndex>0</amiLaunchIndex> - <productCodes/> - <instanceType>t2.micro</instanceType> - <launchTime>2015-12-22T10:44:05.000Z</launchTime> - <placement> - <availabilityZone>eu-west-1c</availabilityZone> - <groupName/> - <tenancy>default</tenancy> - </placement> - <monitoring> - <state>disabled</state> - </monitoring> - <subnetId>subnet-56f5f633</subnetId> - <vpcId>vpc-11112222</vpcId> - <privateIpAddress>192.168.1.88</privateIpAddress> - <ipAddress>54.194.252.215</ipAddress> - <sourceDestCheck>true</sourceDestCheck> - <groupSet> - <item> - <groupId>sg-e4076980</groupId> - <groupName>SecurityGroup1</groupName> - </item> - </groupSet> - <architecture>x86_64</architecture> - <rootDeviceType>ebs</rootDeviceType> - <rootDeviceName>/dev/xvda</rootDeviceName> - <blockDeviceMapping> - <item> - <deviceName>/dev/xvda</deviceName> - <ebs> - <volumeId>vol-1234567890abcdef0</volumeId> - <status>attached</status> - <attachTime>2015-12-22T10:44:09.000Z</attachTime> - <deleteOnTermination>true</deleteOnTermination> - </ebs> - </item> - </blockDeviceMapping> - <virtualizationType>hvm</virtualizationType> - <clientToken>xMcwG14507example</clientToken> - <tagSet> - <item> - <key>Name</key> - <value>Server_1</value> - </item> - </tagSet> - <hypervisor>xen</hypervisor> - <networkInterfaceSet> - <item> - <networkInterfaceId>eni-551ba033</networkInterfaceId> - <subnetId>subnet-56f5f633</subnetId> - <vpcId>vpc-11112222</vpcId> - <description>Primary network interface</description> - <ownerId>123456789012</ownerId> - <status>in-use</status> - <macAddress>02:dd:2c:5e:01:69</macAddress> - <privateIpAddress>192.168.1.88</privateIpAddress> - <privateDnsName>ip-192-168-1-88.eu-west-1.compute.internal</privateDnsName> - <sourceDestCheck>true</sourceDestCheck> - <groupSet> - <item> - <groupId>sg-e4076980</groupId> - <groupName>SecurityGroup1</groupName> - </item> - </groupSet> - <attachment> - <attachmentId>eni-attach-39697adc</attachmentId> - <deviceIndex>0</deviceIndex> - <status>attached</status> - <attachTime>2015-12-22T10:44:05.000Z</attachTime> - <deleteOnTermination>true</deleteOnTermination> - </attachment> - <association> - <publicIp>54.194.252.215</publicIp> - <publicDnsName>ec2-54-194-252-215.eu-west-1.compute.amazonaws.com</publicDnsName> - <ipOwnerId>amazon</ipOwnerId> - </association> - <privateIpAddressesSet> - <item> - <privateIpAddress>192.168.1.88</privateIpAddress> - <privateDnsName>ip-192-168-1-88.eu-west-1.compute.internal</privateDnsName> - <primary>true</primary> - <association> - <publicIp>54.194.252.215</publicIp> - <publicDnsName>ec2-54-194-252-215.eu-west-1.compute.amazonaws.com</publicDnsName> - <ipOwnerId>amazon</ipOwnerId> - </association> - </item> - </privateIpAddressesSet> - <ipv6AddressesSet> - <item> - <ipv6Address>2001:db8:1234:1a2b::123</ipv6Address> - </item> - </ipv6AddressesSet> - </item> - </networkInterfaceSet> - <ebsOptimized>false</ebsOptimized> - </item> - </instancesSet> - </item> - </reservationSet> -</DescribeInstancesResponse>`)) - if err != nil { - w.WriteHeader(500) - } -} diff --git a/test/integration/time_test.go b/test/integration/time_test.go deleted file mode 100644 index 65ec5f8f..00000000 --- a/test/integration/time_test.go +++ /dev/null @@ -1,49 +0,0 @@ -//+build integration -//+build !windows - -package integration - -import ( - "time" - - "github.com/gotestyourself/gotestyourself/icmd" - . "gopkg.in/check.v1" -) - -type TimeSuite struct{} - -var _ = Suite(&TimeSuite{}) - -func (s *TimeSuite) TestTime(c *C) { - f := `Mon Jan 02 15:04:05 MST 2006` - i := `Fri Feb 13 23:31:30 UTC 2009` - inOutTest(c, `{{ (time.Parse "`+f+`" "`+i+`").Format "2006-01-02 15 -0700" }}`, - "2009-02-13 23 +0000") - - result := icmd.RunCmd(icmd.Command(GomplateBin, "-i", - `{{ (time.ParseLocal time.Kitchen "6:00AM").Format "15:04 MST" }}`), func(cmd *icmd.Cmd) { - cmd.Env = []string{"TZ=Africa/Luanda"} - }) - result.Assert(c, icmd.Expected{ExitCode: 0, Out: "06:00 LMT"}) - - result = icmd.RunCmd(icmd.Command(GomplateBin, "-i", - `{{ time.ZoneOffset }}`), func(cmd *icmd.Cmd) { - cmd.Env = []string{"TZ=UTC"} - }) - result.Assert(c, icmd.Expected{ExitCode: 0, Out: "0"}) - - zname, _ := time.Now().Zone() - inOutTest(c, `{{ time.ZoneName }}`, zname) - - inOutTest(c, `{{ (time.Now).Format "2006-01-02 15 -0700" }}`, - time.Now().Format("2006-01-02 15 -0700")) - - inOutTest(c, `{{ (time.ParseInLocation time.Kitchen "Africa/Luanda" "6:00AM").Format "15:04 MST" }}`, - "06:00 LMT") - - inOutTest(c, `{{ (time.Unix 1234567890).UTC.Format "2006-01-02 15 -0700" }}`, - "2009-02-13 23 +0000") - - inOutTest(c, `{{ (time.Unix "1234567890").UTC.Format "2006-01-02 15 -0700" }}`, - "2009-02-13 23 +0000") -} diff --git a/test/integration/typeconv_test.go b/test/integration/typeconv_test.go deleted file mode 100644 index fece8180..00000000 --- a/test/integration/typeconv_test.go +++ /dev/null @@ -1,87 +0,0 @@ -//+build integration -//+build !windows - -package integration - -import ( - . "gopkg.in/check.v1" -) - -type TypeconvSuite struct{} - -var _ = Suite(&TypeconvSuite{}) - -const ( - testYAML = "foo:\\n bar:\\n baz: qux" - testJSON = `{"foo":{"bar":{"baz":"qux"}}}` - testCsv = `lang,keywords -C,32 -Go,25 -COBOL,357` - testTsv = `lang keywords -C 32 -Go 25 -COBOL 357` -) - -func (s *TypeconvSuite) TestTypeconvFuncs(c *C) { - //@test "'has' can handle sub-maps in nested maps" { - inOutTest(c, `{{ has ("`+testYAML+`" | yaml).foo.bar "baz"}}`, - "true") -} -func (s *TypeconvSuite) TestJSON(c *C) { - inOutTest(c, `{{ "`+testYAML+`" | yaml | toJSON }}`, testJSON) - - inOutTest(c, `{{ `+"`"+testJSON+"`"+` | json | toJSONPretty " " }} -{{ toJSONPretty "" (`+"`"+testJSON+"`"+` | json) }}`, - `{ - "foo": { - "bar": { - "baz": "qux" - } - } -} -{ -"foo": { -"bar": { -"baz": "qux" -} -} -}`) -} - -func (s *TypeconvSuite) TestJoin(c *C) { - inOutTest(c, `{{ $a := "[1, 2, 3]" | jsonArray }}{{ join $a "-" }}`, - "1-2-3") -} - -func (s *TypeconvSuite) TestCSV(c *C) { - inOutTest(c, `{{ $c := `+"`"+testCsv+"`"+` | csv -}} -{{ index (index $c 0) 1 }}`, - "keywords") - - inOutTest(c, `{{ $c := `+"`"+testCsv+"`"+` | csvByRow -}} -{{ range $c }}{{ .lang }} has {{ .keywords }} keywords. -{{end}}`, - `C has 32 keywords. -Go has 25 keywords. -COBOL has 357 keywords.`) - - inOutTest(c, `{{ $c := `+"`"+testTsv+"`"+` | csvByColumn "\t" -}} -Languages are: {{ join $c.lang " and " }}`, - "Languages are: C and Go and COBOL") -} - -func (s *TypeconvSuite) TestTOML(c *C) { - inOutTest(c, `{{ $t := `+"`"+`# comment -foo = "bar" - -[baz] -qux = "quux"`+"`"+` | toml -}} -{{ $t.baz.qux }}`, "quux") - - inOutTest(c, `{{ "foo:\n bar:\n baz: qux" | yaml | toTOML }}`, - `[foo] - [foo.bar] - baz = "qux"`) -} |
