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

Function TestExpTaskDelete

cli/task_delete_test.go:22–231  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

20)
21
22func TestExpTaskDelete(t *testing.T) {
23 t.Parallel()
24
25 type testCounters struct {
26 deleteCalls atomic.Int64
27 nameResolves atomic.Int64
28 }
29 type handlerBuilder func(c *testCounters) http.HandlerFunc
30
31 type testCase struct {
32 name string
33 args []string
34 promptYes bool
35 wantErr bool
36 wantDeleteCalls int64
37 wantNameResolves int64
38 wantDeletedMessage int
39 buildHandler handlerBuilder
40 }
41
42 const (
43 id1 = "11111111-1111-1111-1111-111111111111"
44 id2 = "22222222-2222-2222-2222-222222222222"
45 id3 = "33333333-3333-3333-3333-333333333333"
46 id4 = "44444444-4444-4444-4444-444444444444"
47 id5 = "55555555-5555-5555-5555-555555555555"
48 )
49
50 cases := []testCase{
51 {
52 name: "Prompted_ByName_OK",
53 args: []string{"exists"},
54 promptYes: true,
55 buildHandler: func(c *testCounters) http.HandlerFunc {
56 taskID := uuid.MustParse(id1)
57 return func(w http.ResponseWriter, r *http.Request) {
58 switch {
59 case r.Method == http.MethodGet && r.URL.Path == "/api/v2/tasks/me/exists":
60 c.nameResolves.Add(1)
61 httpapi.Write(r.Context(), w, http.StatusOK,
62 codersdk.Task{
63 ID: taskID,
64 Name: "exists",
65 OwnerName: "me",
66 })
67 case r.Method == http.MethodDelete && r.URL.Path == "/api/v2/tasks/me/"+id1:
68 c.deleteCalls.Add(1)
69 w.WriteHeader(http.StatusAccepted)
70 default:
71 httpapi.InternalServerError(w, xerrors.New("unwanted path: "+r.Method+" "+r.URL.Path))
72 }
73 }
74 },
75 wantDeleteCalls: 1,
76 wantNameResolves: 1,
77 },
78 {
79 name: "Prompted_ByUUID_OK",

Callers

nothing calls this directly

Calls 15

WriteFunction · 0.92
InternalServerErrorFunction · 0.92
ContextFunction · 0.92
NewFunction · 0.92
MustURLFunction · 0.92
NewFunction · 0.92
SetupConfigFunction · 0.92
NewFunction · 0.92
StartWithWaiterFunction · 0.92
WithContextMethod · 0.80
WriteLineMethod · 0.80
CountMethod · 0.80

Tested by

no test coverage detected