Files
CLICD/backend/internal/api/disks_unicode_test.go
MengMengCode f2c14c01d3 feat: add instance storage workflows and shadcn monitoring charts
Add offline disk growth and managed data disks, portable full backups and
restore, independent clones and batch instance templates, and local ISO
and QCOW2 uploads. Persist task details and metric history in SQLite.

Replace hand-drawn host and instance charts with shadcn/ui Chart and
Recharts, keep numeric values and units together, and preserve responsive
layouts, icons, time ranges and full-sample statistics.

Validation: backend tests and vet; Linux KVM/LXC/API/config/server tests;
frontend and documentation production builds; real disk, reinstall,
backup, clone, upload, task-history and NAT tests; 37 cross-host restore
checks; responsive chart checks and read-only deployed verification.
Guest Windows restore behavior has not been tested on a running Windows VM.
2026-11-03 23:17:46 +08:00

37 lines
1.2 KiB
Go

package api
import (
"encoding/json"
"net/http"
"strings"
"testing"
)
func TestDiskAPINameLimitCountsUnicodeCharacters(t *testing.T) {
diskAPIFixture(t)
for _, tc := range []struct {
name string
valid bool
}{
{strings.Repeat("盘", 64), true},
{strings.Repeat("盘", 80), true},
{strings.Repeat("盘", 81), false},
{strings.Repeat("x", 80), true},
{strings.Repeat("x", 81), false},
} {
// Deliberately omit size_gb: a valid display name must reach that
// independent required-field check without touching any runtime disk.
body, _ := json.Marshal(map[string]string{"name": tc.name})
response := requestDisk(t, http.MethodPost, "disks", string(body), AuthContext{Type: authTypeAdmin})
if response.Code != http.StatusBadRequest {
t.Fatalf("status=%d: %s", response.Code, response.Body.String())
}
if tc.valid && !strings.Contains(response.Body.String(), "size_gb is required") {
t.Fatalf("valid Unicode name failed byte-length validation: %s", response.Body.String())
}
if !tc.valid && !strings.Contains(response.Body.String(), "Disk name must contain") {
t.Fatalf("overlong display name was not rejected: %s", response.Body.String())
}
}
}