mirror of
https://github.com/coder/coder.git
synced 2026-09-22 05:05:20 +08:00
fix: add workspace option 'deleted' to options type (#2095)
* fix: add workspace option 'deleted' to options type * dead code
This commit is contained in:
@@ -60,12 +60,6 @@ func (api *API) workspace(rw http.ResponseWriter, r *http.Request) {
|
||||
})
|
||||
return
|
||||
}
|
||||
if !workspace.Deleted && showDeleted {
|
||||
httpapi.Write(rw, http.StatusBadRequest, httpapi.Response{
|
||||
Message: fmt.Sprintf("Workspace %q is not deleted, please remove '?deleted=true' and try again", workspace.ID.String()),
|
||||
})
|
||||
return
|
||||
}
|
||||
|
||||
build, err := api.Database.GetLatestWorkspaceBuildByWorkspaceID(r.Context(), workspace.ID)
|
||||
if err != nil {
|
||||
|
||||
@@ -46,10 +46,9 @@ func TestWorkspace(t *testing.T) {
|
||||
workspace := coderdtest.CreateWorkspace(t, client, user.OrganizationID, template.ID)
|
||||
coderdtest.AwaitWorkspaceBuildJob(t, client, workspace.LatestBuild.ID)
|
||||
|
||||
// Getting with deleted=true should fail.
|
||||
// Getting with deleted=true should still work.
|
||||
_, err := client.DeletedWorkspace(context.Background(), workspace.ID)
|
||||
require.Error(t, err)
|
||||
require.ErrorContains(t, err, "400") // bad request
|
||||
require.NoError(t, err)
|
||||
|
||||
// Delete the workspace
|
||||
build, err := client.CreateWorkspaceBuild(context.Background(), workspace.ID, codersdk.CreateWorkspaceBuildRequest{
|
||||
|
||||
@@ -36,14 +36,6 @@ type Client struct {
|
||||
|
||||
type requestOption func(*http.Request)
|
||||
|
||||
func queryParam(k, v string) requestOption {
|
||||
return func(r *http.Request) {
|
||||
q := r.URL.Query()
|
||||
q.Set(k, v)
|
||||
r.URL.RawQuery = q.Encode()
|
||||
}
|
||||
}
|
||||
|
||||
// Request performs an HTTP request with the body provided.
|
||||
// The caller is responsible for closing the response body.
|
||||
func (c *Client) Request(ctx context.Context, method, path string, body interface{}, opts ...requestOption) (*http.Response, error) {
|
||||
|
||||
+20
-1
@@ -38,6 +38,22 @@ type CreateWorkspaceBuildRequest struct {
|
||||
ProvisionerState []byte `json:"state,omitempty"`
|
||||
}
|
||||
|
||||
type WorkspaceOptions struct {
|
||||
Deleted bool `json:"deleted,omitempty"`
|
||||
}
|
||||
|
||||
// asRequestOption returns a function that can be used in (*Client).Request.
|
||||
// It modifies the request query parameters.
|
||||
func (o WorkspaceOptions) asRequestOption() requestOption {
|
||||
return func(r *http.Request) {
|
||||
q := r.URL.Query()
|
||||
if o.Deleted {
|
||||
q.Set("deleted", "true")
|
||||
}
|
||||
r.URL.RawQuery = q.Encode()
|
||||
}
|
||||
}
|
||||
|
||||
// Workspace returns a single workspace.
|
||||
func (c *Client) Workspace(ctx context.Context, id uuid.UUID) (Workspace, error) {
|
||||
return c.getWorkspace(ctx, id)
|
||||
@@ -45,7 +61,10 @@ func (c *Client) Workspace(ctx context.Context, id uuid.UUID) (Workspace, error)
|
||||
|
||||
// DeletedWorkspace returns a single workspace that was deleted.
|
||||
func (c *Client) DeletedWorkspace(ctx context.Context, id uuid.UUID) (Workspace, error) {
|
||||
return c.getWorkspace(ctx, id, queryParam("deleted", "true"))
|
||||
o := WorkspaceOptions{
|
||||
Deleted: true,
|
||||
}
|
||||
return c.getWorkspace(ctx, id, o.asRequestOption())
|
||||
}
|
||||
|
||||
func (c *Client) getWorkspace(ctx context.Context, id uuid.UUID, opts ...requestOption) (Workspace, error) {
|
||||
|
||||
@@ -221,7 +221,7 @@ export interface ProvisionerJobLog {
|
||||
readonly output: string
|
||||
}
|
||||
|
||||
// From codersdk/workspaces.go:182:6
|
||||
// From codersdk/workspaces.go:201:6
|
||||
export interface PutExtendWorkspaceRequest {
|
||||
readonly deadline: string
|
||||
}
|
||||
@@ -298,12 +298,12 @@ export interface UpdateUserProfileRequest {
|
||||
readonly username: string
|
||||
}
|
||||
|
||||
// From codersdk/workspaces.go:141:6
|
||||
// From codersdk/workspaces.go:160:6
|
||||
export interface UpdateWorkspaceAutostartRequest {
|
||||
readonly schedule?: string
|
||||
}
|
||||
|
||||
// From codersdk/workspaces.go:161:6
|
||||
// From codersdk/workspaces.go:180:6
|
||||
export interface UpdateWorkspaceTTLRequest {
|
||||
readonly ttl_ms?: number
|
||||
}
|
||||
@@ -445,18 +445,23 @@ export interface WorkspaceBuild {
|
||||
readonly deadline: string
|
||||
}
|
||||
|
||||
// From codersdk/workspaces.go:64:6
|
||||
// From codersdk/workspaces.go:83:6
|
||||
export interface WorkspaceBuildsRequest extends Pagination {
|
||||
readonly WorkspaceID: string
|
||||
}
|
||||
|
||||
// From codersdk/workspaces.go:200:6
|
||||
// From codersdk/workspaces.go:219:6
|
||||
export interface WorkspaceFilter {
|
||||
readonly organization_id?: string
|
||||
readonly owner?: string
|
||||
readonly name?: string
|
||||
}
|
||||
|
||||
// From codersdk/workspaces.go:41:6
|
||||
export interface WorkspaceOptions {
|
||||
readonly deleted?: boolean
|
||||
}
|
||||
|
||||
// From codersdk/workspaceresources.go:21:6
|
||||
export interface WorkspaceResource {
|
||||
readonly id: string
|
||||
|
||||
Reference in New Issue
Block a user