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.

1.7 KB
Raw Blame
package agentcapabilities

import (
	"reflect"
	"strings"
	"testing"
)

func TestAgentActionableEventKindsReturnsDetachedKnownKinds(t *testing.T) {
	got := AgentActionableEventKinds()
	want := []string{
		string(EventKindFindingCreated),
		string(EventKindApprovalPending),
		string(EventKindActionCompleted),
		string(EventKindAlertFired),
		string(EventKindAlertResolved),
		string(EventKindResourceStatusChanged),
	}
	if !reflect.DeepEqual(got, want) {
		t.Fatalf("AgentActionableEventKinds() = %v, want %v", got, want)
	}

	got[0] = "mutated"
	second := AgentActionableEventKinds()
	if second[0] != string(EventKindFindingCreated) {
		t.Fatalf("AgentActionableEventKinds returned aliased slice: %v", second)
	}
}

func TestIsTransportEventKindPinsStreamPlumbing(t *testing.T) {
	for _, kind := range []EventKind{EventKindStreamConnected, EventKindHeartbeat} {
		if !IsTransportEventKind(string(kind)) {
			t.Fatalf("%s must be transport plumbing", kind)
		}
	}
	for _, kind := range AgentActionableEventKinds() {
		if IsTransportEventKind(kind) {
			t.Fatalf("%s must remain agent-actionable", kind)
		}
	}
}

func TestSubscribeEventsDescriptionUsesSharedEventKinds(t *testing.T) {
	description := SubscribeEventsDescription()
	for _, kind := range append(AgentActionableEventKinds(), string(EventKindHeartbeat)) {
		if !strings.Contains(description, kind) {
			t.Fatalf("subscribe_events description missing %q: %s", kind, description)
		}
	}
	// Change events point agents at the timeline read for surrounding history.
	if !strings.Contains(description, ListRecentChangesCapabilityName) {
		t.Fatalf("subscribe_events description must name %s: %s", ListRecentChangesCapabilityName, description)
	}
}