Skip to content
This repository has been archived by the owner on Dec 26, 2023. It is now read-only.

Commit

Permalink
fix(ui): workspace listing returning 500 error
Browse files Browse the repository at this point in the history
  • Loading branch information
leg100 committed Oct 30, 2023
1 parent 5b3e3f4 commit 6eb89f4
Show file tree
Hide file tree
Showing 4 changed files with 28 additions and 7 deletions.
2 changes: 1 addition & 1 deletion internal/workspace/db.go
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,7 @@ func (r pgresult) toWorkspace() (*Workspace, error) {
if r.LatestRunID.Status == pgtype.Present && r.LatestRunStatus.Status == pgtype.Present {
ws.LatestRun = &LatestRun{
ID: r.LatestRunID.String,
Status: r.LatestRunStatus.String,
Status: runStatus(r.LatestRunStatus.String),
}
}

Expand Down
15 changes: 15 additions & 0 deletions internal/workspace/run.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
package workspace

type (
// LatestRun is a summary of the latest run for a workspace
LatestRun struct {
ID string
Status runStatus
}

// runStatus is the status of a run. Duplicated here rather than use
// run.runStatus in order to avoid an import cycle.
runStatus string
)

func (s runStatus) String() string { return string(s) }
12 changes: 12 additions & 0 deletions internal/workspace/web_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -248,6 +248,18 @@ func TestListWorkspacesHandler(t *testing.T) {
})
}

func TestListWorkspacesHandler_WithLatestRun(t *testing.T) {
app := fakeWebHandlers(t,
withWorkspaces(&Workspace{ID: "ws-foo", LatestRun: &LatestRun{Status: "applied", ID: "run-123"}}),
)

r := httptest.NewRequest("GET", "/?organization_name=acme", nil)
r = r.WithContext(internal.AddSubjectToContext(context.Background(), &auth.SiteAdmin))
w := httptest.NewRecorder()
app.listWorkspaces(w, r)
assert.Equal(t, 200, w.Code, w.Body.String())
}

func TestDeleteWorkspace(t *testing.T) {
ws := &Workspace{ID: "ws-123", Organization: "acme-corp"}
app := fakeWebHandlers(t, withWorkspaces(ws))
Expand Down
6 changes: 0 additions & 6 deletions internal/workspace/workspace.go
Original file line number Diff line number Diff line change
Expand Up @@ -106,12 +106,6 @@ type (
AllowCLIApply *bool
}

// LatestRun is a summary of the latest run for a workspace
LatestRun struct {
ID string
Status string
}

ExecutionMode string

// CreateOptions represents the options for creating a new workspace.
Expand Down

0 comments on commit 6eb89f4

Please sign in to comment.