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/manager_test.go
T
2026-07-02 17:22:26 +08:00

52 lines
1.1 KiB
Go

package workspace
import (
"os"
"path/filepath"
"testing"
)
func TestLocalManagerListReturnsSortedWorkspaces(t *testing.T) {
mgr := NewLocalManager(t.TempDir())
if _, err := mgr.Create("beta"); err != nil {
t.Fatal(err)
}
if _, err := mgr.Create("alpha"); err != nil {
t.Fatal(err)
}
got, err := mgr.List()
if err != nil {
t.Fatal(err)
}
if len(got) != 2 {
t.Fatalf("len = %d, want 2", len(got))
}
if got[0].ID != "alpha" || got[1].ID != "beta" {
t.Fatalf("ids = %q, %q; want alpha, beta", got[0].ID, got[1].ID)
}
if got[0].Root == "" || got[1].Root == "" {
t.Fatal("manager list should keep internal roots for service use")
}
}
func TestLocalManagerListSkipsUnsafeDirectoryNames(t *testing.T) {
root := t.TempDir()
if err := os.Mkdir(filepath.Join(root, "valid"), 0755); err != nil {
t.Fatal(err)
}
// Contains space, which is invalid per ValidID regex
if err := os.Mkdir(filepath.Join(root, "bad name"), 0755); err != nil {
t.Fatal(err)
}
mgr := NewLocalManager(root)
got, err := mgr.List()
if err != nil {
t.Fatal(err)
}
if len(got) != 1 || got[0].ID != "valid" {
t.Fatalf("got %#v, want only valid", got)
}
}