diff options
| author | Dave Henderson <dhenderson@gmail.com> | 2019-04-28 20:14:35 -0400 |
|---|---|---|
| committer | Dave Henderson <dhenderson@gmail.com> | 2019-04-28 20:14:35 -0400 |
| commit | d2880d9d9e20bbe019f02b0477a5ce74c5fc85f2 (patch) | |
| tree | 0746e3b2a24cbfd7778c494860ed4d06f32a2428 /tests/integration/inputdir_test.go | |
| parent | aae1a6803067eccbb4df600a5dbf17b93aebd89d (diff) | |
Fixing file-mode inheritance bug
Signed-off-by: Dave Henderson <dhenderson@gmail.com>
Diffstat (limited to 'tests/integration/inputdir_test.go')
| -rw-r--r-- | tests/integration/inputdir_test.go | 38 |
1 files changed, 28 insertions, 10 deletions
diff --git a/tests/integration/inputdir_test.go b/tests/integration/inputdir_test.go index 341aab57..1e0bfb6a 100644 --- a/tests/integration/inputdir_test.go +++ b/tests/integration/inputdir_test.go @@ -24,7 +24,7 @@ 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.WithFile("filemap.json", `{"eins.txt":"uno","deux.txt":"dos"}`), + fs.WithFile("filemap.json", `{"eins.txt":"uno","deux.txt":"dos","drei.sh":"tres","vier.txt":"quatro"}`), fs.WithFile("out.t", `{{- /* .in may contain a directory name - we want to preserve that */ -}} {{ $f := filepath.Base .in -}} out/{{ .in | strings.ReplaceAll $f (index .filemap $f) }}.out @@ -34,6 +34,8 @@ out/{{ .in | strings.ReplaceAll $f (index .filemap $f) }}.out fs.WithDir("inner", fs.WithFile("deux.txt", `{{ (ds "config").two }}`, fs.WithMode(0444)), ), + fs.WithFile("drei.sh", `#!/bin/sh\necho "hello world"\n`, fs.WithMode(0755)), + fs.WithFile("vier.txt", `{{ (ds "config").two }} * {{ (ds "config").two }}`, fs.WithMode(0544)), ), fs.WithDir("out"), fs.WithDir("bad_in", @@ -56,7 +58,7 @@ func (s *InputDirSuite) TestInputDir(c *C) { files, err := ioutil.ReadDir(s.tmpDir.Join("out")) assert.NilError(c, err) - tassert.Len(c, files, 2) + tassert.Len(c, files, 4) files, err = ioutil.ReadDir(s.tmpDir.Join("out", "inner")) assert.NilError(c, err) @@ -68,14 +70,16 @@ func (s *InputDirSuite) TestInputDir(c *C) { content string }{ {s.tmpDir.Join("out", "eins.txt"), 0644, "eins"}, - {s.tmpDir.Join("out", "inner", "deux.txt"), 0644, "deux"}, + {s.tmpDir.Join("out", "inner", "deux.txt"), 0444, "deux"}, + {s.tmpDir.Join("out", "drei.sh"), 0755, `#!/bin/sh\necho "hello world"\n`}, + {s.tmpDir.Join("out", "vier.txt"), 0544, "deux * deux"}, } for _, v := range testdata { info, err := os.Stat(v.path) assert.NilError(c, err) // chmod support on Windows is pretty weak for now if runtime.GOOS != "windows" { - assert.Equal(c, v.mode, info.Mode()) + assert.Equal(c, v.mode, info.Mode(), v.path) } content, err := ioutil.ReadFile(v.path) assert.NilError(c, err) @@ -94,7 +98,7 @@ func (s *InputDirSuite) TestInputDirWithModeOverride(c *C) { files, err := ioutil.ReadDir(s.tmpDir.Join("out")) assert.NilError(c, err) - tassert.Len(c, files, 2) + tassert.Len(c, files, 4) files, err = ioutil.ReadDir(s.tmpDir.Join("out", "inner")) assert.NilError(c, err) @@ -107,6 +111,8 @@ func (s *InputDirSuite) TestInputDirWithModeOverride(c *C) { }{ {s.tmpDir.Join("out", "eins.txt"), 0601, "eins"}, {s.tmpDir.Join("out", "inner", "deux.txt"), 0601, "deux"}, + {s.tmpDir.Join("out", "drei.sh"), 0601, `#!/bin/sh\necho "hello world"\n`}, + {s.tmpDir.Join("out", "vier.txt"), 0601, "deux * deux"}, } for _, v := range testdata { info, err := os.Stat(v.path) @@ -133,7 +139,7 @@ func (s *InputDirSuite) TestOutputMapInline(c *C) { files, err := ioutil.ReadDir(s.tmpDir.Join("OUT")) assert.NilError(c, err) - tassert.Len(c, files, 2) + tassert.Len(c, files, 4) files, err = ioutil.ReadDir(s.tmpDir.Join("OUT", "INNER")) assert.NilError(c, err) @@ -145,7 +151,9 @@ func (s *InputDirSuite) TestOutputMapInline(c *C) { content string }{ {s.tmpDir.Join("OUT", "EINS.TXT"), 0644, "eins"}, - {s.tmpDir.Join("OUT", "INNER", "DEUX.TXT"), 0644, "deux"}, + {s.tmpDir.Join("OUT", "INNER", "DEUX.TXT"), 0444, "deux"}, + {s.tmpDir.Join("OUT", "DREI.SH"), 0755, `#!/bin/sh\necho "hello world"\n`}, + {s.tmpDir.Join("OUT", "VIER.TXT"), 0544, "deux * deux"}, } for _, v := range testdata { info, err := os.Stat(v.path) @@ -174,7 +182,7 @@ func (s *InputDirSuite) TestOutputMapExternal(c *C) { files, err := ioutil.ReadDir(s.tmpDir.Join("out")) assert.NilError(c, err) - tassert.Len(c, files, 2) + tassert.Len(c, files, 4) files, err = ioutil.ReadDir(s.tmpDir.Join("out", "inner")) assert.NilError(c, err) @@ -186,7 +194,9 @@ func (s *InputDirSuite) TestOutputMapExternal(c *C) { content string }{ {s.tmpDir.Join("out", "uno.out"), 0644, "eins"}, - {s.tmpDir.Join("out", "inner", "dos.out"), 0644, "deux"}, + {s.tmpDir.Join("out", "inner", "dos.out"), 0444, "deux"}, + {s.tmpDir.Join("out", "tres.out"), 0755, `#!/bin/sh\necho "hello world"\n`}, + {s.tmpDir.Join("out", "quatro.out"), 0544, "deux * deux"}, } for _, v := range testdata { info, err := os.Stat(v.path) @@ -212,7 +222,7 @@ func (s *InputDirSuite) TestDefaultOutputDir(c *C) { files, err := ioutil.ReadDir(s.tmpDir.Join("out")) assert.NilError(c, err) - tassert.Len(c, files, 2) + tassert.Len(c, files, 4) files, err = ioutil.ReadDir(s.tmpDir.Join("out", "inner")) assert.NilError(c, err) @@ -225,6 +235,14 @@ func (s *InputDirSuite) TestDefaultOutputDir(c *C) { content, err = ioutil.ReadFile(s.tmpDir.Join("out", "inner", "deux.txt")) assert.NilError(c, err) assert.Equal(c, "deux", string(content)) + + content, err = ioutil.ReadFile(s.tmpDir.Join("out", "drei.sh")) + assert.NilError(c, err) + assert.Equal(c, `#!/bin/sh\necho "hello world"\n`, string(content)) + + content, err = ioutil.ReadFile(s.tmpDir.Join("out", "vier.txt")) + assert.NilError(c, err) + assert.Equal(c, `deux * deux`, string(content)) } func (s *InputDirSuite) TestReportsFilenameWithBadInputFile(c *C) { |
