Skip to content

Commit b265149

Browse files
committed
add symlink backup test
1 parent b059fdf commit b265149

File tree

1 file changed

+36
-0
lines changed

1 file changed

+36
-0
lines changed

cli/dotfiles_test.go

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -73,6 +73,42 @@ func TestDotfiles(t *testing.T) {
7373
assert.NoError(t, err)
7474
assert.Equal(t, string(b), "wow\n")
7575
})
76+
t.Run("SymlinkBackup", func(t *testing.T) {
77+
_, root := clitest.New(t)
78+
testRepo := testGitRepo(t, root)
79+
80+
// nolint:gosec
81+
err := os.WriteFile(filepath.Join(testRepo, ".bashrc"), []byte("wow"), 0750)
82+
assert.NoError(t, err)
83+
84+
// add a conflicting file at destination
85+
// nolint:gosec
86+
err = os.WriteFile(filepath.Join(string(root), ".bashrc"), []byte("backup"), 0750)
87+
assert.NoError(t, err)
88+
89+
c := exec.Command("git", "add", ".bashrc")
90+
c.Dir = testRepo
91+
err = c.Run()
92+
assert.NoError(t, err)
93+
94+
c = exec.Command("git", "commit", "-m", `"add .bashrc"`)
95+
c.Dir = testRepo
96+
out, err := c.CombinedOutput()
97+
assert.NoError(t, err, string(out))
98+
99+
cmd, _ := clitest.New(t, "dotfiles", "--global-config", string(root), "--symlink-dir", string(root), "-y", testRepo)
100+
err = cmd.Execute()
101+
assert.NoError(t, err)
102+
103+
b, err := os.ReadFile(filepath.Join(string(root), ".bashrc"))
104+
assert.NoError(t, err)
105+
assert.Equal(t, string(b), "wow")
106+
107+
// check for backup file
108+
b, err = os.ReadFile(filepath.Join(string(root), ".bashrc.bak"))
109+
assert.NoError(t, err)
110+
assert.Equal(t, string(b), "backup")
111+
})
76112
}
77113

78114
func testGitRepo(t *testing.T, root config.Root) string {

0 commit comments

Comments
 (0)