From 6eb89f48c73337426feb1d704a60f4471cf85942 Mon Sep 17 00:00:00 2001 From: Mike the document version manager Date: Mon, 30 Oct 2023 08:49:50 +0000 Subject: [PATCH] fix(ui): workspace listing returning 500 error --- internal/workspace/db.go | 2 +- internal/workspace/run.go | 15 +++++++++++++++ internal/workspace/web_test.go | 12 ++++++++++++ internal/workspace/workspace.go | 6 ------ 4 files changed, 28 insertions(+), 7 deletions(-) create mode 100644 internal/workspace/run.go diff --git a/internal/workspace/db.go b/internal/workspace/db.go index a4ee0be1a..dbe6bf4e7 100644 --- a/internal/workspace/db.go +++ b/internal/workspace/db.go @@ -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), } } diff --git a/internal/workspace/run.go b/internal/workspace/run.go new file mode 100644 index 000000000..7bb42eb93 --- /dev/null +++ b/internal/workspace/run.go @@ -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) } diff --git a/internal/workspace/web_test.go b/internal/workspace/web_test.go index 23ef210aa..48b181769 100644 --- a/internal/workspace/web_test.go +++ b/internal/workspace/web_test.go @@ -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)) diff --git a/internal/workspace/workspace.go b/internal/workspace/workspace.go index 7f55bcb29..2c0e3365f 100644 --- a/internal/workspace/workspace.go +++ b/internal/workspace/workspace.go @@ -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.