/ veet / main_test.go
swadhinbiswas feat: live scan matrix, safety vacuuming & theme engine · 8/17/2026
ba4f98c
54 lines · 1.3 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
package main

import (
	"bytes"
	"testing"

	"github.com/swadhinbiswas/veet/internal/model"
)

func TestPrintTable(t *testing.T) {
	apps := []model.AppInfo{
		{Name: "neovim", Version: "0.9.5", Source: "pacman", InstallSizeKB: 10240},
		{Name: "vlc", Version: "3.0.18", Source: "flatpak", InstallSizeKB: 204800},
	}
	printTable(apps)
}

func TestPrintJSON(t *testing.T) {
	apps := []model.AppInfo{
		{Name: "neovim", Version: "0.9.5", Source: "pacman", InstallSizeKB: 10240},
	}
	if err := printJSON(apps); err != nil {
		t.Fatalf("unexpected printJSON error: %v", err)
	}
}

func TestRootCmdExecution(t *testing.T) {
	buf := new(bytes.Buffer)
	rootCmd.SetOut(buf)
	rootCmd.SetErr(buf)

	// Test --help flag
	rootCmd.SetArgs([]string{"--help"})
	if err := rootCmd.Execute(); err != nil {
		t.Fatalf("rootCmd --help failed: %v", err)
	}
	if !bytes.Contains(buf.Bytes(), []byte("VEET finds and completely uninstalls")) {
		t.Fatalf("unexpected help output: %s", buf.String())
	}
}

func TestSubcommandsRegistration(t *testing.T) {
	cmds := rootCmd.Commands()
	found := map[string]bool{}
	for _, c := range cmds {
		found[c.Name()] = true
	}
	for _, expected := range []string{"scan", "clean", "orphans", "cache", "history", "tui"} {
		if !found[expected] {
			t.Errorf("expected subcommand %q to be registered", expected)
		}
	}
}