1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
|
package integration
import (
"os"
"path/filepath"
"testing"
"gotest.tools/v3/assert"
"gotest.tools/v3/fs"
)
func setupFileTest(t *testing.T) *fs.Dir {
tmpDir := fs.NewDir(t, "gomplate-inttests",
fs.WithFile("one", "hi\n"),
fs.WithFile("two", "hello\n"))
t.Cleanup(tmpDir.Remove)
return tmpDir
}
func TestFile_ReadsFile(t *testing.T) {
tmpDir := setupFileTest(t)
inOutTest(t, "{{ file.Read `"+tmpDir.Join("one")+"`}}", "hi\n")
}
func TestFile_Write(t *testing.T) {
tmpDir := setupFileTest(t)
outDir := tmpDir.Join("writeOutput")
os.MkdirAll(outDir, 0755)
o, e, err := cmd(t, "-i", `{{ "hello world" | file.Write "./out" }}`).
withDir(outDir).run()
assertSuccess(t, o, e, err, "")
out, err := os.ReadFile(filepath.Join(outDir, "out"))
assert.NilError(t, err)
assert.Equal(t, "hello world", string(out))
}
|