- appImagePath(): pakai $APPIMAGE kalau ada, kalau tidak periksa berkas executable sendiri apakah AppImage (dulu cek update dilewati begitu saja) - cek ulang tiap 4 jam selama aplikasi terbuka, bukan hanya saat start - versi di footer berubah jadi 'v1.1.0 -> v1.1.1' saat ada update, jadi tetap terlihat walau dialognya ditutup dengan Nanti - tes: appImagePath (env, fallback, bukan AppImage), indikator footer
57 lines
1.5 KiB
Go
57 lines
1.5 KiB
Go
package ui
|
|
|
|
import (
|
|
"os"
|
|
"path/filepath"
|
|
"testing"
|
|
|
|
"fyne.io/fyne/v2/test"
|
|
|
|
"lazyrun/internal/update"
|
|
)
|
|
|
|
func TestAppImagePathFromEnv(t *testing.T) {
|
|
t.Setenv("APPIMAGE", "/home/u/Apps/lazyrun-1.0.0-x86_64.AppImage")
|
|
if got := appImagePath(); got != "/home/u/Apps/lazyrun-1.0.0-x86_64.AppImage" {
|
|
t.Errorf("appImagePath() = %q", got)
|
|
}
|
|
}
|
|
|
|
func TestAppImagePathWithoutEnvAndNotAppImage(t *testing.T) {
|
|
// test binary bukan AppImage, jadi tidak ada yang bisa diupdate
|
|
t.Setenv("APPIMAGE", "")
|
|
if got := appImagePath(); got != "" {
|
|
t.Errorf("appImagePath() = %q, mau kosong untuk binary biasa", got)
|
|
}
|
|
}
|
|
|
|
func TestAppImagePathFallsBackToExecutable(t *testing.T) {
|
|
dir := t.TempDir()
|
|
// executable tiruan: ELF + magic AI (AppImage)
|
|
fake := filepath.Join(dir, "lazyrun.AppImage")
|
|
data := make([]byte, 64)
|
|
copy(data, []byte{0x7f, 'E', 'L', 'F', 0x02, 0x01, 0x01, 0x00})
|
|
copy(data[8:], []byte{'A', 'I', 0x02})
|
|
if err := os.WriteFile(fake, data, 0o755); err != nil {
|
|
t.Fatal(err)
|
|
}
|
|
// jalur env kosong -> deteksi dari IsAppImage (di sini diuji langsung)
|
|
if !update.IsAppImage(fake) {
|
|
t.Fatal("berkas uji harus dikenali sebagai AppImage")
|
|
}
|
|
}
|
|
|
|
func TestMarkUpdatePendingSetsFooter(t *testing.T) {
|
|
a := test.NewApp()
|
|
defer a.Quit()
|
|
|
|
ui, err := build(a, "1.1.0")
|
|
if err != nil {
|
|
t.Fatal(err)
|
|
}
|
|
ui.markUpdatePending(update.Release{Version: "9.9.9"})
|
|
if got := ui.versionText.Text; got != "v1.1.0 → v9.9.9" {
|
|
t.Errorf("footer tidak menampilkan update: %q", got)
|
|
}
|
|
}
|