@@ -34,7 +34,7 @@ func TestTaskCreate(t *testing.T) {
34
34
taskID = uuid .New ()
35
35
)
36
36
37
- templateAndVersionFoundHandler := func (t * testing.T ,ctx context.Context ,orgID uuid.UUID ,templateName ,templateVersionName ,presetName ,prompt string ) http.HandlerFunc {
37
+ templateAndVersionFoundHandler := func (t * testing.T ,ctx context.Context ,orgID uuid.UUID ,templateName ,templateVersionName ,presetName ,prompt , taskName string ) http.HandlerFunc {
38
38
t .Helper ()
39
39
40
40
return func (w http.ResponseWriter ,r * http.Request ) {
@@ -84,11 +84,17 @@ func TestTaskCreate(t *testing.T) {
84
84
assert .Equal (t ,templateVersionPresetID ,req .TemplateVersionPresetID ,"template version preset id mismatch" )
85
85
}
86
86
87
- httpapi . Write ( ctx , w , http . StatusCreated , codersdk.Task {
87
+ created := codersdk.Task {
88
88
ID :taskID ,
89
- Name :"task-wild-goldfish-27" ,
89
+ Name :taskName ,
90
90
CreatedAt :taskCreatedAt ,
91
- })
91
+ }
92
+ if req .Name != "" {
93
+ assert .Equal (t ,req .Name ,taskName ,"name mismatch" )
94
+ created .Name = req .Name
95
+ }
96
+
97
+ httpapi .Write (ctx ,w ,http .StatusCreated ,created )
92
98
default :
93
99
t .Errorf ("unexpected path: %s" ,r .URL .Path )
94
100
}
@@ -108,73 +114,80 @@ func TestTaskCreate(t *testing.T) {
108
114
stdin :"reads prompt from stdin" ,
109
115
expectOutput :fmt .Sprintf ("The task %s has been created at %s!" ,cliui .Keyword ("task-wild-goldfish-27" ),cliui .Timestamp (taskCreatedAt )),
110
116
handler :func (t * testing.T ,ctx context.Context ) http.HandlerFunc {
111
- return templateAndVersionFoundHandler (t ,ctx ,organizationID ,"my-template" ,"my-template-version" ,"" ,"reads prompt from stdin" )
117
+ return templateAndVersionFoundHandler (t ,ctx ,organizationID ,"my-template" ,"my-template-version" ,"" ,"reads prompt from stdin" , "task-wild-goldfish-27" )
112
118
},
113
119
},
114
120
{
115
121
args : []string {"my custom prompt" },
116
122
expectOutput :fmt .Sprintf ("The task %s has been created at %s!" ,cliui .Keyword ("task-wild-goldfish-27" ),cliui .Timestamp (taskCreatedAt )),
117
123
handler :func (t * testing.T ,ctx context.Context ) http.HandlerFunc {
118
- return templateAndVersionFoundHandler (t ,ctx ,organizationID ,"my-template" ,"my-template-version" ,"" ,"my custom prompt" )
124
+ return templateAndVersionFoundHandler (t ,ctx ,organizationID ,"my-template" ,"my-template-version" ,"" ,"my custom prompt" ,"task-wild-goldfish-27" )
125
+ },
126
+ },
127
+ {
128
+ args : []string {"--name" ,"abc123" ,"my custom prompt" },
129
+ expectOutput :fmt .Sprintf ("The task %s has been created at %s!" ,cliui .Keyword ("abc123" ),cliui .Timestamp (taskCreatedAt )),
130
+ handler :func (t * testing.T ,ctx context.Context ) http.HandlerFunc {
131
+ return templateAndVersionFoundHandler (t ,ctx ,organizationID ,"my-template" ,"my-template-version" ,"" ,"my custom prompt" ,"abc123" )
119
132
},
120
133
},
121
134
{
122
135
args : []string {"my custom prompt" ,"--template" ,"my-template" ,"--template-version" ,"my-template-version" ,"--org" ,organizationID .String ()},
123
136
expectOutput :fmt .Sprintf ("The task %s has been created at %s!" ,cliui .Keyword ("task-wild-goldfish-27" ),cliui .Timestamp (taskCreatedAt )),
124
137
handler :func (t * testing.T ,ctx context.Context ) http.HandlerFunc {
125
- return templateAndVersionFoundHandler (t ,ctx ,organizationID ,"my-template" ,"my-template-version" ,"" ,"my custom prompt" )
138
+ return templateAndVersionFoundHandler (t ,ctx ,organizationID ,"my-template" ,"my-template-version" ,"" ,"my custom prompt" , "task-wild-goldfish-27" )
126
139
},
127
140
},
128
141
{
129
142
args : []string {"my custom prompt" ,"--template" ,"my-template" ,"--org" ,organizationID .String ()},
130
143
env : []string {"CODER_TASK_TEMPLATE_VERSION=my-template-version" },
131
144
expectOutput :fmt .Sprintf ("The task %s has been created at %s!" ,cliui .Keyword ("task-wild-goldfish-27" ),cliui .Timestamp (taskCreatedAt )),
132
145
handler :func (t * testing.T ,ctx context.Context ) http.HandlerFunc {
133
- return templateAndVersionFoundHandler (t ,ctx ,organizationID ,"my-template" ,"my-template-version" ,"" ,"my custom prompt" )
146
+ return templateAndVersionFoundHandler (t ,ctx ,organizationID ,"my-template" ,"my-template-version" ,"" ,"my custom prompt" , "task-wild-goldfish-27" )
134
147
},
135
148
},
136
149
{
137
150
args : []string {"my custom prompt" ,"--org" ,organizationID .String ()},
138
151
env : []string {"CODER_TASK_TEMPLATE_NAME=my-template" ,"CODER_TASK_TEMPLATE_VERSION=my-template-version" },
139
152
expectOutput :fmt .Sprintf ("The task %s has been created at %s!" ,cliui .Keyword ("task-wild-goldfish-27" ),cliui .Timestamp (taskCreatedAt )),
140
153
handler :func (t * testing.T ,ctx context.Context ) http.HandlerFunc {
141
- return templateAndVersionFoundHandler (t ,ctx ,organizationID ,"my-template" ,"my-template-version" ,"" ,"my custom prompt" )
154
+ return templateAndVersionFoundHandler (t ,ctx ,organizationID ,"my-template" ,"my-template-version" ,"" ,"my custom prompt" , "task-wild-goldfish-27" )
142
155
},
143
156
},
144
157
{
145
158
args : []string {"my custom prompt" ,"--template" ,"my-template" ,"--org" ,organizationID .String ()},
146
159
expectOutput :fmt .Sprintf ("The task %s has been created at %s!" ,cliui .Keyword ("task-wild-goldfish-27" ),cliui .Timestamp (taskCreatedAt )),
147
160
handler :func (t * testing.T ,ctx context.Context ) http.HandlerFunc {
148
- return templateAndVersionFoundHandler (t ,ctx ,organizationID ,"my-template" ,"" ,"" ,"my custom prompt" )
161
+ return templateAndVersionFoundHandler (t ,ctx ,organizationID ,"my-template" ,"" ,"" ,"my custom prompt" , "task-wild-goldfish-27" )
149
162
},
150
163
},
151
164
{
152
165
args : []string {"my custom prompt" ,"--template" ,"my-template" ,"--preset" ,"my-preset" ,"--org" ,organizationID .String ()},
153
166
expectOutput :fmt .Sprintf ("The task %s has been created at %s!" ,cliui .Keyword ("task-wild-goldfish-27" ),cliui .Timestamp (taskCreatedAt )),
154
167
handler :func (t * testing.T ,ctx context.Context ) http.HandlerFunc {
155
- return templateAndVersionFoundHandler (t ,ctx ,organizationID ,"my-template" ,"" ,"my-preset" ,"my custom prompt" )
168
+ return templateAndVersionFoundHandler (t ,ctx ,organizationID ,"my-template" ,"" ,"my-preset" ,"my custom prompt" , "task-wild-goldfish-27" )
156
169
},
157
170
},
158
171
{
159
172
args : []string {"my custom prompt" ,"--template" ,"my-template" },
160
173
env : []string {"CODER_TASK_PRESET_NAME=my-preset" },
161
174
expectOutput :fmt .Sprintf ("The task %s has been created at %s!" ,cliui .Keyword ("task-wild-goldfish-27" ),cliui .Timestamp (taskCreatedAt )),
162
175
handler :func (t * testing.T ,ctx context.Context ) http.HandlerFunc {
163
- return templateAndVersionFoundHandler (t ,ctx ,organizationID ,"my-template" ,"" ,"my-preset" ,"my custom prompt" )
176
+ return templateAndVersionFoundHandler (t ,ctx ,organizationID ,"my-template" ,"" ,"my-preset" ,"my custom prompt" , "task-wild-goldfish-27" )
164
177
},
165
178
},
166
179
{
167
180
args : []string {"my custom prompt" ,"-q" },
168
181
expectOutput :taskID .String (),
169
182
handler :func (t * testing.T ,ctx context.Context ) http.HandlerFunc {
170
- return templateAndVersionFoundHandler (t ,ctx ,organizationID ,"my-template" ,"my-template-version" ,"" ,"my custom prompt" )
183
+ return templateAndVersionFoundHandler (t ,ctx ,organizationID ,"my-template" ,"my-template-version" ,"" ,"my custom prompt" , "task-wild-goldfish-27" )
171
184
},
172
185
},
173
186
{
174
187
args : []string {"my custom prompt" ,"--template" ,"my-template" ,"--preset" ,"not-real-preset" },
175
188
expectError :`preset "not-real-preset" not found` ,
176
189
handler :func (t * testing.T ,ctx context.Context ) http.HandlerFunc {
177
- return templateAndVersionFoundHandler (t ,ctx ,organizationID ,"my-template" ,"" ,"my-preset" ,"my custom prompt" )
190
+ return templateAndVersionFoundHandler (t ,ctx ,organizationID ,"my-template" ,"" ,"my-preset" ,"my custom prompt" , "task-wild-goldfish-27" )
178
191
},
179
192
},
180
193
{