A shepherd for your Appimages.
0

Configure Feed

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

remove stupid tests

Aly Raffauf (Jun 17, 2026, 2:50 PM EDT) 69d6a756 655f99c2

+85 -219
-128
src/appimage_test.go
··· 1 - package main 2 - 3 - import ( 4 - "os" 5 - "path/filepath" 6 - "reflect" 7 - "testing" 8 - ) 9 - 10 - func TestExtractAppImageUsesDestinationAsWorkingDirectory(t *testing.T) { 11 - dir := t.TempDir() 12 - source := filepath.Join(dir, "source.appimage") 13 - extractDest := filepath.Join(dir, "extract") 14 - if err := os.WriteFile(source, []byte("appimage"), 0o644); err != nil { 15 - t.Fatal(err) 16 - } 17 - if err := os.Mkdir(extractDest, 0o755); err != nil { 18 - t.Fatal(err) 19 - } 20 - 21 - var gotName string 22 - var gotArgs []string 23 - var gotDir string 24 - a := app{ 25 - run: func(name string, args []string, dir string) error { 26 - gotName = name 27 - gotArgs = args 28 - gotDir = dir 29 - return nil 30 - }, 31 - } 32 - 33 - extracted, err := a.extractAppImage(source, extractDest) 34 - if err != nil { 35 - t.Fatal(err) 36 - } 37 - 38 - absSource, err := filepath.Abs(source) 39 - if err != nil { 40 - t.Fatal(err) 41 - } 42 - if gotName != absSource { 43 - t.Fatalf("command name = %q, want %q", gotName, absSource) 44 - } 45 - if !reflect.DeepEqual(gotArgs, []string{"--appimage-extract"}) { 46 - t.Fatalf("command args = %#v", gotArgs) 47 - } 48 - if gotDir != extractDest { 49 - t.Fatalf("command dir = %q, want %q", gotDir, extractDest) 50 - } 51 - if extracted != filepath.Join(extractDest, "squashfs-root") { 52 - t.Fatalf("extracted = %q", extracted) 53 - } 54 - if mode := fileMode(source); mode != 0o755 { 55 - t.Fatalf("source mode = %#o, want 0755", mode) 56 - } 57 - } 58 - 59 - func TestInstallAppImageCopiesToAppImagesDir(t *testing.T) { 60 - dir := t.TempDir() 61 - home := filepath.Join(dir, "home") 62 - source := filepath.Join(dir, "source.appimage") 63 - if err := os.WriteFile(source, []byte("appimage"), 0o644); err != nil { 64 - t.Fatal(err) 65 - } 66 - 67 - a := app{homeDir: func() (string, error) { return home, nil }} 68 - dest, err := a.installAppImage(source, "test") 69 - if err != nil { 70 - t.Fatal(err) 71 - } 72 - 73 - want := filepath.Join(home, "AppImages", "test.appimage") 74 - if dest != want { 75 - t.Fatalf("dest = %q, want %q", dest, want) 76 - } 77 - data, err := os.ReadFile(dest) 78 - if err != nil { 79 - t.Fatal(err) 80 - } 81 - if string(data) != "appimage" { 82 - t.Fatalf("installed data = %q", data) 83 - } 84 - if mode := fileMode(dest); mode&0o100 == 0 { 85 - t.Fatalf("installed file is not user-executable: %#o", mode) 86 - } 87 - } 88 - 89 - func TestInstallAppImageReplacesExistingFile(t *testing.T) { 90 - dir := t.TempDir() 91 - home := filepath.Join(dir, "home") 92 - appimages := filepath.Join(home, "AppImages") 93 - if err := os.MkdirAll(appimages, 0o755); err != nil { 94 - t.Fatal(err) 95 - } 96 - 97 - existing := filepath.Join(appimages, "test.appimage") 98 - if err := os.WriteFile(existing, []byte("old"), 0o755); err != nil { 99 - t.Fatal(err) 100 - } 101 - source := filepath.Join(dir, "source.appimage") 102 - if err := os.WriteFile(source, []byte("new"), 0o644); err != nil { 103 - t.Fatal(err) 104 - } 105 - 106 - a := app{homeDir: func() (string, error) { return home, nil }} 107 - dest, err := a.installAppImage(source, "test") 108 - if err != nil { 109 - t.Fatal(err) 110 - } 111 - if dest != existing { 112 - t.Fatalf("dest = %q, want %q", dest, existing) 113 - } 114 - data, err := os.ReadFile(existing) 115 - if err != nil { 116 - t.Fatal(err) 117 - } 118 - if string(data) != "new" { 119 - t.Fatalf("replacement data = %q", data) 120 - } 121 - matches, err := filepath.Glob(filepath.Join(appimages, "*.tmp")) 122 - if err != nil { 123 - t.Fatal(err) 124 - } 125 - if len(matches) != 0 { 126 - t.Fatalf("temporary files left behind: %#v", matches) 127 - } 128 - }
-36
src/cli_test.go
··· 1 - package main 2 - 3 - import ( 4 - "bytes" 5 - "testing" 6 - ) 7 - 8 - func TestInstallCommandRequiresAppImage(t *testing.T) { 9 - var stdout bytes.Buffer 10 - var stderr bytes.Buffer 11 - 12 - cmd := newRootCommand(app{}, &stdout, &stderr) 13 - cmd.SetArgs([]string{"install"}) 14 - 15 - if err := cmd.Execute(); err == nil { 16 - t.Fatal("expected install without APPIMAGE to fail") 17 - } 18 - } 19 - 20 - func TestRootHelpMentionsInstallCommand(t *testing.T) { 21 - var stdout bytes.Buffer 22 - var stderr bytes.Buffer 23 - 24 - cmd := newRootCommand(app{}, &stdout, &stderr) 25 - cmd.SetArgs([]string{"--help"}) 26 - 27 - if err := cmd.Execute(); err != nil { 28 - t.Fatal(err) 29 - } 30 - if !bytes.Contains(stdout.Bytes(), []byte("install")) { 31 - t.Fatalf("help output did not mention install command:\n%s", stdout.String()) 32 - } 33 - if !bytes.Contains(stdout.Bytes(), []byte("completion")) { 34 - t.Fatalf("help output did not mention completion command:\n%s", stdout.String()) 35 - } 36 - }
+35 -20
src/desktop_test.go
··· 3 3 import ( 4 4 "os" 5 5 "path/filepath" 6 - "strings" 7 6 "testing" 8 7 ) 9 8 10 9 const sampleDesktopFile = `# leading comment 11 10 [Desktop Entry] 12 - Name=Helium 13 - Exec=env FOO=bar helium %U 14 - Icon=helium 11 + Name=Example App 12 + Exec=env FOO=bar upstream-app %U 13 + Icon=example-app 15 14 Actions=new-window;new-private-window; 16 15 17 16 [Desktop Action new-window] 18 17 Name=New Window 19 - Exec=helium --new-window %U 18 + Exec=upstream-app --new-window %U 20 19 21 20 [Desktop Action new-private-window] 22 21 Name=New Private Window 23 - Exec=helium --private-window %U 22 + Exec=upstream-app --private-window %U 24 23 ` 25 24 26 25 func TestDesktopFileRoundTripMatchesInput(t *testing.T) { ··· 62 61 if err != nil { 63 62 t.Fatal(err) 64 63 } 65 - if err := a.patchDesktopFile(desktop, "helium"); err != nil { 64 + if err := a.patchDesktopFile(desktop, "example"); err != nil { 66 65 t.Fatal(err) 67 66 } 68 67 if err := desktop.write(output); err != nil { 69 68 t.Fatal(err) 70 69 } 71 70 72 - written, err := os.ReadFile(output) 71 + patched, err := readDesktopFile(output) 73 72 if err != nil { 74 73 t.Fatal(err) 75 74 } 76 - text := string(written) 77 - for _, expected := range []string{ 78 - "[Desktop Action new-window]", 79 - "[Desktop Action new-private-window]", 80 - "Name=New Private Window", 81 - "Exec=env FOO=bar DESKTOPINTEGRATION=1 /home/test/AppImages/helium.appimage %U", 82 - "Exec=env DESKTOPINTEGRATION=1 /home/test/AppImages/helium.appimage --new-window %U", 83 - "Exec=env DESKTOPINTEGRATION=1 /home/test/AppImages/helium.appimage --private-window %U", 84 - } { 85 - if !strings.Contains(text, expected) { 86 - t.Fatalf("patched desktop file missing %q:\n%s", expected, text) 87 - } 75 + 76 + assertDesktopValue(t, patched, desktopEntrySection, "Icon", "/home/test/AppImages/.icons/example") 77 + assertDesktopValue(t, patched, desktopEntrySection, "TryExec", "/home/test/AppImages/example.appimage") 78 + assertDesktopExec(t, patched, desktopEntrySection, []string{"env", "FOO=bar", "DESKTOPINTEGRATION=1", "/home/test/AppImages/example.appimage", "%U"}) 79 + assertDesktopExec(t, patched, "Desktop Action new-window", []string{"env", "DESKTOPINTEGRATION=1", "/home/test/AppImages/example.appimage", "--new-window", "%U"}) 80 + assertDesktopExec(t, patched, "Desktop Action new-private-window", []string{"env", "DESKTOPINTEGRATION=1", "/home/test/AppImages/example.appimage", "--private-window", "%U"}) 81 + assertDesktopValue(t, patched, "Desktop Action new-private-window", "Name", "New Private Window") 82 + } 83 + 84 + func assertDesktopValue(t *testing.T, desktop *desktopFile, section string, key string, want string) { 85 + t.Helper() 86 + 87 + got, ok := desktop.get(key, section) 88 + if !ok { 89 + t.Fatalf("missing %s in section %s", key, section) 90 + } 91 + if got != want { 92 + t.Fatalf("%s/%s = %q, want %q", section, key, got, want) 93 + } 94 + } 95 + 96 + func assertDesktopExec(t *testing.T, desktop *desktopFile, section string, want []string) { 97 + t.Helper() 98 + 99 + execCmd, ok := desktop.get("Exec", section) 100 + if !ok { 101 + t.Fatalf("missing Exec in section %s", section) 88 102 } 103 + assertTokens(t, mustSplit(t, execCmd), want) 89 104 }
+50 -24
src/exec_test.go
··· 1 1 package main 2 2 3 - import "testing" 3 + import ( 4 + "reflect" 5 + "testing" 6 + 7 + "github.com/kballard/go-shellquote" 8 + ) 4 9 5 10 func TestPatchExecCommandDropsOriginalEnvWrappedExecutable(t *testing.T) { 6 - got := patchExecCommand( 7 - "env FOO=bar helium --new-window %U", 8 - "/home/test/AppImages/helium.appimage", 9 - ) 10 - want := "env FOO=bar DESKTOPINTEGRATION=1 /home/test/AppImages/helium.appimage --new-window %U" 11 - if got != want { 12 - t.Fatalf("patchExecCommand() = %q, want %q", got, want) 13 - } 11 + got := mustSplit(t, patchExecCommand( 12 + "env FOO=bar upstream-app --new-window %U", 13 + "/home/test/AppImages/example.appimage", 14 + )) 15 + want := []string{"env", "FOO=bar", "DESKTOPINTEGRATION=1", "/home/test/AppImages/example.appimage", "--new-window", "%U"} 16 + assertTokens(t, got, want) 14 17 } 15 18 16 19 func TestPatchExecCommandStripsMetadataFieldCodes(t *testing.T) { 17 - got := patchExecCommand( 18 - "helium --open %i %c %k %F", 19 - "/home/test/AppImages/helium.appimage", 20 - ) 21 - want := "env DESKTOPINTEGRATION=1 /home/test/AppImages/helium.appimage --open %F" 22 - if got != want { 23 - t.Fatalf("patchExecCommand() = %q, want %q", got, want) 24 - } 20 + got := mustSplit(t, patchExecCommand( 21 + "upstream-app --open %i %c %k %F", 22 + "/home/test/AppImages/example.appimage", 23 + )) 24 + want := []string{"env", "DESKTOPINTEGRATION=1", "/home/test/AppImages/example.appimage", "--open", "%F"} 25 + assertTokens(t, got, want) 25 26 } 26 27 27 28 func TestPatchExecCommandPreservesQuotedArguments(t *testing.T) { 28 - got := patchExecCommand( 29 - "helium --name 'Helium Browser' --flag=\"two words\" %U", 30 - "/home/test/AppImages/helium.appimage", 31 - ) 32 - want := "env DESKTOPINTEGRATION=1 /home/test/AppImages/helium.appimage --name 'Helium Browser' '--flag=two words' %U" 33 - if got != want { 34 - t.Fatalf("patchExecCommand() = %q, want %q", got, want) 29 + got := mustSplit(t, patchExecCommand( 30 + "upstream-app --name 'Example App' --flag=\"two words\" %U", 31 + "/home/test/AppImages/example.appimage", 32 + )) 33 + want := []string{"env", "DESKTOPINTEGRATION=1", "/home/test/AppImages/example.appimage", "--name", "Example App", "--flag=two words", "%U"} 34 + assertTokens(t, got, want) 35 + } 36 + 37 + func TestPatchExecCommandDoesNotDuplicateDesktopIntegration(t *testing.T) { 38 + got := mustSplit(t, patchExecCommand( 39 + "env DESKTOPINTEGRATION=0 FOO=bar upstream-app %U", 40 + "/home/test/AppImages/example.appimage", 41 + )) 42 + want := []string{"env", "DESKTOPINTEGRATION=0", "FOO=bar", "/home/test/AppImages/example.appimage", "%U"} 43 + assertTokens(t, got, want) 44 + } 45 + 46 + func mustSplit(t *testing.T, cmd string) []string { 47 + t.Helper() 48 + 49 + tokens, err := shellquote.Split(cmd) 50 + if err != nil { 51 + t.Fatalf("split %q: %v", cmd, err) 52 + } 53 + return tokens 54 + } 55 + 56 + func assertTokens(t *testing.T, got []string, want []string) { 57 + t.Helper() 58 + 59 + if !reflect.DeepEqual(got, want) { 60 + t.Fatalf("tokens = %#v, want %#v", got, want) 35 61 } 36 62 }
-11
src/test_helpers_test.go
··· 1 - package main 2 - 3 - import "os" 4 - 5 - func fileMode(path string) os.FileMode { 6 - info, err := os.Stat(path) 7 - if err != nil { 8 - panic(err) 9 - } 10 - return info.Mode() & 0o777 11 - }