fix(cli): display workspace created at time instead of current time (#19553)

Applying a suggestion from
https://github.com/coder/coder/pull/19492#discussion_r2301175791
This commit is contained in:
Danielle Maywood
2025-08-26 15:57:44 +01:00
committed by GitHub
parent ef0d74fb75
commit c19f430f35
2 changed files with 13 additions and 10 deletions
+1 -2
View File
@@ -3,7 +3,6 @@ package cli
import ( import (
"fmt" "fmt"
"strings" "strings"
"time"
"github.com/google/uuid" "github.com/google/uuid"
"golang.org/x/xerrors" "golang.org/x/xerrors"
@@ -118,7 +117,7 @@ func (r *RootCmd) taskCreate() *serpent.Command {
inv.Stdout, inv.Stdout,
"The task %s has been created at %s!\n", "The task %s has been created at %s!\n",
cliui.Keyword(workspace.Name), cliui.Keyword(workspace.Name),
cliui.Timestamp(time.Now()), cliui.Timestamp(workspace.CreatedAt),
) )
return nil return nil
+11 -7
View File
@@ -8,6 +8,7 @@ import (
"net/url" "net/url"
"strings" "strings"
"testing" "testing"
"time"
"github.com/google/uuid" "github.com/google/uuid"
"github.com/stretchr/testify/assert" "github.com/stretchr/testify/assert"
@@ -25,6 +26,8 @@ func TestTaskCreate(t *testing.T) {
t.Parallel() t.Parallel()
var ( var (
taskCreatedAt = time.Now()
organizationID = uuid.New() organizationID = uuid.New()
templateID = uuid.New() templateID = uuid.New()
templateVersionID = uuid.New() templateVersionID = uuid.New()
@@ -75,6 +78,7 @@ func TestTaskCreate(t *testing.T) {
httpapi.Write(ctx, w, http.StatusCreated, codersdk.Workspace{ httpapi.Write(ctx, w, http.StatusCreated, codersdk.Workspace{
Name: "task-wild-goldfish-27", Name: "task-wild-goldfish-27",
CreatedAt: taskCreatedAt,
}) })
default: default:
t.Errorf("unexpected path: %s", r.URL.Path) t.Errorf("unexpected path: %s", r.URL.Path)
@@ -91,7 +95,7 @@ func TestTaskCreate(t *testing.T) {
}{ }{
{ {
args: []string{"my-template@my-template-version", "--input", "my custom prompt"}, args: []string{"my-template@my-template-version", "--input", "my custom prompt"},
expectOutput: fmt.Sprintf("The task %s has been created", cliui.Keyword("task-wild-goldfish-27")), expectOutput: fmt.Sprintf("The task %s has been created at %s!", cliui.Keyword("task-wild-goldfish-27"), cliui.Timestamp(taskCreatedAt)),
handler: func(t *testing.T, ctx context.Context) http.HandlerFunc { handler: func(t *testing.T, ctx context.Context) http.HandlerFunc {
return templateAndVersionFoundHandler(t, ctx, "my-template", "my-template-version", "", "my custom prompt") return templateAndVersionFoundHandler(t, ctx, "my-template", "my-template-version", "", "my custom prompt")
}, },
@@ -99,7 +103,7 @@ func TestTaskCreate(t *testing.T) {
{ {
args: []string{"my-template", "--input", "my custom prompt"}, args: []string{"my-template", "--input", "my custom prompt"},
env: []string{"CODER_TASK_TEMPLATE_VERSION=my-template-version"}, env: []string{"CODER_TASK_TEMPLATE_VERSION=my-template-version"},
expectOutput: fmt.Sprintf("The task %s has been created", cliui.Keyword("task-wild-goldfish-27")), expectOutput: fmt.Sprintf("The task %s has been created at %s!", cliui.Keyword("task-wild-goldfish-27"), cliui.Timestamp(taskCreatedAt)),
handler: func(t *testing.T, ctx context.Context) http.HandlerFunc { handler: func(t *testing.T, ctx context.Context) http.HandlerFunc {
return templateAndVersionFoundHandler(t, ctx, "my-template", "my-template-version", "", "my custom prompt") return templateAndVersionFoundHandler(t, ctx, "my-template", "my-template-version", "", "my custom prompt")
}, },
@@ -107,28 +111,28 @@ func TestTaskCreate(t *testing.T) {
{ {
args: []string{"--input", "my custom prompt"}, args: []string{"--input", "my custom prompt"},
env: []string{"CODER_TASK_TEMPLATE_NAME=my-template", "CODER_TASK_TEMPLATE_VERSION=my-template-version"}, env: []string{"CODER_TASK_TEMPLATE_NAME=my-template", "CODER_TASK_TEMPLATE_VERSION=my-template-version"},
expectOutput: fmt.Sprintf("The task %s has been created", cliui.Keyword("task-wild-goldfish-27")), expectOutput: fmt.Sprintf("The task %s has been created at %s!", cliui.Keyword("task-wild-goldfish-27"), cliui.Timestamp(taskCreatedAt)),
handler: func(t *testing.T, ctx context.Context) http.HandlerFunc { handler: func(t *testing.T, ctx context.Context) http.HandlerFunc {
return templateAndVersionFoundHandler(t, ctx, "my-template", "my-template-version", "", "my custom prompt") return templateAndVersionFoundHandler(t, ctx, "my-template", "my-template-version", "", "my custom prompt")
}, },
}, },
{ {
env: []string{"CODER_TASK_TEMPLATE_NAME=my-template", "CODER_TASK_TEMPLATE_VERSION=my-template-version", "CODER_TASK_INPUT=my custom prompt"}, env: []string{"CODER_TASK_TEMPLATE_NAME=my-template", "CODER_TASK_TEMPLATE_VERSION=my-template-version", "CODER_TASK_INPUT=my custom prompt"},
expectOutput: fmt.Sprintf("The task %s has been created", cliui.Keyword("task-wild-goldfish-27")), expectOutput: fmt.Sprintf("The task %s has been created at %s!", cliui.Keyword("task-wild-goldfish-27"), cliui.Timestamp(taskCreatedAt)),
handler: func(t *testing.T, ctx context.Context) http.HandlerFunc { handler: func(t *testing.T, ctx context.Context) http.HandlerFunc {
return templateAndVersionFoundHandler(t, ctx, "my-template", "my-template-version", "", "my custom prompt") return templateAndVersionFoundHandler(t, ctx, "my-template", "my-template-version", "", "my custom prompt")
}, },
}, },
{ {
args: []string{"my-template", "--input", "my custom prompt"}, args: []string{"my-template", "--input", "my custom prompt"},
expectOutput: fmt.Sprintf("The task %s has been created", cliui.Keyword("task-wild-goldfish-27")), expectOutput: fmt.Sprintf("The task %s has been created at %s!", cliui.Keyword("task-wild-goldfish-27"), cliui.Timestamp(taskCreatedAt)),
handler: func(t *testing.T, ctx context.Context) http.HandlerFunc { handler: func(t *testing.T, ctx context.Context) http.HandlerFunc {
return templateAndVersionFoundHandler(t, ctx, "my-template", "", "", "my custom prompt") return templateAndVersionFoundHandler(t, ctx, "my-template", "", "", "my custom prompt")
}, },
}, },
{ {
args: []string{"my-template", "--input", "my custom prompt", "--preset", "my-preset"}, args: []string{"my-template", "--input", "my custom prompt", "--preset", "my-preset"},
expectOutput: fmt.Sprintf("The task %s has been created", cliui.Keyword("task-wild-goldfish-27")), expectOutput: fmt.Sprintf("The task %s has been created at %s!", cliui.Keyword("task-wild-goldfish-27"), cliui.Timestamp(taskCreatedAt)),
handler: func(t *testing.T, ctx context.Context) http.HandlerFunc { handler: func(t *testing.T, ctx context.Context) http.HandlerFunc {
return templateAndVersionFoundHandler(t, ctx, "my-template", "", "my-preset", "my custom prompt") return templateAndVersionFoundHandler(t, ctx, "my-template", "", "my-preset", "my custom prompt")
}, },
@@ -136,7 +140,7 @@ func TestTaskCreate(t *testing.T) {
{ {
args: []string{"my-template", "--input", "my custom prompt"}, args: []string{"my-template", "--input", "my custom prompt"},
env: []string{"CODER_TASK_PRESET_NAME=my-preset"}, env: []string{"CODER_TASK_PRESET_NAME=my-preset"},
expectOutput: fmt.Sprintf("The task %s has been created", cliui.Keyword("task-wild-goldfish-27")), expectOutput: fmt.Sprintf("The task %s has been created at %s!", cliui.Keyword("task-wild-goldfish-27"), cliui.Timestamp(taskCreatedAt)),
handler: func(t *testing.T, ctx context.Context) http.HandlerFunc { handler: func(t *testing.T, ctx context.Context) http.HandlerFunc {
return templateAndVersionFoundHandler(t, ctx, "my-template", "", "my-preset", "my custom prompt") return templateAndVersionFoundHandler(t, ctx, "my-template", "", "my-preset", "my custom prompt")
}, },