@@ -40,6 +40,8 @@ func TestMain(t *testing.M) {
4040// ConfigDirs: [C:\ProgramData C:\Users\runneradmin\AppData\Roaming]
4141// ApplicationDirs: [C:\Users\runneradmin\AppData\Roaming\Microsoft\Windows\Start Menu\Programs C:\ProgramData\Microsoft\Windows\Start Menu\Programs]
4242func TestDefaultConfigDirs (t * testing.T ) {
43+ t .Parallel ()
44+
4345 t .Log ("ConfigHome:" , xdg .ConfigHome )
4446 t .Log ("ConfigDirs:" , xdg .ConfigDirs )
4547 t .Log ("ApplicationDirs:" , xdg .ApplicationDirs )
@@ -192,6 +194,8 @@ func testLocations(t *testing.T) []testLocation {
192194}
193195
194196func TestFindConfigurationFile (t * testing.T ) {
197+ t .Parallel ()
198+
195199 // Work from a temporary directory
196200 err := os .Chdir (os .TempDir ())
197201 require .NoError (t , err )
@@ -206,7 +210,7 @@ func TestFindConfigurationFile(t *testing.T) {
206210 var err error
207211 // Install empty config file
208212 if location .realPath != "" {
209- err = fs .MkdirAll (location .realPath , 0700 )
213+ err = fs .MkdirAll (location .realPath , 0o700 )
210214 require .NoError (t , err )
211215 }
212216 file , err := fs .Create (filepath .Join (location .realPath , location .realFile ))
@@ -230,12 +234,16 @@ func TestFindConfigurationFile(t *testing.T) {
230234}
231235
232236func TestCannotFindConfigurationFile (t * testing.T ) {
237+ t .Parallel ()
238+
233239 found , err := FindConfigurationFile ("some_config_file" )
234240 assert .Empty (t , found )
235241 assert .Error (t , err )
236242}
237243
238244func TestFindResticBinary (t * testing.T ) {
245+ t .Parallel ()
246+
239247 binary , err := FindResticBinary ("some_other_name" )
240248 if binary != "" {
241249 assert .True (t , strings .HasSuffix (binary , getResticBinaryName ()))
@@ -246,14 +254,16 @@ func TestFindResticBinary(t *testing.T) {
246254}
247255
248256func TestFindResticBinaryWithTilde (t * testing.T ) {
257+ t .Parallel ()
258+
249259 if runtime .GOOS == "windows" {
250260 t .Skip ("not supported on Windows" )
251261 return
252262 }
253263 home , err := os .UserHomeDir ()
254264 require .NoError (t , err )
255265
256- tempFile , err := afero .TempFile (fs , home , "TestFindResticBinaryWithTilde" )
266+ tempFile , err := afero .TempFile (fs , home , t . Name () )
257267 require .NoError (t , err )
258268 tempFile .Close ()
259269 defer func () {
@@ -267,6 +277,8 @@ func TestFindResticBinaryWithTilde(t *testing.T) {
267277}
268278
269279func TestShellExpand (t * testing.T ) {
280+ t .Parallel ()
281+
270282 if runtime .GOOS == "windows" {
271283 t .Skip ("not supported on Windows" )
272284 return
@@ -290,6 +302,8 @@ func TestShellExpand(t *testing.T) {
290302
291303 for _ , testItem := range testData {
292304 t .Run (testItem .source , func (t * testing.T ) {
305+ t .Parallel ()
306+
293307 result , err := ShellExpand (testItem .source )
294308 require .NoError (t , err )
295309 assert .Equal (t , testItem .expected , result )
@@ -298,6 +312,8 @@ func TestShellExpand(t *testing.T) {
298312}
299313
300314func TestFindConfigurationIncludes (t * testing.T ) {
315+ t .Parallel ()
316+
301317 testID := fmt .Sprintf ("%d" , uint32 (time .Now ().UnixNano ()))
302318 tempDir := os .TempDir ()
303319 files := []string {
@@ -309,7 +325,9 @@ func TestFindConfigurationIncludes(t *testing.T) {
309325
310326 for _ , file := range files {
311327 require .NoError (t , afero .WriteFile (fs , file , []byte {}, iofs .ModePerm ))
312- defer fs .Remove (file ) // defer stack is ok for cleanup
328+ t .Cleanup (func () {
329+ _ = fs .Remove (file )
330+ })
313331 }
314332
315333 testData := []struct {
@@ -335,6 +353,8 @@ func TestFindConfigurationIncludes(t *testing.T) {
335353
336354 for _ , test := range testData {
337355 t .Run (strings .Join (test .includes , "," ), func (t * testing.T ) {
356+ t .Parallel ()
357+
338358 result , err := FindConfigurationIncludes (files [0 ], test .includes )
339359 if test .expected == nil {
340360 assert .Nil (t , result )
@@ -350,3 +370,36 @@ func TestFindConfigurationIncludes(t *testing.T) {
350370 })
351371 }
352372}
373+
374+ func TestAddRootToRelativePaths (t * testing.T ) {
375+ t .Parallel ()
376+
377+ if platform .IsWindows () {
378+ t .Skip ("not supported on Windows" )
379+ }
380+
381+ testCases := []struct {
382+ root string
383+ inputPath []string
384+ outputPath []string
385+ }{
386+ {
387+ root : "" ,
388+ inputPath : []string {"" , "dir" , "~/user" , "/root" },
389+ outputPath : []string {"" , "dir" , "~/user" , "/root" },
390+ },
391+ {
392+ root : "/home" ,
393+ inputPath : []string {"" , "dir" , "~/user" , "/root" },
394+ outputPath : []string {"/home" , "/home/dir" , "/home/user" , "/root" },
395+ },
396+ }
397+ for _ , testCase := range testCases {
398+ t .Run (testCase .root , func (t * testing.T ) {
399+ t .Parallel ()
400+
401+ result := addRootToRelativePaths (testCase .root , testCase .inputPath )
402+ assert .Equal (t , testCase .outputPath , result )
403+ })
404+ }
405+ }
0 commit comments