- Notifications
You must be signed in to change notification settings - Fork1k
feat(cli): add ability to create tasks for other users#20012
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to ourterms of service andprivacy statement. We’ll occasionally send you account related emails.
Already on GitHub?Sign in to your account
Uh oh!
There was an error while loading.Please reload this page.
Changes fromall commits
File filter
Filter by extension
Conversations
Uh oh!
There was an error while loading.Please reload this page.
Jump to
Uh oh!
There was an error while loading.Please reload this page.
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -34,7 +34,7 @@ func TestTaskCreate(t *testing.T) { | ||
taskID = uuid.New() | ||
) | ||
templateAndVersionFoundHandler := func(t *testing.T, ctx context.Context, orgID uuid.UUID, templateName, templateVersionName, presetName, prompt, taskName, username string) http.HandlerFunc { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others.Learn more. This function definition is getting a little crazy 😄 There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others.Learn more. Yeah, might be time to do some nice fanciness here. Will push a separate PR. | ||
t.Helper() | ||
return func(w http.ResponseWriter, r *http.Request) { | ||
@@ -69,7 +69,7 @@ func TestTaskCreate(t *testing.T) { | ||
ActiveVersionID: templateVersionID, | ||
}, | ||
}) | ||
casefmt.Sprintf("/api/experimental/tasks/%s", username): | ||
var req codersdk.CreateTaskRequest | ||
if !httpapi.Read(ctx, w, r, &req) { | ||
return | ||
@@ -114,80 +114,87 @@ func TestTaskCreate(t *testing.T) { | ||
stdin: "reads prompt from stdin", | ||
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 { | ||
return templateAndVersionFoundHandler(t, ctx, organizationID, "my-template", "my-template-version", "", "reads prompt from stdin", "task-wild-goldfish-27", codersdk.Me) | ||
}, | ||
}, | ||
{ | ||
args: []string{"my custom prompt"}, | ||
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 { | ||
return templateAndVersionFoundHandler(t, ctx, organizationID, "my-template", "my-template-version", "", "my custom prompt", "task-wild-goldfish-27", codersdk.Me) | ||
}, | ||
}, | ||
{ | ||
args: []string{"my custom prompt", "--owner", "someone-else"}, | ||
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 { | ||
return templateAndVersionFoundHandler(t, ctx, organizationID, "my-template", "my-template-version", "", "my custom prompt", "task-wild-goldfish-27", "someone-else") | ||
}, | ||
}, | ||
{ | ||
args: []string{"--name", "abc123", "my custom prompt"}, | ||
expectOutput: fmt.Sprintf("The task %s has been created at %s!", cliui.Keyword("abc123"), cliui.Timestamp(taskCreatedAt)), | ||
handler: func(t *testing.T, ctx context.Context) http.HandlerFunc { | ||
return templateAndVersionFoundHandler(t, ctx, organizationID, "my-template", "my-template-version", "", "my custom prompt", "abc123", codersdk.Me) | ||
}, | ||
}, | ||
{ | ||
args: []string{"my custom prompt", "--template", "my-template", "--template-version", "my-template-version", "--org", organizationID.String()}, | ||
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 { | ||
return templateAndVersionFoundHandler(t, ctx, organizationID, "my-template", "my-template-version", "", "my custom prompt", "task-wild-goldfish-27", codersdk.Me) | ||
}, | ||
}, | ||
{ | ||
args: []string{"my custom prompt", "--template", "my-template", "--org", organizationID.String()}, | ||
env: []string{"CODER_TASK_TEMPLATE_VERSION=my-template-version"}, | ||
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 { | ||
return templateAndVersionFoundHandler(t, ctx, organizationID, "my-template", "my-template-version", "", "my custom prompt", "task-wild-goldfish-27", codersdk.Me) | ||
}, | ||
}, | ||
{ | ||
args: []string{"my custom prompt", "--org", organizationID.String()}, | ||
env: []string{"CODER_TASK_TEMPLATE_NAME=my-template", "CODER_TASK_TEMPLATE_VERSION=my-template-version"}, | ||
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 { | ||
return templateAndVersionFoundHandler(t, ctx, organizationID, "my-template", "my-template-version", "", "my custom prompt", "task-wild-goldfish-27", codersdk.Me) | ||
}, | ||
}, | ||
{ | ||
args: []string{"my custom prompt", "--template", "my-template", "--org", organizationID.String()}, | ||
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 { | ||
return templateAndVersionFoundHandler(t, ctx, organizationID, "my-template", "", "", "my custom prompt", "task-wild-goldfish-27", codersdk.Me) | ||
}, | ||
}, | ||
{ | ||
args: []string{"my custom prompt", "--template", "my-template", "--preset", "my-preset", "--org", organizationID.String()}, | ||
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 { | ||
return templateAndVersionFoundHandler(t, ctx, organizationID, "my-template", "", "my-preset", "my custom prompt", "task-wild-goldfish-27", codersdk.Me) | ||
}, | ||
}, | ||
{ | ||
args: []string{"my custom prompt", "--template", "my-template"}, | ||
env: []string{"CODER_TASK_PRESET_NAME=my-preset"}, | ||
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 { | ||
return templateAndVersionFoundHandler(t, ctx, organizationID, "my-template", "", "my-preset", "my custom prompt", "task-wild-goldfish-27", codersdk.Me) | ||
}, | ||
}, | ||
{ | ||
args: []string{"my custom prompt", "-q"}, | ||
expectOutput: taskID.String(), | ||
handler: func(t *testing.T, ctx context.Context) http.HandlerFunc { | ||
return templateAndVersionFoundHandler(t, ctx, organizationID, "my-template", "my-template-version", "", "my custom prompt", "task-wild-goldfish-27", codersdk.Me) | ||
}, | ||
}, | ||
{ | ||
args: []string{"my custom prompt", "--template", "my-template", "--preset", "not-real-preset"}, | ||
expectError: `preset "not-real-preset" not found`, | ||
handler: func(t *testing.T, ctx context.Context) http.HandlerFunc { | ||
return templateAndVersionFoundHandler(t, ctx, organizationID, "my-template", "", "my-preset", "my custom prompt", "task-wild-goldfish-27", codersdk.Me) | ||
}, | ||
}, | ||
{ | ||
Uh oh!
There was an error while loading.Please reload this page.