Skip to content

Commit

Permalink
Add some more template dir tests
Browse files Browse the repository at this point in the history
  • Loading branch information
zb140 authored and twpayne committed Jul 7, 2019
1 parent 77b8641 commit f88c88a
Showing 1 changed file with 43 additions and 0 deletions.
43 changes: 43 additions & 0 deletions cmd/apply_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -88,9 +88,47 @@ func TestApplyCommand(t *testing.T) {
},
},
},
{
name: "define_template",
root: map[string]interface{}{
"/home/user/.local/share/chezmoi": map[string]interface{}{
"dir/file.tmpl": `{{ define "foo" }}cont{{end}}{{ template "foo" }}ents`,
},
},
},
{
name: "partial_template",
root: map[string]interface{}{
"/home/user/.local/share/chezmoi": map[string]interface{}{
"dir/file.tmpl": `{{ template "foo" }}ents`,
".chezmoitemplates/foo": "{{ if true }}cont{{ end }}",
},
},
},
{
name: "multiple_templates",
root: map[string]interface{}{
"/home/user/.local/share/chezmoi": map[string]interface{}{
"dir/file.tmpl": `{{ template "foo" }}`,
"dir/other.tmpl": `{{ if true }}other stuff{{ end }}`,
".chezmoitemplates/foo": "{{ if true }}contents{{ end }}",
},
},
},
{
name: "multiple_associated",
root: map[string]interface{}{
"/home/user/.local/share/chezmoi": map[string]interface{}{
"dir/file.tmpl": `{{ template "foo" }}{{ template "bar" }}`,
".chezmoitemplates/foo": "{{ if true }}cont{{ end }}",
".chezmoitemplates/bar": "{{ if true }}ents{{ end }}",
},
},
},
} {
t.Run(tc.name, func(t *testing.T) {
tc.root["/home/user/.local/share/chezmoi/dir/file"] = "contents"
tc.root["/home/user/.local/share/chezmoi/dir/other"] = "other stuff"
tc.root["/home/user/.local/share/chezmoi/symlink_symlink"] = "target"
fs, cleanup, err := vfst.NewTestFS(tc.root)
require.NoError(t, err)
Expand All @@ -111,6 +149,11 @@ func TestApplyCommand(t *testing.T) {
vfst.TestModePerm(0644),
vfst.TestContentsString("contents"),
),
vfst.TestPath("/home/user/dir/other",
vfst.TestModeIsRegular,
vfst.TestModePerm(0644),
vfst.TestContentsString("other stuff"),
),
vfst.TestPath("/home/user/symlink",
vfst.TestModeType(os.ModeSymlink),
vfst.TestSymlinkTarget("target"),
Expand Down

0 comments on commit f88c88a

Please sign in to comment.