package fonts import ( "context" "testing" "github.com/MDietermann/ArduinoArchSetup/internal/module" "github.com/MDietermann/ArduinoArchSetup/internal/platform" ) type fakeRunner struct { runCalls [][]string outCalls [][]string installed map[string]bool } func (f *fakeRunner) Run(_ context.Context, name string, args ...string) error { f.runCalls = append(f.runCalls, append([]string{name}, args...)) return nil } func (f *fakeRunner) Output(_ context.Context, name string, args ...string) ([]byte, error) { f.outCalls = append(f.outCalls, append([]string{name}, args...)) if name == "pacman" && len(args) == 2 && args[0] == "-Q" { if f.installed[args[1]] { return []byte("ok"), nil } return nil, errOne } return nil, nil } type eo struct{} func (eo) Error() string { return "exit 1" } var errOne = eo{} type nop struct{} func (nop) Progress(string, int, int, string) {} func (nop) Log(string, string) {} func TestFontsPlanApplyUsesYay(t *testing.T) { r := &fakeRunner{installed: map[string]bool{"yay": true}} m := New([]string{"ttf-jetbrains-mono-nerd"}, platform.NewPacman(r), platform.NewYay(r)) st, _ := m.Detect(context.Background()) p, _ := m.Plan(context.Background(), st) if err := m.Apply(context.Background(), p, nop{}); err != nil { t.Fatal(err) } sawYay := false for _, c := range r.runCalls { if len(c) >= 2 && c[0] == "yay" && c[1] == "-S" { sawYay = true } } if !sawYay { t.Fatalf("no yay install; calls=%v", r.runCalls) } } func TestFontsDetectPresentNoActions(t *testing.T) { r := &fakeRunner{installed: map[string]bool{"yay": true, "ttf-jetbrains-mono-nerd": true}} m := New([]string{"ttf-jetbrains-mono-nerd"}, platform.NewPacman(r), platform.NewYay(r)) st, _ := m.Detect(context.Background()) p, _ := m.Plan(context.Background(), st) if !p.IsEmpty() { t.Fatal("want empty plan when already installed") } } var _ module.Module = Module{}