-
Notifications
You must be signed in to change notification settings - Fork 473
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
10 changed files
with
203 additions
and
14 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,59 @@ | ||
package chezmoi | ||
|
||
import ( | ||
"testing" | ||
|
||
"github.com/stretchr/testify/assert" | ||
) | ||
|
||
func TestNormalizeLinkname(t *testing.T) { | ||
for _, tc := range []struct { | ||
linkname string | ||
expected string | ||
}{ | ||
{ | ||
linkname: "rel", | ||
expected: "rel", | ||
}, | ||
{ | ||
linkname: "rel/forward", | ||
expected: "rel/forward", | ||
}, | ||
{ | ||
linkname: "rel\\backward", | ||
expected: "rel/backward", | ||
}, | ||
{ | ||
linkname: "rel/forward\\backward", | ||
expected: "rel/forward/backward", | ||
}, | ||
{ | ||
linkname: "/abs/forward", | ||
expected: "/abs/forward", | ||
}, | ||
{ | ||
linkname: "\\abs\\backward", | ||
expected: "/abs/backward", | ||
}, | ||
{ | ||
linkname: "/abs/forward\\backward", | ||
expected: "/abs/forward/backward", | ||
}, | ||
{ | ||
linkname: "c:/abs/forward", | ||
expected: "C:/abs/forward", | ||
}, | ||
{ | ||
linkname: "c:\\abs\\backward", | ||
expected: "C:/abs/backward", | ||
}, | ||
{ | ||
linkname: "c:/abs/forward\\backward", | ||
expected: "C:/abs/forward/backward", | ||
}, | ||
} { | ||
t.Run(tc.linkname, func(t *testing.T) { | ||
assert.Equal(t, tc.expected, normalizeLinkname(tc.linkname)) | ||
}) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,86 @@ | ||
package cmd | ||
|
||
import ( | ||
"io/fs" | ||
"testing" | ||
|
||
"github.com/stretchr/testify/require" | ||
"github.com/twpayne/go-vfs/v3" | ||
"github.com/twpayne/go-vfs/v3/vfst" | ||
|
||
"github.com/twpayne/chezmoi/v2/internal/chezmoitest" | ||
) | ||
|
||
func TestSymlinks(t *testing.T) { | ||
for _, tc := range []struct { | ||
name string | ||
extraRoot interface{} | ||
args []string | ||
tests []interface{} | ||
}{ | ||
{ | ||
name: "symlink_forward_slash_unix", | ||
extraRoot: map[string]interface{}{ | ||
"/home/user/.local/share/chezmoi/symlink_dot_symlink": ".dir/file", | ||
}, | ||
args: []string{"~/.symlink"}, | ||
tests: []interface{}{ | ||
vfst.TestPath("/home/user/.symlink", | ||
vfst.TestModeType(fs.ModeSymlink), | ||
vfst.TestSymlinkTarget(".dir/file"), | ||
), | ||
}, | ||
}, | ||
{ | ||
name: "symlink_forward_slash_windows", | ||
extraRoot: map[string]interface{}{ | ||
"/home/user/.local/share/chezmoi/symlink_dot_symlink": ".dir/file", | ||
}, | ||
args: []string{"~/.symlink"}, | ||
tests: []interface{}{ | ||
vfst.TestPath("/home/user/.symlink", | ||
vfst.TestModeType(fs.ModeSymlink), | ||
vfst.TestSymlinkTarget(".dir\\file"), | ||
), | ||
}, | ||
}, | ||
{ | ||
name: "symlink_backward_slash_windows", | ||
extraRoot: map[string]interface{}{ | ||
"/home/user/.local/share/chezmoi/symlink_dot_symlink": ".dir\\file", | ||
}, | ||
args: []string{"~/.symlink"}, | ||
tests: []interface{}{ | ||
vfst.TestPath("/home/user/.symlink", | ||
vfst.TestModeType(fs.ModeSymlink), | ||
vfst.TestSymlinkTarget(".dir\\file"), | ||
), | ||
}, | ||
}, | ||
{ | ||
name: "symlink_mixed_slash_windows", | ||
extraRoot: map[string]interface{}{ | ||
"/home/user/.local/share/chezmoi/symlink_dot_symlink": ".dir/subdir\\file", | ||
}, | ||
args: []string{"~/.symlink"}, | ||
tests: []interface{}{ | ||
vfst.TestPath("/home/user/.symlink", | ||
vfst.TestModeType(fs.ModeSymlink), | ||
vfst.TestSymlinkTarget(".dir\\subdir\\file"), | ||
), | ||
}, | ||
}, | ||
} { | ||
t.Run(tc.name, func(t *testing.T) { | ||
chezmoitest.SkipUnlessGOOS(t, tc.name) | ||
chezmoitest.WithTestFS(t, nil, func(fileSystem vfs.FS) { | ||
if tc.extraRoot != nil { | ||
require.NoError(t, vfst.NewBuilder().Build(fileSystem, tc.extraRoot)) | ||
} | ||
require.NoError(t, newTestConfig(t, fileSystem).execute(append([]string{"apply"}, tc.args...))) | ||
vfst.RunTests(t, fileSystem, "", tc.tests) | ||
require.NoError(t, newTestConfig(t, fileSystem).execute([]string{"verify"})) | ||
}) | ||
}) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
[!windows] skip 'Windows only' | ||
|
||
# test that chezmoi apply normalizes symlinks | ||
chezmoi apply $HOME${/}.symlink_backward_slash $HOME${/}.symlink_forward_slash | ||
readlink $HOME/.symlink_backward_slash $HOME\.dir\file | ||
readlink $HOME/.symlink_forward_slash $HOME\.dir\file | ||
|
||
# test that the persistent state matches the actual state | ||
chezmoi verify | ||
|
||
-- home/user/.dir/file -- | ||
# contents of .dir/file | ||
-- home/user/.local/share/chezmoi/symlink_dot_symlink_backward_slash.tmpl -- | ||
{{ env "HOME" }}\.dir\file | ||
-- home/user/.local/share/chezmoi/symlink_dot_symlink_forward_slash.tmpl -- | ||
{{ env "HOME" }}/.dir/file |