Skip to content

armgit / Pulse

Public Imported from GitHub
0

Real-time monitoring dashboard for Proxmox VE, PBS, Docker, Kubernetes, TrueNAS and vSphere. Self-hosted, with alerts for failed backups, full disks, unhealthy containers and offline nodes.

2.1 KB
Raw Blame
package pulsecli

import (
	"bytes"
	"context"
	"io"
	"strings"
	"testing"
)

func TestNewRootCommandVersionSkipsRunE(t *testing.T) {
	runCalled := false
	cmd := NewRootCommand(CommandSpec{
		Use:            "pulse",
		Short:          "Pulse",
		Long:           "Pulse",
		Version:        "1.2.3",
		VersionPrinter: func(w io.Writer) { _, _ = w.Write([]byte("Pulse 1.2.3\n")) },
	}, RuntimeSpec{
		Run: func(context.Context) error { runCalled = true; return nil },
	}, CommandDeps{})
	out := bytes.NewBuffer(nil)
	cmd.SetOut(out)
	cmd.SetErr(out)
	cmd.SetArgs([]string{"version"})
	if err := cmd.ExecuteContext(context.Background()); err != nil {
		t.Fatalf("ExecuteContext(version): %v", err)
	}
	if runCalled {
		t.Fatal("RunE should not be called for version")
	}
	if got := out.String(); !strings.Contains(got, "Pulse 1.2.3") {
		t.Fatalf("version output = %q", got)
	}
}

func TestNewRootCommandConfigInfoSkipsRunE(t *testing.T) {
	runCalled := false
	cmd := NewRootCommand(CommandSpec{
		Use:   "pulse",
		Short: "Pulse",
		Long:  "Pulse",
	}, RuntimeSpec{
		Run: func(context.Context) error { runCalled = true; return nil },
	}, CommandDeps{
		Config: &ConfigDeps{},
	})
	out := bytes.NewBuffer(nil)
	tempDir := t.TempDir()
	t.Setenv("PULSE_DATA_DIR", tempDir)
	cmd.SetOut(out)
	cmd.SetErr(out)
	cmd.SetArgs([]string{"config", "info"})
	if err := cmd.ExecuteContext(context.Background()); err != nil {
		t.Fatalf("ExecuteContext(config info): %v", err)
	}
	if runCalled {
		t.Fatal("RunE should not be called for config info")
	}
	if got := out.String(); !strings.Contains(got, "Pulse Configuration Information") || !strings.Contains(got, tempDir+"/") {
		t.Fatalf("config info output = %q", got)
	}
}

func TestNewRootCommandIncludesFleetConnections(t *testing.T) {
	cmd := NewRootCommand(CommandSpec{
		Use:   "pulse",
		Short: "Pulse",
		Long:  "Pulse",
	}, RuntimeSpec{}, CommandDeps{})

	found, _, err := cmd.Find([]string{"fleet", "connections"})
	if err != nil {
		t.Fatalf("find fleet connections: %v", err)
	}
	if found == nil || found.Use != "connections" {
		t.Fatalf("fleet connections command not registered: %#v", found)
	}
}