mirror of
https://github.com/coder/coder.git
synced 2026-09-24 15:04:27 +08:00
feat: add 'impending deletion' badges to workspaces page (#7530)
* update deleting logic
* added status badge on workspaces page
* licensing and feature flagging
* preset filter for failed workspaces
* remove comment
* PR feedback
* Revert "PR feedback"
This reverts commit 2dfbb50acd.
* PR feedback 2
This commit is contained in:
@@ -8,6 +8,7 @@ import (
|
||||
|
||||
"github.com/coder/coder/coderd/database"
|
||||
"github.com/coder/coder/coderd/util/ptr"
|
||||
"github.com/coder/coder/codersdk"
|
||||
)
|
||||
|
||||
func Test_calculateDeletingAt(t *testing.T) {
|
||||
@@ -17,10 +18,11 @@ func Test_calculateDeletingAt(t *testing.T) {
|
||||
name string
|
||||
workspace database.Workspace
|
||||
template database.Template
|
||||
build codersdk.WorkspaceBuild
|
||||
expected *time.Time
|
||||
}{
|
||||
{
|
||||
name: "DeletingAt",
|
||||
name: "InactiveWorkspace",
|
||||
workspace: database.Workspace{
|
||||
Deleted: false,
|
||||
LastUsedAt: time.Now().Add(time.Duration(-10) * time.Hour * 24), // 10 days ago
|
||||
@@ -28,6 +30,9 @@ func Test_calculateDeletingAt(t *testing.T) {
|
||||
template: database.Template{
|
||||
InactivityTTL: int64(9 * 24 * time.Hour), // 9 days
|
||||
},
|
||||
build: codersdk.WorkspaceBuild{
|
||||
Status: codersdk.WorkspaceStatusStopped,
|
||||
},
|
||||
expected: ptr.Ref(time.Now().Add(time.Duration(-1) * time.Hour * 24)), // yesterday
|
||||
},
|
||||
{
|
||||
@@ -39,27 +44,22 @@ func Test_calculateDeletingAt(t *testing.T) {
|
||||
template: database.Template{
|
||||
InactivityTTL: 0,
|
||||
},
|
||||
expected: nil,
|
||||
},
|
||||
{
|
||||
name: "DeletedWorkspace",
|
||||
workspace: database.Workspace{
|
||||
Deleted: true,
|
||||
LastUsedAt: time.Now().Add(time.Duration(-10) * time.Hour * 24),
|
||||
},
|
||||
template: database.Template{
|
||||
InactivityTTL: int64(9 * 24 * time.Hour),
|
||||
build: codersdk.WorkspaceBuild{
|
||||
Status: codersdk.WorkspaceStatusStopped,
|
||||
},
|
||||
expected: nil,
|
||||
},
|
||||
{
|
||||
name: "ActiveWorkspace",
|
||||
workspace: database.Workspace{
|
||||
Deleted: true,
|
||||
LastUsedAt: time.Now().Add(time.Duration(-5) * time.Hour), // 5 hours ago
|
||||
Deleted: false,
|
||||
LastUsedAt: time.Now(),
|
||||
},
|
||||
template: database.Template{
|
||||
InactivityTTL: int64(1 * 24 * time.Hour), // 1 day
|
||||
InactivityTTL: int64(1 * 24 * time.Hour),
|
||||
},
|
||||
build: codersdk.WorkspaceBuild{
|
||||
Status: codersdk.WorkspaceStatusRunning,
|
||||
},
|
||||
expected: nil,
|
||||
},
|
||||
@@ -70,7 +70,7 @@ func Test_calculateDeletingAt(t *testing.T) {
|
||||
t.Run(tc.name, func(t *testing.T) {
|
||||
t.Parallel()
|
||||
|
||||
found := calculateDeletingAt(tc.workspace, tc.template)
|
||||
found := calculateDeletingAt(tc.workspace, tc.template, tc.build)
|
||||
if tc.expected == nil {
|
||||
require.Nil(t, found, "impending deletion should be nil")
|
||||
} else {
|
||||
|
||||
Reference in New Issue
Block a user