Skip to content

Commit 8f551f1

Browse files
committed
fix(orgo): decode live workspace envelope
1 parent 0382ab8 commit 8f551f1

2 files changed

Lines changed: 23 additions & 0 deletions

File tree

internal/providers/orgo/client.go

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -174,6 +174,7 @@ func (c *orgoHTTPClient) DeleteWorkspace(ctx context.Context, id string) error {
174174

175175
func (c *orgoHTTPClient) ListWorkspaces(ctx context.Context) ([]orgoWorkspace, error) {
176176
var envelope struct {
177+
Projects []orgoWorkspace `json:"projects"`
177178
Workspaces []orgoWorkspace `json:"workspaces"`
178179
Data []orgoWorkspace `json:"data"`
179180
Items []orgoWorkspace `json:"items"`
@@ -184,6 +185,8 @@ func (c *orgoHTTPClient) ListWorkspaces(ctx context.Context) ([]orgoWorkspace, e
184185
}
185186
if err := json.Unmarshal(raw, &envelope); err == nil {
186187
switch {
188+
case envelope.Projects != nil:
189+
return envelope.Projects, nil
187190
case envelope.Workspaces != nil:
188191
return envelope.Workspaces, nil
189192
case envelope.Data != nil:

internal/providers/orgo/client_test.go

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -106,6 +106,26 @@ func TestGetWorkspaceReadsOfficialDesktopsField(t *testing.T) {
106106
}
107107
}
108108

109+
func TestListWorkspacesReadsLiveProjectsEnvelope(t *testing.T) {
110+
server := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
111+
if r.URL.Path != "/workspaces" {
112+
t.Fatalf("path=%s", r.URL.Path)
113+
}
114+
w.Header().Set("Content-Type", "application/json")
115+
fmt.Fprint(w, `{"projects":[{"id":"workspace_test","name":"Test"}]}`)
116+
}))
117+
t.Cleanup(server.Close)
118+
119+
client := &orgoHTTPClient{baseURL: server.URL, apiKey: "test-key", http: server.Client()}
120+
workspaces, err := client.ListWorkspaces(context.Background())
121+
if err != nil {
122+
t.Fatal(err)
123+
}
124+
if len(workspaces) != 1 || workspaces[0].ID != "workspace_test" {
125+
t.Fatalf("workspaces=%#v", workspaces)
126+
}
127+
}
128+
109129
func TestNewOrgoClientRejectsInsecureNonLoopbackAPIBase(t *testing.T) {
110130
t.Setenv("CRABBOX_ORGO_API_KEY", "test-key")
111131
t.Setenv("CRABBOX_ORGO_API_BASE", "http://api.example.test")

0 commit comments

Comments
 (0)