11package common
22
33import (
4+ "context"
5+ "os"
6+ "path"
47 "testing"
58
69 "github.com/stretchr/testify/require"
@@ -13,9 +16,12 @@ func TestExpandPath_NoPath_NoBase(t *testing.T) {
1316}
1417
1518func TestExpandPath_NoPath_RelBase (t * testing.T ) {
16- path , err := ExpandPath ("" , "repo" , "" )
17- require .NoError (t , err )
18- require .Equal (t , "repo" , path )
19+ testCases := []string {"repo" , "./repo" }
20+ for _ , base := range testCases {
21+ path , err := ExpandPath ("" , base , "" )
22+ require .NoError (t , err )
23+ require .Equal (t , "repo" , path )
24+ }
1925}
2026
2127func TestExpandPath_NoPath_AbsBase (t * testing.T ) {
@@ -25,9 +31,12 @@ func TestExpandPath_NoPath_AbsBase(t *testing.T) {
2531}
2632
2733func TestExpandtPath_RelPath_NoBase (t * testing.T ) {
28- path , err := ExpandPath ("repo" , "" , "" )
29- require .NoError (t , err )
30- require .Equal (t , "repo" , path )
34+ testCases := []string {"repo" , "./repo" }
35+ for _ , pth := range testCases {
36+ path , err := ExpandPath (pth , "" , "" )
37+ require .NoError (t , err )
38+ require .Equal (t , "repo" , path )
39+ }
3140}
3241
3342func TestExpandtPath_RelPath_RelBase (t * testing.T ) {
@@ -107,3 +116,42 @@ func TestExpandtPath_ErrorTildeUsernameNotSupported_TildeUsernameWithPath(t *tes
107116 require .ErrorContains (t , err , "~username syntax is not supported" )
108117 require .Equal (t , "" , path )
109118}
119+
120+ func TestMkdirAll_AbsPath_NotExists (t * testing.T ) {
121+ absPath := path .Join (t .TempDir (), "a/b/c" )
122+ require .NoDirExists (t , absPath )
123+ err := MkdirAll (context .Background (), absPath , - 1 , - 1 )
124+ require .NoError (t , err )
125+ require .DirExists (t , absPath )
126+ }
127+
128+ func TestMkdirAll_AbsPath_Exists (t * testing.T ) {
129+ absPath , err := os .Getwd ()
130+ require .NoError (t , err )
131+ err = MkdirAll (context .Background (), absPath , - 1 , - 1 )
132+ require .NoError (t , err )
133+ require .DirExists (t , absPath )
134+ }
135+
136+ func TestMkdirAll_RelPath_NotExists (t * testing.T ) {
137+ cwd := t .TempDir ()
138+ os .Chdir (cwd )
139+ relPath := "a/b/c"
140+ absPath := path .Join (cwd , relPath )
141+ require .NoDirExists (t , absPath )
142+ err := MkdirAll (context .Background (), relPath , - 1 , - 1 )
143+ require .NoError (t , err )
144+ require .DirExists (t , absPath )
145+ }
146+
147+ func TestMkdirAll_RelPath_Exists (t * testing.T ) {
148+ cwd := t .TempDir ()
149+ os .Chdir (cwd )
150+ relPath := "a/b/c"
151+ absPath := path .Join (cwd , relPath )
152+ err := os .MkdirAll (absPath , 0o755 )
153+ require .NoError (t , err )
154+ err = MkdirAll (context .Background (), relPath , - 1 , - 1 )
155+ require .NoError (t , err )
156+ require .DirExists (t , absPath )
157+ }
0 commit comments