@@ -10,31 +10,69 @@ import (
1010)
1111
1212func TestFromPath (t * testing.T ) {
13- mockPathwrap := new (pathwrap.MockPath )
14- mockGit := new (git.MockGit )
15- n := NewNamer (mockPathwrap , mockGit )
16-
17- t .Run ("name for git repo" , func (t * testing.T ) {
18- mockGit .On ("ShowTopLevel" , "/Users/josh/c/dotfiles/.config/neovim" ).Return (true , "/Users/josh/c/dotfiles" , nil )
19- mockGit .On ("GitCommonDir" , "/Users/josh/c/dotfiles/.config/neovim" ).Return (true , "" , nil )
20- mockPathwrap .On ("Base" , "/Users/josh/c/dotfiles" ).Return ("dotfiles" )
21- name , _ := n .Name ("/Users/josh/c/dotfiles/.config/neovim" )
22- assert .Equal (t , "dotfiles/_config/neovim" , name )
23- })
13+ t .Run ("when path does not contain a symlink" , func (t * testing.T ) {
14+ mockPathwrap := new (pathwrap.MockPath )
15+ mockGit := new (git.MockGit )
16+ n := NewNamer (mockPathwrap , mockGit )
17+
18+ t .Run ("name for git repo" , func (t * testing.T ) {
19+ mockPathwrap .On ("EvalSymlinks" , "/Users/josh/config/dotfiles/.config/neovim" ).Return ("/Users/josh/config/dotfiles/.config/neovim" , nil )
20+ mockGit .On ("ShowTopLevel" , "/Users/josh/config/dotfiles/.config/neovim" ).Return (true , "/Users/josh/config/dotfiles" , nil )
21+ mockGit .On ("GitCommonDir" , "/Users/josh/config/dotfiles/.config/neovim" ).Return (true , "" , nil )
22+ mockPathwrap .On ("Base" , "/Users/josh/config/dotfiles" ).Return ("dotfiles" )
23+ name , _ := n .Name ("/Users/josh/config/dotfiles/.config/neovim" )
24+ assert .Equal (t , "dotfiles/_config/neovim" , name )
25+ })
26+
27+ t .Run ("name for git worktree" , func (t * testing.T ) {
28+ mockPathwrap .On ("EvalSymlinks" , "/Users/josh/config/sesh/main" ).Return ("/Users/josh/config/sesh/main" , nil )
29+ mockGit .On ("ShowTopLevel" , "/Users/josh/config/sesh/main" ).Return (true , "/Users/josh/config/sesh/main" , nil )
30+ mockGit .On ("GitCommonDir" , "/Users/josh/config/sesh/main" ).Return (true , "/Users/josh/config/sesh/.bare" , nil )
31+ mockPathwrap .On ("Base" , "/Users/josh/config/sesh" ).Return ("sesh" )
32+ name , _ := n .Name ("/Users/josh/config/sesh/main" )
33+ assert .Equal (t , "sesh/main" , name )
34+ })
2435
25- t .Run ("name for git worktree" , func (t * testing.T ) {
26- mockGit .On ("ShowTopLevel" , "/Users/josh/c/sesh/main" ).Return (true , "/Users/josh/c/sesh/main" , nil )
27- mockGit .On ("GitCommonDir" , "/Users/josh/c/sesh/main" ).Return (true , "/Users/josh/c/sesh/.bare" , nil )
28- mockPathwrap .On ("Base" , "/Users/josh/c/sesh" ).Return ("sesh" )
29- name , _ := n .Name ("/Users/josh/c/sesh/main" )
30- assert .Equal (t , "sesh/main" , name )
36+ t .Run ("returns base on non-git dir" , func (t * testing.T ) {
37+ mockPathwrap .On ("EvalSymlinks" , "/Users/josh/.config/neovim" ).Return ("/Users/josh/.config/neovim" , nil )
38+ mockGit .On ("ShowTopLevel" , "/Users/josh/.config/neovim" ).Return (false , "" , fmt .Errorf ("not a git repository (or any of the parent" ))
39+ mockGit .On ("GitCommonDir" , "/Users/josh/.config/neovim" ).Return (false , "" , fmt .Errorf ("not a git repository (or any of the parent" ))
40+ mockPathwrap .On ("Base" , "/Users/josh/.config/neovim" ).Return ("neovim" )
41+ name , _ := n .Name ("/Users/josh/.config/neovim" )
42+ assert .Equal (t , "neovim" , name )
43+ })
3144 })
3245
33- t .Run ("returns base on non-git dir" , func (t * testing.T ) {
34- mockGit .On ("ShowTopLevel" , "/Users/josh/.config/neovim" ).Return (false , "" , fmt .Errorf ("not a git repository (or any of the parent" ))
35- mockGit .On ("GitCommonDir" , "/Users/josh/.config/neovim" ).Return (false , "" , fmt .Errorf ("not a git repository (or any of the parent" ))
36- mockPathwrap .On ("Base" , "/Users/josh/.config/neovim" ).Return ("neovim" )
37- name , _ := n .Name ("/Users/josh/.config/neovim" )
38- assert .Equal (t , "neovim" , name )
46+ t .Run ("when path contains a symlink" , func (t * testing.T ) {
47+ mockPathwrap := new (pathwrap.MockPath )
48+ mockGit := new (git.MockGit )
49+ n := NewNamer (mockPathwrap , mockGit )
50+
51+ t .Run ("name for symlinked file in symlinked git repo" , func (t * testing.T ) {
52+ mockPathwrap .On ("EvalSymlinks" , "/Users/josh/d/.c/neovim" ).Return ("/Users/josh/dotfiles/.config/neovim" , nil )
53+ mockGit .On ("ShowTopLevel" , "/Users/josh/dotfiles/.config/neovim" ).Return (true , "/Users/josh/dotfiles" , nil )
54+ mockGit .On ("GitCommonDir" , "/Users/josh/dotfiles/.config/neovim" ).Return (true , "" , nil )
55+ mockPathwrap .On ("Base" , "/Users/josh/dotfiles" ).Return ("dotfiles" )
56+ name , _ := n .Name ("/Users/josh/d/.c/neovim" )
57+ assert .Equal (t , "dotfiles/_config/neovim" , name )
58+ })
59+
60+ t .Run ("name for git worktree" , func (t * testing.T ) {
61+ mockPathwrap .On ("EvalSymlinks" , "/Users/josh/p/sesh/main" ).Return ("/Users/josh/projects/sesh/main" , nil )
62+ mockGit .On ("ShowTopLevel" , "/Users/josh/projects/sesh/main" ).Return (true , "/Users/josh/projects/sesh/main" , nil )
63+ mockGit .On ("GitCommonDir" , "/Users/josh/projects/sesh/main" ).Return (true , "/Users/josh/projects/sesh/.bare" , nil )
64+ mockPathwrap .On ("Base" , "/Users/josh/projects/sesh" ).Return ("sesh" )
65+ name , _ := n .Name ("/Users/josh/p/sesh/main" )
66+ assert .Equal (t , "sesh/main" , name )
67+ })
68+
69+ t .Run ("returns base on non-git dir" , func (t * testing.T ) {
70+ mockPathwrap .On ("EvalSymlinks" , "/Users/josh/c/neovim" ).Return ("/Users/josh/.config/neovim" , nil )
71+ mockGit .On ("ShowTopLevel" , "/Users/josh/.config/neovim" ).Return (false , "" , fmt .Errorf ("not a git repository (or any of the parent" ))
72+ mockGit .On ("GitCommonDir" , "/Users/josh/.config/neovim" ).Return (false , "" , fmt .Errorf ("not a git repository (or any of the parent" ))
73+ mockPathwrap .On ("Base" , "/Users/josh/.config/neovim" ).Return ("neovim" )
74+ name , _ := n .Name ("/Users/josh/c/neovim" )
75+ assert .Equal (t , "neovim" , name )
76+ })
3977 })
4078}
0 commit comments