Files
glpi-ai-agent/internal/config/config_test.go
T
jbergner 40a98e0f57
release-tag / release-image (push) Successful in 1m37s
Update am Dashboard
2026-07-28 05:33:10 +02:00

127 lines
3.7 KiB
Go

package config
import (
"testing"
"time"
)
func validConfig() Config {
return Config{
GLPIURL: "https://glpi.internal.example",
GLPIClientID: "client-id",
GLPIClientSecret: "real-secret-value",
GLPIUsername: "svc-agent",
GLPIPassword: "real-password-value",
GLPIAllowedStatusIDs: []int64{1},
WebAllowAnonymous: true,
Workers: 1,
QueueSize: 1,
CategoryConfidence: .9,
ReplyConfidence: .9,
KnowledgeMinScore: .8,
KnowledgeAllowedSources: []string{"internal-kb"},
KnowledgeAutoReplySources: []string{"internal-kb"},
CommunicationLanguage: "de-DE",
CommunicationStyle: "formal",
OllamaTimeout: time.Minute,
OllamaNumPredict: 256,
OllamaKeepAlive: 10 * time.Minute,
OllamaThink: false,
OllamaMaxConcurrent: 1,
}
}
func TestValidateRejectsPlainHTTPByDefault(t *testing.T) {
c := validConfig()
c.GLPIURL = "http://glpi.internal.example"
if err := c.Validate(); err == nil {
t.Fatal("expected plain HTTP to be rejected")
}
c.GLPIAllowInsecureHTTP = true
if err := c.Validate(); err != nil {
t.Fatalf("explicit insecure override should validate: %v", err)
}
}
func TestValidateRejectsPlaceholderSecrets(t *testing.T) {
c := validConfig()
c.GLPIClientSecret = "CHANGE_ME"
if err := c.Validate(); err == nil {
t.Fatal("expected placeholder secret to be rejected")
}
}
func TestValidateRequiresAllowedStatus(t *testing.T) {
c := validConfig()
c.GLPIAllowedStatusIDs = nil
if err := c.Validate(); err == nil {
t.Fatal("expected empty status whitelist to be rejected")
}
}
func TestValidateRejectsAutoReplySourceOutsideAllowlist(t *testing.T) {
c := validConfig()
c.KnowledgeAutoReplySources = []string{"vendor-docs"}
if err := c.Validate(); err == nil {
t.Fatal("expected auto-reply source outside allowlist to be rejected")
}
}
func TestValidateRejectsUnknownCommunicationStyle(t *testing.T) {
c := validConfig()
c.CommunicationStyle = "super-friendly"
if err := c.Validate(); err == nil {
t.Fatal("expected unsupported communication style to be rejected")
}
}
func TestValidateRequiresMajorIncidentFilter(t *testing.T) {
c := validConfig()
c.ContextEnabled = true
c.ContextTimeout = 1
c.MajorIncidentsEnabled = true
c.GLPIMajorIncidentLimit = 20
if err := c.Validate(); err == nil {
t.Fatal("expected major incident filter to be required")
}
}
func TestValidateUptimeKumaMetricsRequiresAPIKey(t *testing.T) {
c := validConfig()
c.ContextEnabled = true
c.ContextTimeout = 1
c.UptimeKumaEnabled = true
c.UptimeKumaURL = "https://uptime.internal.example"
c.UptimeKumaMode = "metrics"
c.UptimeKumaMaxIssues = 20
if err := c.Validate(); err == nil {
t.Fatal("expected Uptime Kuma API key to be required in metrics mode")
}
c.UptimeKumaAPIKey = "test-api-key"
if err := c.Validate(); err != nil {
t.Fatalf("expected metrics mode with API key to validate: %v", err)
}
}
func TestValidateUserDeviceFilterRequiresUserPlaceholder(t *testing.T) {
c := validConfig()
c.ContextEnabled = true
c.ContextTimeout = 1
c.UserDeviceContextEnabled = true
c.GLPIUserDevicePaths = []string{"/Assets/Computer"}
c.GLPIUserDeviceFilterTemplate = "user.id==42"
c.GLPIUserDeviceLimit = 20
if err := c.Validate(); err == nil {
t.Fatal("expected user device filter template to require {{user_id}}")
}
}
func TestKnowledgeWebEditRequiresAuthentication(t *testing.T) {
c := validConfig()
c.KnowledgeWebEditEnabled = true
c.WebAllowAnonymous = true
if err := c.Validate(); err == nil {
t.Fatal("expected anonymous KB editing to be rejected")
}
}