mirror of
https://github.com/AvengeMedia/DankMaterialShell.git
synced 2026-10-16 16:24:00 -04:00
cards: fix regression that created borders matugen: run on a low priority worker and seeds dms-colors before other templates
159 lines
4.1 KiB
Go
159 lines
4.1 KiB
Go
package utils
|
|
|
|
import (
|
|
"os"
|
|
"path/filepath"
|
|
"strings"
|
|
"testing"
|
|
)
|
|
|
|
func TestFlatpakInPathUnavailable(t *testing.T) {
|
|
tempDir := t.TempDir()
|
|
t.Setenv("PATH", tempDir)
|
|
|
|
result := FlatpakInPath()
|
|
if result {
|
|
t.Errorf("expected false when flatpak not in PATH, got true")
|
|
}
|
|
}
|
|
|
|
func TestFlatpakExistsNoFlatpak(t *testing.T) {
|
|
tempDir := t.TempDir()
|
|
t.Setenv("PATH", tempDir)
|
|
|
|
result := FlatpakExists("any.package.name")
|
|
if result {
|
|
t.Errorf("expected false when flatpak not in PATH, got true")
|
|
}
|
|
}
|
|
|
|
func TestFlatpakSearchBySubstringNoFlatpak(t *testing.T) {
|
|
tempDir := t.TempDir()
|
|
t.Setenv("PATH", tempDir)
|
|
|
|
result := FlatpakSearchBySubstring("test")
|
|
if result {
|
|
t.Errorf("expected false when flatpak not in PATH, got true")
|
|
}
|
|
}
|
|
|
|
func TestFlatpakInstallationDirNoFlatpak(t *testing.T) {
|
|
tempDir := t.TempDir()
|
|
t.Setenv("PATH", tempDir)
|
|
|
|
_, err := FlatpakInstallationDir("any.package.name")
|
|
if err == nil {
|
|
t.Errorf("expected error when flatpak not in PATH")
|
|
}
|
|
if err != nil && !strings.Contains(err.Error(), "not found in PATH") {
|
|
t.Errorf("expected 'not found in PATH' error, got: %v", err)
|
|
}
|
|
}
|
|
|
|
func TestFlatpakSearchBySubstringCommandFailure(t *testing.T) {
|
|
if !FlatpakInPath() {
|
|
t.Skip("flatpak not in PATH")
|
|
}
|
|
|
|
// Mock a failing flatpak command through PATH interception
|
|
tempDir := t.TempDir()
|
|
fakeFlatpak := filepath.Join(tempDir, "flatpak")
|
|
|
|
script := "#!/bin/sh\nexit 1\n"
|
|
err := os.WriteFile(fakeFlatpak, []byte(script), 0o755)
|
|
if err != nil {
|
|
t.Fatalf("failed to create fake flatpak: %v", err)
|
|
}
|
|
|
|
originalPath := os.Getenv("PATH")
|
|
t.Setenv("PATH", tempDir+":"+originalPath)
|
|
|
|
result := FlatpakSearchBySubstring("test")
|
|
if result {
|
|
t.Errorf("expected false when flatpak command fails, got true")
|
|
}
|
|
}
|
|
|
|
func TestFlatpakInstallationDirCommandFailure(t *testing.T) {
|
|
if !FlatpakInPath() {
|
|
t.Skip("flatpak not in PATH")
|
|
}
|
|
|
|
// Mock a failing flatpak command through PATH interception
|
|
tempDir := t.TempDir()
|
|
fakeFlatpak := filepath.Join(tempDir, "flatpak")
|
|
|
|
script := "#!/bin/sh\nexit 1\n"
|
|
err := os.WriteFile(fakeFlatpak, []byte(script), 0o755)
|
|
if err != nil {
|
|
t.Fatalf("failed to create fake flatpak: %v", err)
|
|
}
|
|
|
|
originalPath := os.Getenv("PATH")
|
|
t.Setenv("PATH", tempDir+":"+originalPath)
|
|
|
|
_, err = FlatpakInstallationDir("test.package")
|
|
if err == nil {
|
|
t.Errorf("expected error when flatpak command fails")
|
|
}
|
|
if err != nil && !strings.Contains(err.Error(), "not installed") {
|
|
t.Errorf("expected 'not installed' error, got: %v", err)
|
|
}
|
|
}
|
|
|
|
func TestAnyFlatpakExistsNoFlatpak(t *testing.T) {
|
|
tempDir := t.TempDir()
|
|
t.Setenv("PATH", tempDir)
|
|
|
|
result := AnyFlatpakExists("any.package.name", "another.package")
|
|
if result {
|
|
t.Errorf("expected false when flatpak not in PATH, got true")
|
|
}
|
|
}
|
|
|
|
func TestAnyFlatpakExistsEmpty(t *testing.T) {
|
|
result := AnyFlatpakExists()
|
|
if result {
|
|
t.Errorf("expected false when no flatpaks specified")
|
|
}
|
|
}
|
|
|
|
func TestFlatpakExistsByInstallationDir(t *testing.T) {
|
|
if !FlatpakInPath() {
|
|
t.Skip("flatpak not in PATH")
|
|
}
|
|
user := t.TempDir()
|
|
system := t.TempDir()
|
|
extra := t.TempDir()
|
|
confDir := t.TempDir()
|
|
t.Setenv("FLATPAK_USER_DIR", user)
|
|
t.Setenv("FLATPAK_SYSTEM_DIR", system)
|
|
old := flatpakInstallationsDir
|
|
flatpakInstallationsDir = confDir
|
|
t.Cleanup(func() { flatpakInstallationsDir = old })
|
|
|
|
if err := os.MkdirAll(filepath.Join(user, "app", "app.user.test"), 0o755); err != nil {
|
|
t.Fatal(err)
|
|
}
|
|
if err := os.MkdirAll(filepath.Join(extra, "app", "app.extra.test"), 0o755); err != nil {
|
|
t.Fatal(err)
|
|
}
|
|
conf := "[Installation \"extra\"]\nPath=" + extra + "\n"
|
|
if err := os.WriteFile(filepath.Join(confDir, "extra.conf"), []byte(conf), 0o644); err != nil {
|
|
t.Fatal(err)
|
|
}
|
|
|
|
if !FlatpakExists("app.user.test") {
|
|
t.Errorf("expected app in the user installation to be found")
|
|
}
|
|
if !FlatpakExists("app.extra.test") {
|
|
t.Errorf("expected app in an installations.d path to be found")
|
|
}
|
|
if FlatpakExists("app.missing.test") {
|
|
t.Errorf("expected missing app to be reported absent")
|
|
}
|
|
if !AnyFlatpakExists("app.missing.test", "app.user.test") {
|
|
t.Errorf("expected AnyFlatpakExists to find the installed app")
|
|
}
|
|
}
|