MCPcopy Index your code
hub / github.com/coder/coder / TestTaskCreate

Function TestTaskCreate

cli/task_create_test.go:23–356  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

21)
22
23func TestTaskCreate(t *testing.T) {
24 t.Parallel()
25
26 var (
27 taskCreatedAt = time.Now()
28
29 organizationID = uuid.New()
30 anotherOrganizationID = uuid.New()
31 templateID = uuid.New()
32 templateVersionID = uuid.New()
33 templateVersionPresetID = uuid.New()
34 taskID = uuid.New()
35 )
36
37 templateAndVersionFoundHandler := func(t *testing.T, ctx context.Context, orgID uuid.UUID, templateName, templateVersionName, presetName, prompt, taskName, username string) http.HandlerFunc {
38 t.Helper()
39
40 return func(w http.ResponseWriter, r *http.Request) {
41 switch r.URL.Path {
42 case "/api/v2/users/me/organizations":
43 httpapi.Write(ctx, w, http.StatusOK, []codersdk.Organization{
44 {MinimalOrganization: codersdk.MinimalOrganization{
45 ID: orgID,
46 }},
47 })
48 case fmt.Sprintf("/api/v2/organizations/%s/templates/%s/versions/%s", orgID, templateName, templateVersionName):
49 httpapi.Write(ctx, w, http.StatusOK, codersdk.TemplateVersion{
50 ID: templateVersionID,
51 })
52 case fmt.Sprintf("/api/v2/organizations/%s/templates/%s", orgID, templateName):
53 httpapi.Write(ctx, w, http.StatusOK, codersdk.Template{
54 ID: templateID,
55 ActiveVersionID: templateVersionID,
56 })
57 case fmt.Sprintf("/api/v2/templateversions/%s/presets", templateVersionID):
58 httpapi.Write(ctx, w, http.StatusOK, []codersdk.Preset{
59 {
60 ID: templateVersionPresetID,
61 Name: presetName,
62 },
63 })
64 case "/api/v2/templates":
65 httpapi.Write(ctx, w, http.StatusOK, []codersdk.Template{
66 {
67 ID: templateID,
68 Name: templateName,
69 ActiveVersionID: templateVersionID,
70 },
71 })
72 case fmt.Sprintf("/api/v2/tasks/%s", username):
73 var req codersdk.CreateTaskRequest
74 if !httpapi.Read(ctx, w, r, &req) {
75 return
76 }
77
78 assert.Equal(t, prompt, req.Input, "prompt mismatch")
79 assert.Equal(t, templateVersionID, req.TemplateVersionID, "template version mismatch")
80

Callers

nothing calls this directly

Calls 15

WriteFunction · 0.92
ReadFunction · 0.92
KeywordFunction · 0.92
TimestampFunction · 0.92
ResourceNotFoundFunction · 0.92
ContextFunction · 0.92
NewFunction · 0.92
MustURLFunction · 0.92
NewFunction · 0.92
SetupConfigFunction · 0.92
handlerMethod · 0.80
WithContextMethod · 0.80

Tested by

no test coverage detected