Files
LokiStack/backend/services/ingress_access_test.go
logan 2d73661dd1 feat: complete Loki query, insights, settings and deployment workflows
Add the Loki query UI, access policies, ingress insights, alert and registry settings, and their backend APIs. Include the related Kubernetes deployment and collector updates required by the integrated application.

Validated with go test ./..., npm run build, and npm run lint.
2026-10-25 21:28:32 +08:00

38 lines
1.4 KiB
Go

package services
import (
"strings"
"testing"
appsv1 "k8s.io/api/apps/v1"
corev1 "k8s.io/api/core/v1"
)
func TestIngressAccessConfiguration(t *testing.T) {
if got := ingressConfigArg([]string{"/nginx-ingress-controller", "--configmap=ingress-nginx/ingress-nginx-controller"}); got != "ingress-nginx/ingress-nginx-controller" {
t.Fatalf("unexpected configmap: %q", got)
}
if got := ingressConfigArg([]string{"--configmap", "custom/controller"}); got != "custom/controller" {
t.Fatalf("unexpected separate configmap flag: %q", got)
}
for _, field := range []string{`"host":"$host"`, `"http_host":"$http_host"`, `"request":"$request"`, `"http_referer":"$http_referer"`, `"method":"$request_method"`, `"status":$status`} {
if !strings.Contains(ingressAccessFormat, field) {
t.Errorf("missing access log field %s", field)
}
}
}
func TestIngressHostNetworkRolloutStrategy(t *testing.T) {
replicas := int32(2)
dep := &appsv1.Deployment{Spec: appsv1.DeploymentSpec{Replicas: &replicas, Template: corev1.PodTemplateSpec{Spec: corev1.PodSpec{HostNetwork: true}}}}
if !setIngressRolloutStrategy(dep) {
t.Fatal("expected host-network rollout adjustment")
}
if dep.Spec.Strategy.RollingUpdate.MaxSurge.IntVal != 0 || dep.Spec.Strategy.RollingUpdate.MaxUnavailable.IntVal != 1 {
t.Fatalf("unexpected rollout strategy: %+v", dep.Spec.Strategy.RollingUpdate)
}
if setIngressRolloutStrategy(dep) {
t.Fatal("strategy update must be idempotent")
}
}