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.9 KB
Raw Blame
package ai

import (
	"testing"
	"time"
)

func TestNewDefaultConfig(t *testing.T) {
	cfg := NewDefaultConfig()

	if cfg == nil {
		t.Fatal("Expected non-nil config")
	}

	// Verify some default values
	if cfg.Model != "" {
		t.Errorf("Expected default model to remain empty until provider resolution, got %q", cfg.Model)
	}
}

func TestDefaultBaselineConfig(t *testing.T) {
	cfg := DefaultBaselineConfig()

	// Verify config has reasonable defaults
	if cfg.LearningWindow <= 0 {
		t.Error("Expected positive LearningWindow")
	}
	if cfg.MinSamples <= 0 {
		t.Error("Expected positive MinSamples")
	}
}

func TestNewBaselineStore(t *testing.T) {
	cfg := DefaultBaselineConfig()
	store := NewBaselineStore(cfg)

	if store == nil {
		t.Fatal("Expected non-nil baseline store")
	}
}

func TestDefaultPatternConfig(t *testing.T) {
	cfg := DefaultPatternConfig()

	if cfg.MaxEvents != 5000 {
		t.Fatalf("MaxEvents = %d, want 5000", cfg.MaxEvents)
	}
	if cfg.MinOccurrences != 3 {
		t.Fatalf("MinOccurrences = %d, want 3", cfg.MinOccurrences)
	}
	if cfg.PatternWindow != 90*24*time.Hour {
		t.Fatalf("PatternWindow = %v, want %v", cfg.PatternWindow, 90*24*time.Hour)
	}
	if cfg.PredictionLimit != 30*24*time.Hour {
		t.Fatalf("PredictionLimit = %v, want %v", cfg.PredictionLimit, 30*24*time.Hour)
	}
}

func TestNewPatternDetector(t *testing.T) {
	cfg := DefaultPatternConfig()
	detector := NewPatternDetector(cfg)

	if detector == nil {
		t.Fatal("Expected non-nil pattern detector")
	}
}

func TestDefaultCorrelationConfig(t *testing.T) {
	cfg := DefaultCorrelationConfig()

	if cfg.MaxEvents != 10000 {
		t.Fatalf("MaxEvents = %d, want 10000", cfg.MaxEvents)
	}
	if cfg.CorrelationWindow != 10*time.Minute {
		t.Fatalf("CorrelationWindow = %v, want %v", cfg.CorrelationWindow, 10*time.Minute)
	}
	if cfg.MinOccurrences != 3 {
		t.Fatalf("MinOccurrences = %d, want 3", cfg.MinOccurrences)
	}
	if cfg.RetentionWindow != 30*24*time.Hour {
		t.Fatalf("RetentionWindow = %v, want %v", cfg.RetentionWindow, 30*24*time.Hour)
	}
}

func TestNewCorrelationDetector(t *testing.T) {
	cfg := DefaultCorrelationConfig()
	detector := NewCorrelationDetector(cfg)

	if detector == nil {
		t.Fatal("Expected non-nil correlation detector")
	}
}

func TestMin(t *testing.T) {
	tests := []struct {
		a, b     int
		expected int
	}{
		{1, 2, 1},
		{5, 3, 3},
		{0, 0, 0},
		{-1, 1, -1},
		{10, 10, 10},
	}

	for _, tt := range tests {
		result := min(tt.a, tt.b)
		if result != tt.expected {
			t.Errorf("min(%d, %d) = %d, want %d", tt.a, tt.b, result, tt.expected)
		}
	}
}

func TestNewChangeDetector(t *testing.T) {
	cfg := ChangeDetectorConfig{
		MaxChanges: 100,
	}
	detector := NewChangeDetector(cfg)

	if detector == nil {
		t.Fatal("Expected non-nil change detector")
	}
}

func TestNewRemediationLog(t *testing.T) {
	cfg := RemediationLogConfig{
		MaxRecords: 50,
	}
	log := NewRemediationLog(cfg)

	if log == nil {
		t.Fatal("Expected non-nil remediation log")
	}
}