package admin

import "testing"

func TestNormalizeR2ConfigSplitsBucketPath(t *testing.T) {
	cfg, err := normalizeR2Config(R2Config{
		Endpoint:        "https://example.r2.cloudflarestorage.com/stroage",
		Bucket:          "stroage/Image/",
		AccessKeyID:     "access-key",
		SecretAccessKey: "secret-key",
		Region:          "auto",
		PublicBaseURL:   "r2.example.com",
		MaxUploadBytes:  20,
	})
	if err != nil {
		t.Fatalf("normalizeR2Config returned error: %v", err)
	}
	if cfg.Endpoint != "https://example.r2.cloudflarestorage.com" {
		t.Fatalf("unexpected endpoint: %s", cfg.Endpoint)
	}
	if cfg.Bucket != "stroage" {
		t.Fatalf("unexpected bucket: %s", cfg.Bucket)
	}
	if cfg.Prefix != "Image" {
		t.Fatalf("unexpected prefix: %s", cfg.Prefix)
	}
	if cfg.PublicBaseURL != "https://r2.example.com" {
		t.Fatalf("unexpected public base URL: %s", cfg.PublicBaseURL)
	}
}
