@@ -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 ,taskName string ) http.HandlerFunc {
37
+ templateAndVersionFoundHandler := func (t * testing.T ,ctx context.Context ,orgID uuid.UUID ,templateName ,templateVersionName ,presetName ,prompt ,taskName , username string ) http.HandlerFunc {
38
38
t .Helper ()
39
39
40
40
return func (w http.ResponseWriter ,r * http.Request ) {
@@ -69,7 +69,7 @@ func TestTaskCreate(t *testing.T) {
69
69
ActiveVersionID :templateVersionID ,
70
70
},
71
71
})
72
- case "/api/experimental/tasks/me" :
72
+ case fmt . Sprintf ( "/api/experimental/tasks/%s" , username ) :
73
73
var req codersdk.CreateTaskRequest
74
74
if ! httpapi .Read (ctx ,w ,r ,& req ) {
75
75
return
@@ -114,80 +114,87 @@ func TestTaskCreate(t *testing.T) {
114
114
stdin :"reads prompt from stdin" ,
115
115
expectOutput :fmt .Sprintf ("The task %s has been created at %s!" ,cliui .Keyword ("task-wild-goldfish-27" ),cliui .Timestamp (taskCreatedAt )),
116
116
handler :func (t * testing.T ,ctx context.Context ) http.HandlerFunc {
117
- return templateAndVersionFoundHandler (t ,ctx ,organizationID ,"my-template" ,"my-template-version" ,"" ,"reads prompt from stdin" ,"task-wild-goldfish-27" )
117
+ return templateAndVersionFoundHandler (t ,ctx ,organizationID ,"my-template" ,"my-template-version" ,"" ,"reads prompt from stdin" ,"task-wild-goldfish-27" , codersdk . Me )
118
118
},
119
119
},
120
120
{
121
121
args : []string {"my custom prompt" },
122
122
expectOutput :fmt .Sprintf ("The task %s has been created at %s!" ,cliui .Keyword ("task-wild-goldfish-27" ),cliui .Timestamp (taskCreatedAt )),
123
123
handler :func (t * testing.T ,ctx context.Context ) http.HandlerFunc {
124
- return templateAndVersionFoundHandler (t ,ctx ,organizationID ,"my-template" ,"my-template-version" ,"" ,"my custom prompt" ,"task-wild-goldfish-27" )
124
+ return templateAndVersionFoundHandler (t ,ctx ,organizationID ,"my-template" ,"my-template-version" ,"" ,"my custom prompt" ,"task-wild-goldfish-27" ,codersdk .Me )
125
+ },
126
+ },
127
+ {
128
+ args : []string {"my custom prompt" ,"--owner" ,"someone-else" },
129
+ expectOutput :fmt .Sprintf ("The task %s has been created at %s!" ,cliui .Keyword ("task-wild-goldfish-27" ),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" ,"task-wild-goldfish-27" ,"someone-else" )
125
132
},
126
133
},
127
134
{
128
135
args : []string {"--name" ,"abc123" ,"my custom prompt" },
129
136
expectOutput :fmt .Sprintf ("The task %s has been created at %s!" ,cliui .Keyword ("abc123" ),cliui .Timestamp (taskCreatedAt )),
130
137
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" )
138
+ return templateAndVersionFoundHandler (t ,ctx ,organizationID ,"my-template" ,"my-template-version" ,"" ,"my custom prompt" ,"abc123" , codersdk . Me )
132
139
},
133
140
},
134
141
{
135
142
args : []string {"my custom prompt" ,"--template" ,"my-template" ,"--template-version" ,"my-template-version" ,"--org" ,organizationID .String ()},
136
143
expectOutput :fmt .Sprintf ("The task %s has been created at %s!" ,cliui .Keyword ("task-wild-goldfish-27" ),cliui .Timestamp (taskCreatedAt )),
137
144
handler :func (t * testing.T ,ctx context.Context ) http.HandlerFunc {
138
- return templateAndVersionFoundHandler (t ,ctx ,organizationID ,"my-template" ,"my-template-version" ,"" ,"my custom prompt" ,"task-wild-goldfish-27" )
145
+ return templateAndVersionFoundHandler (t ,ctx ,organizationID ,"my-template" ,"my-template-version" ,"" ,"my custom prompt" ,"task-wild-goldfish-27" , codersdk . Me )
139
146
},
140
147
},
141
148
{
142
149
args : []string {"my custom prompt" ,"--template" ,"my-template" ,"--org" ,organizationID .String ()},
143
150
env : []string {"CODER_TASK_TEMPLATE_VERSION=my-template-version" },
144
151
expectOutput :fmt .Sprintf ("The task %s has been created at %s!" ,cliui .Keyword ("task-wild-goldfish-27" ),cliui .Timestamp (taskCreatedAt )),
145
152
handler :func (t * testing.T ,ctx context.Context ) http.HandlerFunc {
146
- return templateAndVersionFoundHandler (t ,ctx ,organizationID ,"my-template" ,"my-template-version" ,"" ,"my custom prompt" ,"task-wild-goldfish-27" )
153
+ return templateAndVersionFoundHandler (t ,ctx ,organizationID ,"my-template" ,"my-template-version" ,"" ,"my custom prompt" ,"task-wild-goldfish-27" , codersdk . Me )
147
154
},
148
155
},
149
156
{
150
157
args : []string {"my custom prompt" ,"--org" ,organizationID .String ()},
151
158
env : []string {"CODER_TASK_TEMPLATE_NAME=my-template" ,"CODER_TASK_TEMPLATE_VERSION=my-template-version" },
152
159
expectOutput :fmt .Sprintf ("The task %s has been created at %s!" ,cliui .Keyword ("task-wild-goldfish-27" ),cliui .Timestamp (taskCreatedAt )),
153
160
handler :func (t * testing.T ,ctx context.Context ) http.HandlerFunc {
154
- return templateAndVersionFoundHandler (t ,ctx ,organizationID ,"my-template" ,"my-template-version" ,"" ,"my custom prompt" ,"task-wild-goldfish-27" )
161
+ return templateAndVersionFoundHandler (t ,ctx ,organizationID ,"my-template" ,"my-template-version" ,"" ,"my custom prompt" ,"task-wild-goldfish-27" , codersdk . Me )
155
162
},
156
163
},
157
164
{
158
165
args : []string {"my custom prompt" ,"--template" ,"my-template" ,"--org" ,organizationID .String ()},
159
166
expectOutput :fmt .Sprintf ("The task %s has been created at %s!" ,cliui .Keyword ("task-wild-goldfish-27" ),cliui .Timestamp (taskCreatedAt )),
160
167
handler :func (t * testing.T ,ctx context.Context ) http.HandlerFunc {
161
- return templateAndVersionFoundHandler (t ,ctx ,organizationID ,"my-template" ,"" ,"" ,"my custom prompt" ,"task-wild-goldfish-27" )
168
+ return templateAndVersionFoundHandler (t ,ctx ,organizationID ,"my-template" ,"" ,"" ,"my custom prompt" ,"task-wild-goldfish-27" , codersdk . Me )
162
169
},
163
170
},
164
171
{
165
172
args : []string {"my custom prompt" ,"--template" ,"my-template" ,"--preset" ,"my-preset" ,"--org" ,organizationID .String ()},
166
173
expectOutput :fmt .Sprintf ("The task %s has been created at %s!" ,cliui .Keyword ("task-wild-goldfish-27" ),cliui .Timestamp (taskCreatedAt )),
167
174
handler :func (t * testing.T ,ctx context.Context ) http.HandlerFunc {
168
- return templateAndVersionFoundHandler (t ,ctx ,organizationID ,"my-template" ,"" ,"my-preset" ,"my custom prompt" ,"task-wild-goldfish-27" )
175
+ return templateAndVersionFoundHandler (t ,ctx ,organizationID ,"my-template" ,"" ,"my-preset" ,"my custom prompt" ,"task-wild-goldfish-27" , codersdk . Me )
169
176
},
170
177
},
171
178
{
172
179
args : []string {"my custom prompt" ,"--template" ,"my-template" },
173
180
env : []string {"CODER_TASK_PRESET_NAME=my-preset" },
174
181
expectOutput :fmt .Sprintf ("The task %s has been created at %s!" ,cliui .Keyword ("task-wild-goldfish-27" ),cliui .Timestamp (taskCreatedAt )),
175
182
handler :func (t * testing.T ,ctx context.Context ) http.HandlerFunc {
176
- return templateAndVersionFoundHandler (t ,ctx ,organizationID ,"my-template" ,"" ,"my-preset" ,"my custom prompt" ,"task-wild-goldfish-27" )
183
+ return templateAndVersionFoundHandler (t ,ctx ,organizationID ,"my-template" ,"" ,"my-preset" ,"my custom prompt" ,"task-wild-goldfish-27" , codersdk . Me )
177
184
},
178
185
},
179
186
{
180
187
args : []string {"my custom prompt" ,"-q" },
181
188
expectOutput :taskID .String (),
182
189
handler :func (t * testing.T ,ctx context.Context ) http.HandlerFunc {
183
- return templateAndVersionFoundHandler (t ,ctx ,organizationID ,"my-template" ,"my-template-version" ,"" ,"my custom prompt" ,"task-wild-goldfish-27" )
190
+ return templateAndVersionFoundHandler (t ,ctx ,organizationID ,"my-template" ,"my-template-version" ,"" ,"my custom prompt" ,"task-wild-goldfish-27" , codersdk . Me )
184
191
},
185
192
},
186
193
{
187
194
args : []string {"my custom prompt" ,"--template" ,"my-template" ,"--preset" ,"not-real-preset" },
188
195
expectError :`preset "not-real-preset" not found` ,
189
196
handler :func (t * testing.T ,ctx context.Context ) http.HandlerFunc {
190
- return templateAndVersionFoundHandler (t ,ctx ,organizationID ,"my-template" ,"" ,"my-preset" ,"my custom prompt" ,"task-wild-goldfish-27" )
197
+ return templateAndVersionFoundHandler (t ,ctx ,organizationID ,"my-template" ,"" ,"my-preset" ,"my custom prompt" ,"task-wild-goldfish-27" , codersdk . Me )
191
198
},
192
199
},
193
200
{