Skip to content

Commit

Permalink
unit test should not remove the xdg config path
Browse files Browse the repository at this point in the history
  • Loading branch information
creativeprojects committed Jul 1, 2020
1 parent 5e4132f commit 4315bc6
Showing 1 changed file with 37 additions and 30 deletions.
67 changes: 37 additions & 30 deletions filesearch/filesearch_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -46,10 +46,11 @@ func TestDefaultConfigDirs(t *testing.T) {
}

type testLocation struct {
realPath string
realFile string
searchPath string
searchFile string
realPath string
realFile string
searchPath string
searchFile string
deletePathAfter bool
}

func TestFindConfigurationFile(t *testing.T) {
Expand Down Expand Up @@ -101,40 +102,46 @@ func TestFindConfigurationFile(t *testing.T) {
searchFile: "profiles",
},
{
realPath: "unittest-config",
realFile: "profiles.spec",
searchPath: "unittest-config",
searchFile: "profiles.spec",
realPath: "unittest-config",
realFile: "profiles.spec",
searchPath: "unittest-config",
searchFile: "profiles.spec",
deletePathAfter: true,
},
{
realPath: "unittest-config",
realFile: "profiles.conf",
searchPath: "unittest-config",
searchFile: "profiles",
realPath: "unittest-config",
realFile: "profiles.conf",
searchPath: "unittest-config",
searchFile: "profiles",
deletePathAfter: true,
},
{
realPath: "unittest-config",
realFile: "profiles.toml",
searchPath: "unittest-config",
searchFile: "profiles",
realPath: "unittest-config",
realFile: "profiles.toml",
searchPath: "unittest-config",
searchFile: "profiles",
deletePathAfter: true,
},
{
realPath: "unittest-config",
realFile: "profiles.yaml",
searchPath: "unittest-config",
searchFile: "profiles",
realPath: "unittest-config",
realFile: "profiles.yaml",
searchPath: "unittest-config",
searchFile: "profiles",
deletePathAfter: true,
},
{
realPath: "unittest-config",
realFile: "profiles.json",
searchPath: "unittest-config",
searchFile: "profiles",
realPath: "unittest-config",
realFile: "profiles.json",
searchPath: "unittest-config",
searchFile: "profiles",
deletePathAfter: true,
},
{
realPath: "unittest-config",
realFile: "profiles.hcl",
searchPath: "unittest-config",
searchFile: "profiles",
realPath: "unittest-config",
realFile: "profiles.hcl",
searchPath: "unittest-config",
searchFile: "profiles",
deletePathAfter: true,
},
{
realPath: filepath.Join(xdg.ConfigHome, "resticprofile"),
Expand Down Expand Up @@ -191,8 +198,8 @@ func TestFindConfigurationFile(t *testing.T) {
assert.Equal(t, filepath.Join(location.realPath, location.realFile), found)

// Clears up the test file
if location.realPath == "" {
err = os.Remove(location.realFile)
if location.realPath == "" || !location.deletePathAfter {
err = os.Remove(filepath.Join(location.realPath, location.realFile))
} else {
err = os.RemoveAll(location.realPath)
}
Expand Down

0 comments on commit 4315bc6

Please sign in to comment.