Skip to content

Commit

Permalink
Update macOS & Windows tests
Browse files Browse the repository at this point in the history
  • Loading branch information
muesli committed Mar 14, 2020
1 parent c8dc183 commit a58ff73
Show file tree
Hide file tree
Showing 2 changed files with 84 additions and 6 deletions.
45 changes: 42 additions & 3 deletions paths_darwin_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,12 +12,43 @@ func TestPaths(t *testing.T) {
dataDir string
cacheDir string
configFile string
dataFile string
logFile string
}{
{NewScope(System, "foobar"), "/Library/Application Support/foobar", "/Library/Caches/foobar", "/Library/Preferences/foobar/foobar.conf", "/Library/Logs/foobar/foobar.log"},
{NewScope(User, "foobar"), "~/Library/Application Support/foobar", "~/Library/Caches/foobar", "~/Library/Preferences/foobar/foobar.conf", "~/Library/Logs/foobar/foobar.log"},
{NewCustomHomeScope("/tmp", "", "foobar"), "/tmp/Library/Application Support/foobar", "/tmp/Library/Caches/foobar", "/tmp/Library/Preferences/foobar/foobar.conf", "/tmp/Library/Logs/foobar/foobar.log"},
{
scope: NewScope(System, "foobar"),
dataDir: "/Library/Application Support/foobar",
cacheDir: "/Library/Caches/foobar",
configFile: "/Library/Preferences/foobar/foobar.conf",
dataFile: "/Library/Application Support/foobar/foobar.data",
logFile: "/Library/Logs/foobar/foobar.log",
},
{
scope: NewVendorScope(System, "barcorp", "foobar"),
dataDir: "/Library/Application Support/barcorp/foobar",
cacheDir: "/Library/Caches/barcorp/foobar",
configFile: "/Library/Preferences/barcorp/foobar/foobar.conf",
dataFile: "/Library/Application Support/barcorp/foobar/foobar.data",
logFile: "/Library/Logs/barcorp/foobar/foobar.log",
},
{
scope: NewScope(User, "foobar"),
dataDir: "~/Library/Application Support/foobar",
cacheDir: "~/Library/Caches/foobar",
configFile: "~/Library/Preferences/foobar/foobar.conf",
dataFile: "~/Library/Application Support/foobar/foobar.data",
logFile: "~/Library/Logs/foobar/foobar.log",
},
{
scope: NewCustomHomeScope("/tmp", "", "foobar"),
dataDir: "/tmp/Library/Application Support/foobar",
cacheDir: "/tmp/Library/Caches/foobar",
configFile: "/tmp/Library/Preferences/foobar/foobar.conf",
dataFile: "/tmp/Library/Application Support/foobar/foobar.data",
logFile: "/tmp/Library/Logs/foobar/foobar.log",
},
}

for _, tt := range tests {
paths, err := tt.scope.DataDirs()
if err != nil {
Expand All @@ -43,6 +74,14 @@ func TestPaths(t *testing.T) {
t.Errorf("Expected config path: %s - got: %s", tt.configFile, path)
}

path, err = tt.scope.DataPath(tt.scope.App + ".data")
if err != nil {
t.Errorf("Error retrieving data path: %s", err)
}
if path != expandUser(tt.dataFile) {
t.Errorf("Expected data path: %s - got: %s", tt.dataFile, path)
}

path, err = tt.scope.LogPath(tt.scope.App + ".log")
if err != nil {
t.Errorf("Error retrieving log path: %s", err)
Expand Down
45 changes: 42 additions & 3 deletions paths_windows_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,12 +12,43 @@ func TestPaths(t *testing.T) {
dataDir string
cacheDir string
configFile string
dataFile string
logFile string
}{
{NewScope(System, "foobar"), "C:\\ProgramData\\foobar", "C:\\ProgramData\\foobar\\Cache", "C:\\ProgramData\\foobar\\Config\\foobar.conf", "C:\\ProgramData\\foobar\\Logs\\foobar.log"},
{NewScope(User, "foobar"), "C:\\Users\\runneradmin\\AppData\\Local\\foobar", "C:\\Users\\runneradmin\\AppData\\Local\\foobar\\Cache", "C:\\Users\\runneradmin\\AppData\\Local\\foobar\\Config\\foobar.conf", "C:\\Users\\runneradmin\\AppData\\Local\\foobar\\Logs\\foobar.log"},
{NewCustomHomeScope("C:\\tmp", "", "foobar"), "C:\\tmp", "C:\\tmp\\Cache", "C:\\tmp\\Config\\foobar.conf", "C:\\tmp\\Logs\\foobar.log"},
{
scope: NewScope(System, "foobar"),
dataDir: "C:\\ProgramData\\foobar",
cacheDir: "C:\\ProgramData\\foobar\\Cache",
configFile: "C:\\ProgramData\\foobar\\Config\\foobar.conf",
dataFile: "C:\\ProgramData\\foobar\\foobar.data",
logFile: "C:\\ProgramData\\foobar\\Logs\\foobar.log",
},
{
scope: NewVendorScope(System, "barcorp", "foobar"),
dataDir: "C:\\ProgramData\\barcorp\\foobar",
cacheDir: "C:\\ProgramData\\barcorp\\foobar\\Cache",
configFile: "C:\\ProgramData\\barcorp\\foobar\\Config\\foobar.conf",
dataFile: "C:\\ProgramData\\barcorp\\foobar\\foobar.data",
logFile: "C:\\ProgramData\\barcorp\\foobar\\Logs\\foobar.log",
},
{
scope: NewScope(User, "foobar"),
dataDir: "C:\\Users\\runneradmin\\AppData\\Local\\foobar",
cacheDir: "C:\\Users\\runneradmin\\AppData\\Local\\foobar\\Cache",
configFile: "C:\\Users\\runneradmin\\AppData\\Local\\foobar\\Config\\foobar.conf",
dataFile: "C:\\Users\\runneradmin\\AppData\\Local\\foobar\\foobar.data",
logFile: "C:\\Users\\runneradmin\\AppData\\Local\\foobar\\Logs\\foobar.log",
},
{
scope: NewCustomHomeScope("C:\\tmp", "", "foobar"),
dataDir: "C:\\tmp",
cacheDir: "C:\\tmp\\Cache",
configFile: "C:\\tmp\\Config\\foobar.conf",
dataFile: "C:\\tmp\\foobar.data",
logFile: "C:\\tmp\\Logs\\foobar.log",
},
}

for _, tt := range tests {
paths, err := tt.scope.DataDirs()
if err != nil {
Expand All @@ -43,6 +74,14 @@ func TestPaths(t *testing.T) {
t.Errorf("Expected config path: %s - got: %s", tt.configFile, path)
}

path, err = tt.scope.DataPath(tt.scope.App + ".data")
if err != nil {
t.Errorf("Error retrieving data path: %s", err)
}
if path != expandUser(tt.dataFile) {
t.Errorf("Expected data path: %s - got: %s", tt.dataFile, path)
}

path, err = tt.scope.LogPath(tt.scope.App + ".log")
if err != nil {
t.Errorf("Error retrieving log path: %s", err)
Expand Down

0 comments on commit a58ff73

Please sign in to comment.