@@ -60,6 +60,14 @@ func TestTaskCreate(t *testing.T) {
60
60
Name :presetName ,
61
61
},
62
62
})
63
+ case "/api/v2/templates" :
64
+ httpapi .Write (ctx ,w ,http .StatusOK , []codersdk.Template {
65
+ {
66
+ ID :templateID ,
67
+ Name :templateName ,
68
+ ActiveVersionID :templateVersionID ,
69
+ },
70
+ })
63
71
case "/api/experimental/tasks/me" :
64
72
var req codersdk.CreateTaskRequest
65
73
if ! httpapi .Read (ctx ,w ,r ,& req ) {
@@ -93,22 +101,29 @@ func TestTaskCreate(t *testing.T) {
93
101
handler func (t * testing.T ,ctx context.Context ) http.HandlerFunc
94
102
}{
95
103
{
96
- args : []string {"my-template@my-template-version" ,"--input" ,"my custom prompt" ,"--org" ,organizationID .String ()},
104
+ args : []string {"my custom prompt" },
105
+ expectOutput :fmt .Sprintf ("The task %s has been created at %s!" ,cliui .Keyword ("task-wild-goldfish-27" ),cliui .Timestamp (taskCreatedAt )),
106
+ handler :func (t * testing.T ,ctx context.Context ) http.HandlerFunc {
107
+ return templateAndVersionFoundHandler (t ,ctx ,organizationID ,"my-template" ,"my-template-version" ,"" ,"my custom prompt" )
108
+ },
109
+ },
110
+ {
111
+ args : []string {"my custom prompt" ,"--template" ,"my-template" ,"--template-version" ,"my-template-version" ,"--org" ,organizationID .String ()},
97
112
expectOutput :fmt .Sprintf ("The task %s has been created at %s!" ,cliui .Keyword ("task-wild-goldfish-27" ),cliui .Timestamp (taskCreatedAt )),
98
113
handler :func (t * testing.T ,ctx context.Context ) http.HandlerFunc {
99
114
return templateAndVersionFoundHandler (t ,ctx ,organizationID ,"my-template" ,"my-template-version" ,"" ,"my custom prompt" )
100
115
},
101
116
},
102
117
{
103
- args : []string {"my-template " ,"--input " ,"my custom prompt " ,"--org" ,organizationID .String ()},
118
+ args : []string {"my custom prompt " ,"--template " ,"my-template " ,"--org" ,organizationID .String ()},
104
119
env : []string {"CODER_TASK_TEMPLATE_VERSION=my-template-version" },
105
120
expectOutput :fmt .Sprintf ("The task %s has been created at %s!" ,cliui .Keyword ("task-wild-goldfish-27" ),cliui .Timestamp (taskCreatedAt )),
106
121
handler :func (t * testing.T ,ctx context.Context ) http.HandlerFunc {
107
122
return templateAndVersionFoundHandler (t ,ctx ,organizationID ,"my-template" ,"my-template-version" ,"" ,"my custom prompt" )
108
123
},
109
124
},
110
125
{
111
- args : []string {"--input" , " my custom prompt" ,"--org" ,organizationID .String ()},
126
+ args : []string {"my custom prompt" ,"--org" ,organizationID .String ()},
112
127
env : []string {"CODER_TASK_TEMPLATE_NAME=my-template" ,"CODER_TASK_TEMPLATE_VERSION=my-template-version" },
113
128
expectOutput :fmt .Sprintf ("The task %s has been created at %s!" ,cliui .Keyword ("task-wild-goldfish-27" ),cliui .Timestamp (taskCreatedAt )),
114
129
handler :func (t * testing.T ,ctx context.Context ) http.HandlerFunc {
@@ -123,36 +138,36 @@ func TestTaskCreate(t *testing.T) {
123
138
},
124
139
},
125
140
{
126
- args : []string {"my-template " ,"--input " ,"my custom prompt " ,"--org" ,organizationID .String ()},
141
+ args : []string {"my custom prompt " ,"--template " ,"my-template " ,"--org" ,organizationID .String ()},
127
142
expectOutput :fmt .Sprintf ("The task %s has been created at %s!" ,cliui .Keyword ("task-wild-goldfish-27" ),cliui .Timestamp (taskCreatedAt )),
128
143
handler :func (t * testing.T ,ctx context.Context ) http.HandlerFunc {
129
144
return templateAndVersionFoundHandler (t ,ctx ,organizationID ,"my-template" ,"" ,"" ,"my custom prompt" )
130
145
},
131
146
},
132
147
{
133
- args : []string {"my-template " ,"--input " ,"my custom prompt " ,"--preset" ,"my-preset" ,"--org" ,organizationID .String ()},
148
+ args : []string {"my custom prompt " ,"--template " ,"my-template " ,"--preset" ,"my-preset" ,"--org" ,organizationID .String ()},
134
149
expectOutput :fmt .Sprintf ("The task %s has been created at %s!" ,cliui .Keyword ("task-wild-goldfish-27" ),cliui .Timestamp (taskCreatedAt )),
135
150
handler :func (t * testing.T ,ctx context.Context ) http.HandlerFunc {
136
151
return templateAndVersionFoundHandler (t ,ctx ,organizationID ,"my-template" ,"" ,"my-preset" ,"my custom prompt" )
137
152
},
138
153
},
139
154
{
140
- args : []string {"my-template " ,"--input " ,"my custom prompt " },
155
+ args : []string {"my custom prompt " ,"--template " ,"my-template " },
141
156
env : []string {"CODER_TASK_PRESET_NAME=my-preset" },
142
157
expectOutput :fmt .Sprintf ("The task %s has been created at %s!" ,cliui .Keyword ("task-wild-goldfish-27" ),cliui .Timestamp (taskCreatedAt )),
143
158
handler :func (t * testing.T ,ctx context.Context ) http.HandlerFunc {
144
159
return templateAndVersionFoundHandler (t ,ctx ,organizationID ,"my-template" ,"" ,"my-preset" ,"my custom prompt" )
145
160
},
146
161
},
147
162
{
148
- args : []string {"my-template " ,"--input " ,"my custom prompt " ,"--preset" ,"not-real-preset" },
163
+ args : []string {"my custom prompt " ,"--template " ,"my-template " ,"--preset" ,"not-real-preset" },
149
164
expectError :`preset "not-real-preset" not found` ,
150
165
handler :func (t * testing.T ,ctx context.Context ) http.HandlerFunc {
151
166
return templateAndVersionFoundHandler (t ,ctx ,organizationID ,"my-template" ,"" ,"my-preset" ,"my custom prompt" )
152
167
},
153
168
},
154
169
{
155
- args : []string {"my-template@not-real- template-version " ,"--input " ,"my custom prompt " },
170
+ args : []string {"my custom prompt" , "-- template" , "my-template " ,"--template-version " ,"not-real-template-version " },
156
171
expectError :httpapi .ResourceNotFoundResponse .Message ,
157
172
handler :func (t * testing.T ,ctx context.Context ) http.HandlerFunc {
158
173
return func (w http.ResponseWriter ,r * http.Request ) {
@@ -163,6 +178,11 @@ func TestTaskCreate(t *testing.T) {
163
178
ID :organizationID ,
164
179
}},
165
180
})
181
+ case fmt .Sprintf ("/api/v2/organizations/%s/templates/my-template" ,organizationID ):
182
+ httpapi .Write (ctx ,w ,http .StatusOK , codersdk.Template {
183
+ ID :templateID ,
184
+ ActiveVersionID :templateVersionID ,
185
+ })
166
186
case fmt .Sprintf ("/api/v2/organizations/%s/templates/my-template/versions/not-real-template-version" ,organizationID ):
167
187
httpapi .ResourceNotFound (w )
168
188
default :
@@ -172,7 +192,7 @@ func TestTaskCreate(t *testing.T) {
172
192
},
173
193
},
174
194
{
175
- args : []string {"not-real-template " ,"--input " ,"my custom prompt " ,"--org" ,organizationID .String ()},
195
+ args : []string {"my custom prompt " ,"--template " ,"not-real-template " ,"--org" ,organizationID .String ()},
176
196
expectError :httpapi .ResourceNotFoundResponse .Message ,
177
197
handler :func (t * testing.T ,ctx context.Context ) http.HandlerFunc {
178
198
return func (w http.ResponseWriter ,r * http.Request ) {
@@ -192,7 +212,7 @@ func TestTaskCreate(t *testing.T) {
192
212
},
193
213
},
194
214
{
195
- args : []string {"template-in-different-org " ,"--input " ,"my-custom-prompt " ,"--org" ,anotherOrganizationID .String ()},
215
+ args : []string {"my-custom-prompt " ,"--template " ,"template-in-different-org " ,"--org" ,anotherOrganizationID .String ()},
196
216
expectError :httpapi .ResourceNotFoundResponse .Message ,
197
217
handler :func (t * testing.T ,ctx context.Context ) http.HandlerFunc {
198
218
return func (w http.ResponseWriter ,r * http.Request ) {
@@ -212,7 +232,7 @@ func TestTaskCreate(t *testing.T) {
212
232
},
213
233
},
214
234
{
215
- args : []string {"no-org" , "--input" , "my-custom -prompt" },
235
+ args : []string {"no-org-prompt" },
216
236
expectError :"Must select an organization with --org=<org_name>" ,
217
237
handler :func (t * testing.T ,ctx context.Context ) http.HandlerFunc {
218
238
return func (w http.ResponseWriter ,r * http.Request ) {