This repository has been archived on 2026-07-17. You can view files and clone it. You cannot open issues or pull requests or push a commit.
Files
codespace/internal/workspace/path_test.go
T
2026-07-02 15:07:54 +08:00

32 lines
716 B
Go

package workspace
import (
"testing"
)
func TestValidIDAcceptsSafeSegments(t *testing.T) {
valid := []string{"user1", "project-A", "project_A", "project.1"}
for _, id := range valid {
if !ValidID(id) {
t.Errorf("expected ValidID(%q) to be true", id)
}
}
}
func TestValidIDRejectsUnsafeSegments(t *testing.T) {
invalid := []string{"", ".", "..", "/tmp/x", "../x", "a/b", "a b", "中文", "*"}
for _, id := range invalid {
if ValidID(id) {
t.Errorf("expected ValidID(%q) to be false", id)
}
}
}
func TestRootForUsesConfiguredRoot(t *testing.T) {
got := RootFor("/tmp/workspaces", "user1")
want := "/tmp/workspaces/user1"
if got != want {
t.Errorf("RootFor = %q, want %q", got, want)
}
}