summaryrefslogtreecommitdiff
path: root/internal/api/server_test.go
diff options
context:
space:
mode:
Diffstat (limited to 'internal/api/server_test.go')
-rw-r--r--internal/api/server_test.go44
1 files changed, 44 insertions, 0 deletions
diff --git a/internal/api/server_test.go b/internal/api/server_test.go
index 8484e02..765b813 100644
--- a/internal/api/server_test.go
+++ b/internal/api/server_test.go
@@ -99,6 +99,50 @@ func (m *mockRunner) Run(_ context.Context, _ *task.Task, _ *storage.Execution)
return nil
}
+func TestListWorkspaces_UsesConfiguredRoot(t *testing.T) {
+ srv, _ := testServer(t)
+
+ root := t.TempDir()
+ for _, name := range []string{"alpha", "beta", "gamma"} {
+ if err := os.Mkdir(filepath.Join(root, name), 0755); err != nil {
+ t.Fatal(err)
+ }
+ }
+ // Also create a file (should be excluded from results).
+ f, err := os.Create(filepath.Join(root, "notadir.txt"))
+ if err != nil {
+ t.Fatal(err)
+ }
+ f.Close()
+
+ srv.SetWorkspaceRoot(root)
+
+ req := httptest.NewRequest("GET", "/api/workspaces", nil)
+ w := httptest.NewRecorder()
+ srv.Handler().ServeHTTP(w, req)
+
+ if w.Code != http.StatusOK {
+ t.Fatalf("status: want 200, got %d", w.Code)
+ }
+ var dirs []string
+ if err := json.NewDecoder(w.Body).Decode(&dirs); err != nil {
+ t.Fatalf("decode: %v", err)
+ }
+ want := map[string]bool{
+ root + "/alpha": true,
+ root + "/beta": true,
+ root + "/gamma": true,
+ }
+ if len(dirs) != len(want) {
+ t.Fatalf("want %d dirs, got %d: %v", len(want), len(dirs), dirs)
+ }
+ for _, d := range dirs {
+ if !want[d] {
+ t.Errorf("unexpected dir in response: %s", d)
+ }
+ }
+}
+
func TestHealthEndpoint(t *testing.T) {
srv, _ := testServer(t)
req := httptest.NewRequest("GET", "/api/health", nil)