package services import ( "fmt" "strings" "testing" "lokistack/models" ) // TestObjectStoreConfigs 验证 OSS / COS / OBS 生成的 Loki 配置: // 走 S3 兼容(object_store: s3 + bucketnames),虚拟主机风格,compactor 用本地盘。 func TestObjectStoreConfigs(t *testing.T) { for _, typ := range []string{"oss", "cos", "obs"} { t.Run(typ, func(t *testing.T) { d := &models.LokiDeployment{ Name: "test-loki", Namespace: "log", Mode: "k8s-yaml", Replicas: 1, RetentionDays: 15, StorageConfig: &models.StorageConfig{ StorageType: typ, Bucket: "test-bucket", Endpoint: "oss-cn-hongkong.aliyuncs.com", Region: "oss-cn-hongkong", AccessKey: "AKTEST", SecretKey: "SKTEST", PathPrefix: "loki", }, } cfg := NewLokiDeployer(d, func(level, message, detail string) {}).generateLokiConfig() fmt.Printf("---- %s ----\n%s\n", typ, cfg) if strings.Contains(cfg, "alibabacloud") { t.Fatal("storage_config still contains alibabacloud") } for _, want := range []string{ "object_store: s3", "bucketnames: test-bucket", "endpoint: oss-cn-hongkong.aliyuncs.com", "region: oss-cn-hongkong", "s3forcepathstyle: false", "delete_request_store: filesystem", } { if !strings.Contains(cfg, want) { t.Fatalf("missing %q", want) } } }) } }