Files
seaweedfs/weed/storage/blockvol/naming_test.go
T
Ping QiuandClaude Opus 4.6 5a9a52f2d0 feat: Phase 6 CP6-2 -- CSI control-plane integration + csi-sanity/k3s validation
CP6-2 wires the CSI driver to SeaweedFS master/volume-server control plane:
- Proto: block volume messages in master.proto/volume_server.proto, codegen
- Master registry: in-memory BlockVolumeRegistry with Pending->Active status,
  full/delta heartbeat, inflight lock, placement (fewest volumes)
- VS gRPC: AllocateBlockVolume/DeleteBlockVolume handlers, shared naming
- Master RPCs: CreateBlockVolume (retry up to 3 servers), Delete, Lookup
- Heartbeat: block volume fields wired into bidirectional stream
- CSI Controller: VolumeBackend interface (Local + Master), returns volume_context
- CSI Node: reads volume_context for remote targets, staged map + IQN derivation
- Mode flag: --mode=controller/node/all, --master for control-plane
- K8s manifests: csi-driver.yaml, csi-controller.yaml, csi-node.yaml

csi-sanity conformance (33 pass, 58 skip) found 6 bugs:
- BUG-SANITY-1/2/3: missing VolumeCapabilities/VolumeCapability validation
- BUG-SANITY-4: NodePublish used mount instead of bind mount
- BUG-SANITY-5: NodeUnpublish didn't remove target path
- BUG-SANITY-6: NodeUnpublish failed on unmounted path

k3s Level 4 (PVC->Pod data persistence) found 1 bug:
- BUG-K3S-1: IsLoggedIn didn't handle iscsiadm exit code 21

226 CSI tests + 54 server tests = 280 new tests, all passing.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
2026-03-04 11:01:08 -08:00

80 lines
1.8 KiB
Go

package blockvol
import (
"strings"
"testing"
)
func TestSanitizeFilename(t *testing.T) {
tests := []struct {
input string
want string
}{
{"simple", "simple"},
{"VolA", "vola"},
{"pvc-abc-123", "pvc-abc-123"},
{"has spaces", "has-spaces"},
{"UPPER_CASE", "upper_case"},
{"special!@#$%chars", "special-----chars"},
{"dots.and-dashes", "dots.and-dashes"},
}
for _, tt := range tests {
got := SanitizeFilename(tt.input)
if got != tt.want {
t.Errorf("SanitizeFilename(%q) = %q, want %q", tt.input, got, tt.want)
}
}
}
func TestSanitizeIQN(t *testing.T) {
tests := []struct {
input string
want string
}{
{"simple", "simple"},
{"VolA", "vola"},
{"pvc-abc-123", "pvc-abc-123"},
{"has spaces", "has-spaces"},
{"under_score", "under-score"},
}
for _, tt := range tests {
got := SanitizeIQN(tt.input)
if got != tt.want {
t.Errorf("SanitizeIQN(%q) = %q, want %q", tt.input, got, tt.want)
}
}
}
func TestSanitizeIQN_Truncation(t *testing.T) {
long := strings.Repeat("a", 100)
got := SanitizeIQN(long)
if len(got) > 64 {
t.Errorf("SanitizeIQN should truncate to 64 chars, got %d", len(got))
}
// Should end with hash suffix.
if !strings.Contains(got, "-") {
t.Error("truncated IQN should have hash suffix separated by dash")
}
}
func TestSanitizeConsistency(t *testing.T) {
// SanitizeFilename and SanitizeIQN should agree on lowercasing.
// "VolA" and "vola" should produce the same sanitized output from both.
names := []string{"VolA", "vola"}
for _, fn := range []struct {
name string
f func(string) string
}{
{"SanitizeFilename", SanitizeFilename},
{"SanitizeIQN", SanitizeIQN},
} {
results := make(map[string]bool)
for _, n := range names {
results[fn.f(n)] = true
}
if len(results) != 1 {
t.Errorf("%s: 'VolA' and 'vola' should produce same result, got %v", fn.name, results)
}
}
}