A shepherd for your Appimages.
0

Configure Feed

Select the types of activity you want to include in your feed.

improve tests

Aly Raffauf (Jun 17, 2026, 5:27 PM EDT) eea48c1c 26e721a4

+18 -41
+18 -29
cmd/appherder/appimage_test.go
··· 2 2 3 3 import ( 4 4 "bytes" 5 - "encoding/binary" 6 5 "errors" 7 6 "os" 8 7 "path/filepath" 9 8 "testing" 10 9 ) 11 10 12 - // elfHeader builds a minimal little-endian ELF header with the given class 13 - // (1=32-bit, 2=64-bit) and section-header-table fields. 14 - func elfHeader(class byte, shoff uint64, shentsize, shnum uint16) []byte { 15 - h := make([]byte, 64) 16 - copy(h, []byte{0x7f, 'E', 'L', 'F'}) 17 - h[4] = class 18 - h[5] = 1 // little-endian 19 - if class == 2 { 20 - binary.LittleEndian.PutUint64(h[40:48], shoff) 21 - binary.LittleEndian.PutUint16(h[58:60], shentsize) 22 - binary.LittleEndian.PutUint16(h[60:62], shnum) 23 - } else { 24 - binary.LittleEndian.PutUint32(h[32:36], uint32(shoff)) 25 - binary.LittleEndian.PutUint16(h[46:48], shentsize) 26 - binary.LittleEndian.PutUint16(h[48:50], shnum) 11 + func TestAppImageSquashfsOffset(t *testing.T) { 12 + // First 64 bytes of a real type-2 ELF64 AppImage (appimagetool), whose 13 + // squashfs payload begins at the offset asserted below. 14 + header := []byte{ 15 + 0x7f, 0x45, 0x4c, 0x46, 0x02, 0x01, 0x01, 0x00, 0x41, 0x49, 0x02, 0x00, 16 + 0x00, 0x00, 0x00, 0x00, 0x03, 0x00, 0x3e, 0x00, 0x01, 0x00, 0x00, 0x00, 17 + 0x87, 0xae, 0x02, 0x00, 0x00, 0x00, 0x00, 0x00, 0x40, 0x00, 0x00, 0x00, 18 + 0x00, 0x00, 0x00, 0x00, 0x78, 0x62, 0x0e, 0x00, 0x00, 0x00, 0x00, 0x00, 19 + 0x00, 0x00, 0x00, 0x00, 0x40, 0x00, 0x38, 0x00, 0x0a, 0x00, 0x40, 0x00, 20 + 0x1e, 0x00, 0x1d, 0x00, 21 + } 22 + got, err := appImageSquashfsOffset(bytes.NewReader(header)) 23 + if err != nil { 24 + t.Fatal(err) 27 25 } 28 - return h 29 - } 30 - 31 - func TestAppImageSquashfsOffset(t *testing.T) { 32 - for _, class := range []byte{1, 2} { 33 - got, err := appImageSquashfsOffset(bytes.NewReader(elfHeader(class, 1000, 64, 10))) 34 - if err != nil { 35 - t.Fatalf("class %d: %v", class, err) 36 - } 37 - if want := int64(1000 + 64*10); got != want { 38 - t.Fatalf("class %d: offset = %d, want %d", class, got, want) 39 - } 26 + if want := int64(944632); got != want { 27 + t.Fatalf("offset = %d, want %d", got, want) 40 28 } 41 29 } 42 30 ··· 47 35 } 48 36 49 37 func TestAppImageSquashfsOffsetRejectsType1(t *testing.T) { 50 - h := elfHeader(2, 1000, 64, 10) 38 + h := make([]byte, 64) 39 + copy(h, []byte{0x7f, 'E', 'L', 'F'}) 51 40 h[8], h[9], h[10] = 'A', 'I', 1 52 41 if _, err := appImageSquashfsOffset(bytes.NewReader(h)); err == nil { 53 42 t.Fatal("expected error for type-1 AppImage")
-12
cmd/appherder/uninstall_test.go
··· 28 28 } 29 29 } 30 30 31 - func TestInstalledPaths(t *testing.T) { 32 - got := installedPaths("/home/test", "example") 33 - want := []string{ 34 - "/home/test/AppImages/example.appimage", 35 - "/home/test/AppImages/.icons/example", 36 - "/home/test/.local/share/applications/example.desktop", 37 - } 38 - if !reflect.DeepEqual(got, want) { 39 - t.Fatalf("installedPaths() = %#v, want %#v", got, want) 40 - } 41 - } 42 - 43 31 func TestUninstallRemovesInstalledFilesOnly(t *testing.T) { 44 32 home := t.TempDir() 45 33 for _, path := range installedPaths(home, "example") {