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.
42 lines
1.4 KiB
Go
42 lines
1.4 KiB
Go
package services
|
|
|
|
import (
|
|
"strings"
|
|
"testing"
|
|
|
|
"opsxloki/models"
|
|
)
|
|
|
|
func TestDockerLokiConfigUsesEnvironmentForStorageCredentials(t *testing.T) {
|
|
deployment := &models.LokiDeployment{
|
|
ID: 7, Mode: "host-docker", RetentionDays: 60, Replicas: 1,
|
|
StorageConfig: &models.StorageConfig{
|
|
StorageType: "minio", Endpoint: "http://10.10.10.88:9000", Bucket: "loki",
|
|
AccessKey: "test-access-secret", SecretKey: "test-secret-secret",
|
|
},
|
|
}
|
|
config := NewLokiDeployer(deployment, nil).generateLokiConfig()
|
|
if strings.Contains(config, "test-access-secret") || strings.Contains(config, "test-secret-secret") {
|
|
t.Fatal("Docker Loki config embedded storage credentials")
|
|
}
|
|
for _, expected := range []string{"${LOKI_STORAGE_ACCESS_KEY}", "${LOKI_STORAGE_SECRET_KEY}", "retention_period: 1440h"} {
|
|
if !strings.Contains(config, expected) {
|
|
t.Errorf("config missing %q", expected)
|
|
}
|
|
}
|
|
if got := dockerContainerName(deployment.ID); got != "lokideploy-loki-7" {
|
|
t.Fatalf("unexpected container name: %s", got)
|
|
}
|
|
}
|
|
|
|
func TestDockerLokiImageRejectsShellInputAndOldVersions(t *testing.T) {
|
|
for _, version := range []string{"2.9.8", "3.0.0;touch /tmp/example", "3.9.9"} {
|
|
if _, err := dockerLokiImage(version); err == nil {
|
|
t.Errorf("accepted unsupported version %q", version)
|
|
}
|
|
}
|
|
if image, err := dockerLokiImage("3.4.0"); err != nil || image != "grafana/loki:3.4.0" {
|
|
t.Fatalf("unexpected image %q, error %v", image, err)
|
|
}
|
|
}
|