@@ -60,6 +60,14 @@ func TestTaskCreate(t *testing.T) {
6060Name :presetName ,
6161},
6262})
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+ })
6371case "/api/experimental/tasks/me" :
6472var req codersdk.CreateTaskRequest
6573if ! httpapi .Read (ctx ,w ,r ,& req ) {
@@ -93,22 +101,29 @@ func TestTaskCreate(t *testing.T) {
93101handler func (t * testing.T ,ctx context.Context ) http.HandlerFunc
94102}{
95103{
96- args : []string {"my-template@my-template-version" , "--input" , "my custom prompt", "--org" , organizationID . String () },
104+ args : []string {"my custom prompt" },
97105expectOutput :fmt .Sprintf ("The task %s has been created at %s!" ,cliui .Keyword ("task-wild-goldfish-27" ),cliui .Timestamp (taskCreatedAt )),
98106handler :func (t * testing.T ,ctx context.Context ) http.HandlerFunc {
99107return templateAndVersionFoundHandler (t ,ctx ,organizationID ,"my-template" ,"my-template-version" ,"" ,"my custom prompt" )
100108},
101109},
102110{
103- args : []string {"my-template" ,"--input" ,"my custom prompt" ,"--org" ,organizationID .String ()},
111+ args : []string {"my custom prompt" ,"--template" ,"my-template" ,"--template-version" ,"my-template-version" ,"--org" ,organizationID .String ()},
112+ expectOutput :fmt .Sprintf ("The task %s has been created at %s!" ,cliui .Keyword ("task-wild-goldfish-27" ),cliui .Timestamp (taskCreatedAt )),
113+ handler :func (t * testing.T ,ctx context.Context ) http.HandlerFunc {
114+ return templateAndVersionFoundHandler (t ,ctx ,organizationID ,"my-template" ,"my-template-version" ,"" ,"my custom prompt" )
115+ },
116+ },
117+ {
118+ args : []string {"my custom prompt" ,"--template" ,"my-template" ,"--org" ,organizationID .String ()},
104119env : []string {"CODER_TASK_TEMPLATE_VERSION=my-template-version" },
105120expectOutput :fmt .Sprintf ("The task %s has been created at %s!" ,cliui .Keyword ("task-wild-goldfish-27" ),cliui .Timestamp (taskCreatedAt )),
106121handler :func (t * testing.T ,ctx context.Context ) http.HandlerFunc {
107122return templateAndVersionFoundHandler (t ,ctx ,organizationID ,"my-template" ,"my-template-version" ,"" ,"my custom prompt" )
108123},
109124},
110125{
111- args : []string {"--input" , " my custom prompt" ,"--org" ,organizationID .String ()},
126+ args : []string {"my custom prompt" ,"--org" ,organizationID .String ()},
112127env : []string {"CODER_TASK_TEMPLATE_NAME=my-template" ,"CODER_TASK_TEMPLATE_VERSION=my-template-version" },
113128expectOutput :fmt .Sprintf ("The task %s has been created at %s!" ,cliui .Keyword ("task-wild-goldfish-27" ),cliui .Timestamp (taskCreatedAt )),
114129handler :func (t * testing.T ,ctx context.Context ) http.HandlerFunc {
@@ -123,36 +138,36 @@ func TestTaskCreate(t *testing.T) {
123138},
124139},
125140{
126- args : []string {"my-template " ,"--input " ,"my custom prompt " ,"--org" ,organizationID .String ()},
141+ args : []string {"my custom prompt " ,"--template " ,"my-template " ,"--org" ,organizationID .String ()},
127142expectOutput :fmt .Sprintf ("The task %s has been created at %s!" ,cliui .Keyword ("task-wild-goldfish-27" ),cliui .Timestamp (taskCreatedAt )),
128143handler :func (t * testing.T ,ctx context.Context ) http.HandlerFunc {
129144return templateAndVersionFoundHandler (t ,ctx ,organizationID ,"my-template" ,"" ,"" ,"my custom prompt" )
130145},
131146},
132147{
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 ()},
134149expectOutput :fmt .Sprintf ("The task %s has been created at %s!" ,cliui .Keyword ("task-wild-goldfish-27" ),cliui .Timestamp (taskCreatedAt )),
135150handler :func (t * testing.T ,ctx context.Context ) http.HandlerFunc {
136151return templateAndVersionFoundHandler (t ,ctx ,organizationID ,"my-template" ,"" ,"my-preset" ,"my custom prompt" )
137152},
138153},
139154{
140- args : []string {"my-template " ,"--input " ,"my custom prompt " },
155+ args : []string {"my custom prompt " ,"--template " ,"my-template " },
141156env : []string {"CODER_TASK_PRESET_NAME=my-preset" },
142157expectOutput :fmt .Sprintf ("The task %s has been created at %s!" ,cliui .Keyword ("task-wild-goldfish-27" ),cliui .Timestamp (taskCreatedAt )),
143158handler :func (t * testing.T ,ctx context.Context ) http.HandlerFunc {
144159return templateAndVersionFoundHandler (t ,ctx ,organizationID ,"my-template" ,"" ,"my-preset" ,"my custom prompt" )
145160},
146161},
147162{
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" },
149164expectError :`preset "not-real-preset" not found` ,
150165handler :func (t * testing.T ,ctx context.Context ) http.HandlerFunc {
151166return templateAndVersionFoundHandler (t ,ctx ,organizationID ,"my-template" ,"" ,"my-preset" ,"my custom prompt" )
152167},
153168},
154169{
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 " },
156171expectError :httpapi .ResourceNotFoundResponse .Message ,
157172handler :func (t * testing.T ,ctx context.Context ) http.HandlerFunc {
158173return func (w http.ResponseWriter ,r * http.Request ) {
@@ -163,6 +178,11 @@ func TestTaskCreate(t *testing.T) {
163178ID :organizationID ,
164179}},
165180})
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+ })
166186case fmt .Sprintf ("/api/v2/organizations/%s/templates/my-template/versions/not-real-template-version" ,organizationID ):
167187httpapi .ResourceNotFound (w )
168188default :
@@ -172,7 +192,7 @@ func TestTaskCreate(t *testing.T) {
172192},
173193},
174194{
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 ()},
176196expectError :httpapi .ResourceNotFoundResponse .Message ,
177197handler :func (t * testing.T ,ctx context.Context ) http.HandlerFunc {
178198return func (w http.ResponseWriter ,r * http.Request ) {
@@ -192,7 +212,7 @@ func TestTaskCreate(t *testing.T) {
192212},
193213},
194214{
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 ()},
196216expectError :httpapi .ResourceNotFoundResponse .Message ,
197217handler :func (t * testing.T ,ctx context.Context ) http.HandlerFunc {
198218return func (w http.ResponseWriter ,r * http.Request ) {
@@ -212,7 +232,7 @@ func TestTaskCreate(t *testing.T) {
212232},
213233},
214234{
215- args : []string {"no-org" , "--input" , "my-custom -prompt" },
235+ args : []string {"no-org-prompt" },
216236expectError :"Must select an organization with --org=<org_name>" ,
217237handler :func (t * testing.T ,ctx context.Context ) http.HandlerFunc {
218238return func (w http.ResponseWriter ,r * http.Request ) {
@@ -225,6 +245,26 @@ func TestTaskCreate(t *testing.T) {
225245}
226246},
227247},
248+ {
249+ args : []string {"no task templates" },
250+ expectError :"no task templates configured" ,
251+ handler :func (t * testing.T ,ctx context.Context ) http.HandlerFunc {
252+ return func (w http.ResponseWriter ,r * http.Request ) {
253+ switch r .URL .Path {
254+ case "/api/v2/users/me/organizations" :
255+ httpapi .Write (ctx ,w ,http .StatusOK , []codersdk.Organization {
256+ {MinimalOrganization : codersdk.MinimalOrganization {
257+ ID :organizationID ,
258+ }},
259+ })
260+ case "/api/v2/templates" :
261+ httpapi .Write (ctx ,w ,http .StatusOK , []codersdk.Template {})
262+ default :
263+ t .Errorf ("unexpected path: %s" ,r .URL .Path )
264+ }
265+ }
266+ },
267+ },
228268}
229269
230270for _ ,tt := range tests {