| 1 |
package userdirs |
| 2 |
|
| 3 |
import ( |
| 4 |
"os/exec" |
| 5 |
"strings" |
| 6 |
"testing" |
| 7 |
) |
| 8 |
|
| 9 |
// XdgUserDir runs the xdg-user-dir command with the given argument. |
| 10 |
func XdgUserDir(s string) string { |
| 11 |
out, err := exec.Command("xdg-user-dir", s).Output() |
| 12 |
if err != nil { |
| 13 |
panic(err) |
| 14 |
} |
| 15 |
return strings.TrimSpace(string(out)) |
| 16 |
} |
| 17 |
|
| 18 |
func doTest(t *testing.T, s1, s2 string) { |
| 19 |
t.Log(s1) |
| 20 |
t.Log(s2) |
| 21 |
if s1 != s2 { |
| 22 |
t.Fail() |
| 23 |
} |
| 24 |
} |
| 25 |
|
| 26 |
func TestDesktop(t *testing.T) { |
| 27 |
doTest(t, Desktop, XdgUserDir("DESKTOP")) |
| 28 |
} |
| 29 |
|
| 30 |
func TestDocuments(t *testing.T) { |
| 31 |
doTest(t, Documents, XdgUserDir("DOCUMENTS")) |
| 32 |
} |
| 33 |
|
| 34 |
func TestDownload(t *testing.T) { |
| 35 |
doTest(t, Download, XdgUserDir("DOWNLOAD")) |
| 36 |
} |
| 37 |
|
| 38 |
func TestMusic(t *testing.T) { |
| 39 |
doTest(t, Music, XdgUserDir("MUSIC")) |
| 40 |
} |
| 41 |
|
| 42 |
func TestPictures(t *testing.T) { |
| 43 |
doTest(t, Pictures, XdgUserDir("PICTURES")) |
| 44 |
} |
| 45 |
|
| 46 |
func TestPublicShare(t *testing.T) { |
| 47 |
doTest(t, PublicShare, XdgUserDir("PUBLICSHARE")) |
| 48 |
} |
| 49 |
|
| 50 |
func TestTemplates(t *testing.T) { |
| 51 |
doTest(t, Templates, XdgUserDir("TEMPLATES")) |
| 52 |
} |
| 53 |
|
| 54 |
func TestVideos(t *testing.T) { |
| 55 |
doTest(t, Videos, XdgUserDir("VIDEOS")) |
| 56 |
} |