Skip to content
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
fix: coderd: add test for nonexistent workspace
  • Loading branch information
johnstcn committed Apr 6, 2022
commit ff80571eed293b2c414e351459b0808d0aa7ccbd
16 changes: 16 additions & 0 deletions coderd/workspaces_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package coderd_test

import (
"context"
"fmt"
"net/http"
"testing"
"time"
Expand Down Expand Up @@ -292,6 +293,21 @@ func TestWorkspaceUpdateAutostart(t *testing.T) {
require.Equal(t, testCase.expectedInterval, interval, "unexpected interval")
})
}

t.Run("NotFound", func(t *testing.T) {
var (
ctx = context.Background()
client = coderdtest.New(t, nil)
_ = coderdtest.CreateFirstUser(t, client)
wsid = uuid.New()
req = codersdk.UpdateWorkspaceAutostartRequest{
Schedule: "9 30 1-5",
}
)

err := client.UpdateWorkspaceAutostart(ctx, wsid, req)
require.EqualError(t, err, fmt.Sprintf("status code 404: workspace %q does not exist", wsid), "unexpected error")
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit: We could assert to codersdk.Error here to check the status code!

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ack

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

FYI I ended up needing to squelch a linter error when trying to use errors.As on codersdk.Error.
This is the sort of thing I ended up with: https://go.dev/play/p/NHTmnYWan6g

})
}

func mustLocation(t *testing.T, location string) *time.Location {
Expand Down