Repository: cli/cli
File: pkg/cmd/cache/delete/delete_test.go (Go)

Code before:
		{
			name: "no caches to delete when deleting all but succeed on no cache non-tty",
			opts: DeleteOptions{DeleteAll: true, SucceedOnNoCaches: true},
			stubs: func(reg *httpmock.Registry) {
				reg.Register(
					httpmock.REST("GET", "repos/OWNER/REPO/actions/caches"),
					httpmock.JSONResponse(shared.CachePayload{
						ActionsCaches: []shared.Cache{},
						TotalCount:    0,
					}),
				)
			},
			tty:        false,
			wantErr:    false,
			wantStdout: "",
		},
		{
			name: "deletes cache with ref tty",
			opts: DeleteOptions{Identifier: "cache-key", Ref: "refs/heads/main"},
			stubs: func(reg *httpmock.Registry) {
				reg.Register(
					httpmock.QueryMatcher("DELETE", "repos/OWNER/REPO/actions/caches", url.Values{
						"key": []string{"cache-key"},
						"ref": []string{"refs/heads/main"},
					}),
					httpmock.StatusStringResponse(204, ""),
				)
			},
			tty:        true,
			wantStdout: "✓ Deleted 1 cache from OWNER/REPO\n",
		},
		{
			name: "deletes cache with ref non-tty",
			opts: DeleteOptions{Identifier: "cache-key", Ref: "refs/heads/main"},
			stubs: func(reg *httpmock.Registry) {
				reg.Register(
					httpmock.QueryMatcher("DELETE", "repos/OWNER/REPO/actions/caches", url.Values{
						"key": []string{"cache-key"},
						"ref": []string{"refs/heads/main"},
					}),
					httpmock.StatusStringResponse(204, ""),
				)
			},
			tty:        false,
			wantStdout: "",
		},
		{
			name: "invalid ref value returns API error",
			opts: DeleteOptions{Identifier: "cache-key", Ref: "invalid-ref"},
			stubs: func(reg *httpmock.Registry) {
				reg.Register(

Review comment (suggestion):
While I was testing with the API, noticed it's actually an `HTTP 200`. I think this was a mistake from the past (or maybe API behaviour has changed).

Code after:
				)
			},
			tty:        true,
			wantErr:    false,
			wantStdout: "✓ No caches to delete\n",
		},
		{
			name: "no caches to delete when deleting all but succeed on no cache non-tty",
			opts: DeleteOptions{DeleteAll: true, SucceedOnNoCaches: true},
			stubs: func(reg *httpmock.Registry) {
				reg.Register(
					httpmock.REST("GET", "repos/OWNER/REPO/actions/caches"),
					httpmock.JSONResponse(shared.CachePayload{
						ActionsCaches: []shared.Cache{},
						TotalCount:    0,
					}),
				)
			},
			tty:        false,
			wantErr:    false,
			wantStdout: "",
		},
		{
			name: "deletes cache with ref tty",
			opts: DeleteOptions{Identifier: "cache-key", Ref: "refs/heads/main"},
			stubs: func(reg *httpmock.Registry) {
				reg.Register(
					httpmock.QueryMatcher("DELETE", "repos/OWNER/REPO/actions/caches", url.Values{
						"key": []string{"cache-key"},
						"ref": []string{"refs/heads/main"},
					}),
					// The response is a JSON object but we don't need it here.
					httpmock.StatusStringResponse(200, "{}"),
				)
			},
			tty:        true,
			wantStdout: "✓ Deleted 1 cache from OWNER/REPO\n",
		},
		{
			name: "deletes cache with ref non-tty",
			opts: DeleteOptions{Identifier: "cache-key", Ref: "refs/heads/main"},
			stubs: func(reg *httpmock.Registry) {
				reg.Register(
					httpmock.QueryMatcher("DELETE", "repos/OWNER/REPO/actions/caches", url.Values{
						"key": []string{"cache-key"},
						"ref": []string{"refs/heads/main"},
					}),
					// The response is a JSON object but we don't need it here.
					httpmock.StatusStringResponse(200, "{}"),
				)
			},