| 1 | //go:build linux |
| 2 | |
| 3 | package main |
| 4 | |
| 5 | import ( |
| 6 | "os" |
| 7 | "path/filepath" |
| 8 | "testing" |
| 9 | ) |
| 10 | |
| 11 | func TestDirIsWritable(t *testing.T) { |
| 12 | dir := t.TempDir() |
| 13 | if !dirIsWritable(dir) { |
| 14 | t.Fatal("temp dir should be writable") |
| 15 | } |
| 16 | // A non-existent path is not writable. |
| 17 | if dirIsWritable(filepath.Join(dir, "missing-subdir")) { |
| 18 | t.Fatal("missing dir should not be writable") |
| 19 | } |
| 20 | } |
| 21 | |
| 22 | func TestDetectLinuxInstallProfilePortableWritable(t *testing.T) { |
| 23 | // When the test binary itself is not dpkg-owned (almost always true in CI |
| 24 | // workspaces), detection should land on portable if the binary dir is writable. |
| 25 | profile := detectLinuxInstallProfile() |
| 26 | if profile.Mode == installModeDeb { |
| 27 | // Running from a real .deb install in the developer's environment. |
| 28 | if !profile.RequiresElev || !profile.CanSelfUpdate { |
| 29 | t.Fatalf("deb profile incomplete: %+v", profile) |
| 30 | } |
| 31 | return |
| 32 | } |
| 33 | if profile.Mode == installModePortable { |
| 34 | if !profile.CanSelfUpdate || profile.ArtifactKind != artifactKindTarball { |
| 35 | t.Fatalf("portable profile incomplete: %+v", profile) |
| 36 | } |
| 37 | return |
| 38 | } |
| 39 | if profile.Mode != installModeManual { |
| 40 | t.Fatalf("unexpected mode: %+v", profile) |
| 41 | } |
| 42 | } |
| 43 | |
| 44 | func TestIsDpkgOwnedReasonixRejectsEmpty(t *testing.T) { |
| 45 | if isDpkgOwnedReasonix("") { |
| 46 | t.Fatal("empty path must not be dpkg-owned") |
| 47 | } |
| 48 | if isDpkgOwnedReasonix("relative/path") { |
| 49 | t.Fatal("relative path must not be dpkg-owned") |
| 50 | } |
| 51 | // A random absolute path that is not packaged. |
| 52 | if isDpkgOwnedReasonix(filepath.Join(t.TempDir(), "reasonix-desktop")) { |
| 53 | t.Fatal("unpackaged path must not be dpkg-owned") |
| 54 | } |
| 55 | } |
| 56 | |
| 57 | func TestLinuxDebHelperReadyAbsentInTemp(t *testing.T) { |
| 58 | // Unless the developer machine has the system helper installed, readiness |
| 59 | // should be false in typical test environments. |
| 60 | if _, err := os.Stat(linuxUpdateHelperPath); err == nil { |
| 61 | if !linuxDebHelperReady() { |
| 62 | t.Fatal("helper present but readiness false") |
| 63 | } |
| 64 | return |
| 65 | } |
| 66 | if linuxDebHelperReady() { |
| 67 | t.Fatal("helper absent but readiness true") |
| 68 | } |
| 69 | } |
| 70 |