feat: init

This commit is contained in:
2026-06-06 06:15:45 +03:30
commit a986de98b0
33 changed files with 2141 additions and 0 deletions
+29
View File
@@ -0,0 +1,29 @@
package volume
import (
"fmt"
"path"
"strings"
)
func ID(storageID, name string) string {
return path.Join(storageID, name)
}
func Parse(volumeID string) (storageID, name string, err error) {
parts := strings.Split(volumeID, "/")
if len(parts) != 2 {
return "", "", fmt.Errorf("invalid volume id %q", volumeID)
}
return parts[0], parts[1], nil
}
func SanitizeName(name string) string {
name = strings.TrimSpace(name)
name = strings.ReplaceAll(name, " ", "-")
return name
}
func ExportKey(volumeID string) string {
return strings.NewReplacer("/", "_", " ", "_").Replace(volumeID)
}
+25
View File
@@ -0,0 +1,25 @@
package volume
import "testing"
func TestParseVolumeID(t *testing.T) {
storageID, name, err := Parse("nfs-prod/pvc-1")
if err != nil {
t.Fatalf("Parse failed: %v", err)
}
if storageID != "nfs-prod" || name != "pvc-1" {
t.Fatalf("unexpected parse result: %q %q", storageID, name)
}
}
func TestParseVolumeIDRejectsInvalid(t *testing.T) {
if _, _, err := Parse("only-one-part"); err == nil {
t.Fatal("expected error for invalid volume id")
}
}
func TestID(t *testing.T) {
if got := ID("nfs-prod", "pvc-1"); got != "nfs-prod/pvc-1" {
t.Fatalf("unexpected id: %q", got)
}
}