32 lines
716 B
Go
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)
|
|
}
|
|
}
|