Add test cases for succeed on no cache and api errors for --all (#1)
This commit is contained in:
parent
9e13890c77
commit
2f0f387e11
1 changed files with 61 additions and 0 deletions
61
pkg/cmd/cache/delete/delete_test.go
vendored
61
pkg/cmd/cache/delete/delete_test.go
vendored
|
|
@ -176,6 +176,19 @@ func TestDeleteRun(t *testing.T) {
|
|||
tty: true,
|
||||
wantStdout: "✓ Deleted 2 caches from OWNER/REPO\n",
|
||||
},
|
||||
{
|
||||
name: "attempts to delete all caches but api errors",
|
||||
opts: DeleteOptions{DeleteAll: true},
|
||||
stubs: func(reg *httpmock.Registry) {
|
||||
reg.Register(
|
||||
httpmock.REST("GET", "repos/OWNER/REPO/actions/caches"),
|
||||
httpmock.StatusStringResponse(500, ""),
|
||||
)
|
||||
},
|
||||
tty: true,
|
||||
wantErr: true,
|
||||
wantErrMsg: "HTTP 500 (https://api.github.com/repos/OWNER/REPO/actions/caches?per_page=100)",
|
||||
},
|
||||
{
|
||||
name: "displays delete error",
|
||||
opts: DeleteOptions{Identifier: "123"},
|
||||
|
|
@ -202,6 +215,54 @@ func TestDeleteRun(t *testing.T) {
|
|||
tty: true,
|
||||
wantStdout: "✓ Deleted 1 cache from OWNER/REPO\n",
|
||||
},
|
||||
{
|
||||
name: "no caches to delete when deleting all",
|
||||
opts: DeleteOptions{Identifier: "123", DeleteAll: 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: true,
|
||||
wantErrMsg: "X No caches to delete",
|
||||
},
|
||||
{
|
||||
name: "no caches to delete when deleting all but succeed on no cache tty",
|
||||
opts: DeleteOptions{Identifier: "123", 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: 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{Identifier: "123", 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: "",
|
||||
},
|
||||
}
|
||||
|
||||
for _, tt := range tests {
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue