summaryrefslogtreecommitdiff
path: root/internal/tests/integration/basic_test.go
diff options
context:
space:
mode:
authorDave Henderson <dhenderson@gmail.com>2022-01-09 14:45:24 -0500
committerDave Henderson <dhenderson@gmail.com>2022-02-13 11:53:47 -0500
commit4510ec9c9e9b1cdce83ec893dfe2aebfdd5db8d7 (patch)
tree831048f23820fe9c3c8749bedbbf839a4a546621 /internal/tests/integration/basic_test.go
parent839e8973475f1f0bdc05657ea13cd23a16d85cd8 (diff)
Ensure output file paths exist
Signed-off-by: Dave Henderson <dhenderson@gmail.com>
Diffstat (limited to 'internal/tests/integration/basic_test.go')
-rw-r--r--internal/tests/integration/basic_test.go45
1 files changed, 39 insertions, 6 deletions
diff --git a/internal/tests/integration/basic_test.go b/internal/tests/integration/basic_test.go
index 243bef4b..a1e2dc70 100644
--- a/internal/tests/integration/basic_test.go
+++ b/internal/tests/integration/basic_test.go
@@ -1,6 +1,7 @@
package integration
import (
+ "io/fs"
"io/ioutil"
"os"
"testing"
@@ -8,14 +9,19 @@ import (
"github.com/hairyhenderson/gomplate/v3/internal/iohelpers"
"gotest.tools/v3/assert"
"gotest.tools/v3/assert/cmp"
- "gotest.tools/v3/fs"
+ testfs "gotest.tools/v3/fs"
)
-func setupBasicTest(t *testing.T) *fs.Dir {
- tmpDir := fs.NewDir(t, "gomplate-inttests",
- fs.WithFile("one", "hi\n", fs.WithMode(0640)),
- fs.WithFile("two", "hello\n"),
- fs.WithFile("broken", "", fs.WithMode(0000)))
+func setupBasicTest(t *testing.T) *testfs.Dir {
+ tmpDir := testfs.NewDir(t, "gomplate-inttests",
+ testfs.WithFile("one", "hi\n", testfs.WithMode(0640)),
+ testfs.WithFile("two", "hello\n"),
+ testfs.WithFile("broken", "", testfs.WithMode(0000)),
+ testfs.WithDir("subdir",
+ testfs.WithFile("f1", "first\n", testfs.WithMode(0640)),
+ testfs.WithFile("f2", "second\n"),
+ ),
+ )
t.Cleanup(tmpDir.Remove)
return tmpDir
}
@@ -256,3 +262,30 @@ func TestBasic_AppliesChmodBeforeWrite(t *testing.T) {
assert.NilError(t, err)
assert.Equal(t, "hi\n", string(content))
}
+
+func TestBasic_CreatesMissingDirectory(t *testing.T) {
+ tmpDir := setupBasicTest(t)
+ out := tmpDir.Join("foo/bar/baz")
+ o, e, err := cmd(t, "-f", tmpDir.Join("one"), "-o", out).run()
+ assertSuccess(t, o, e, err, "")
+
+ info, err := os.Stat(out)
+ assert.NilError(t, err)
+ assert.Equal(t, iohelpers.NormalizeFileMode(0640), info.Mode())
+ content, err := ioutil.ReadFile(out)
+ assert.NilError(t, err)
+ assert.Equal(t, "hi\n", string(content))
+
+ out = tmpDir.Join("outdir")
+ o, e, err = cmd(t,
+ "--input-dir", tmpDir.Join("subdir"),
+ "--output-dir", out,
+ ).run()
+ assertSuccess(t, o, e, err, "")
+
+ info, err = os.Stat(out)
+ assert.NilError(t, err)
+
+ assert.Equal(t, iohelpers.NormalizeFileMode(0o755|fs.ModeDir), info.Mode())
+ assert.Equal(t, true, info.IsDir())
+}