|
| 1 | +//go:build darwin |
| 2 | + |
| 3 | +package util |
| 4 | + |
| 5 | +import ( |
| 6 | + "strings" |
| 7 | + "testing" |
| 8 | +) |
| 9 | + |
| 10 | +func TestGetSystemInfo(t *testing.T) { |
| 11 | + info := GetSystemInfo() |
| 12 | + |
| 13 | + if info["localizedName"] == "" { |
| 14 | + t.Error("localizedName is empty") |
| 15 | + } |
| 16 | + if info["name"] == "" { |
| 17 | + t.Error("name is empty") |
| 18 | + } |
| 19 | +} |
| 20 | + |
| 21 | +func TestUserHomeDir(t *testing.T) { |
| 22 | + dir, err := UserHomeDir() |
| 23 | + if err != nil { |
| 24 | + t.Fatalf("unexpected error: %v", err) |
| 25 | + } |
| 26 | + if !strings.HasPrefix(dir, "/") { |
| 27 | + t.Errorf("expected absolute path, got %q", dir) |
| 28 | + } |
| 29 | +} |
| 30 | + |
| 31 | +func TestUserCacheDir(t *testing.T) { |
| 32 | + dir, err := UserCacheDir() |
| 33 | + if err != nil { |
| 34 | + t.Fatalf("unexpected error: %v", err) |
| 35 | + } |
| 36 | + if !strings.HasPrefix(dir, "/") { |
| 37 | + t.Errorf("expected absolute path, got %q", dir) |
| 38 | + } |
| 39 | +} |
| 40 | + |
| 41 | +func TestShortenPath(t *testing.T) { |
| 42 | + home, err := UserHomeDir() |
| 43 | + if err != nil { |
| 44 | + t.Skip("could not get home dir") |
| 45 | + } |
| 46 | + |
| 47 | + cases := []struct { |
| 48 | + input string |
| 49 | + want string |
| 50 | + }{ |
| 51 | + {home, "~"}, |
| 52 | + {home + "/foo/bar", "~/foo/bar"}, |
| 53 | + {"/other/path", "/other/path"}, |
| 54 | + {"", ""}, |
| 55 | + } |
| 56 | + for _, c := range cases { |
| 57 | + if got := ShortenPath(c.input); got != c.want { |
| 58 | + t.Errorf("ShortenPath(%q) = %q, want %q", c.input, got, c.want) |
| 59 | + } |
| 60 | + } |
| 61 | +} |
0 commit comments