(t *testing.T)
| 17 | ) |
| 18 | |
| 19 | func TestGetCaches(t *testing.T) { |
| 20 | tests := []struct { |
| 21 | name string |
| 22 | opts GetCachesOptions |
| 23 | stubs func(*httpmock.Registry) |
| 24 | wantsCount int |
| 25 | }{ |
| 26 | { |
| 27 | name: "no caches", |
| 28 | opts: GetCachesOptions{}, |
| 29 | stubs: func(reg *httpmock.Registry) { |
| 30 | reg.Register( |
| 31 | httpmock.REST("GET", "repos/OWNER/REPO/actions/caches"), |
| 32 | httpmock.StringResponse(`{"actions_caches": [], "total_count": 0}`), |
| 33 | ) |
| 34 | }, |
| 35 | wantsCount: 0, |
| 36 | }, |
| 37 | { |
| 38 | name: "limits cache count", |
| 39 | opts: GetCachesOptions{Limit: 1}, |
| 40 | stubs: func(reg *httpmock.Registry) { |
| 41 | reg.Register( |
| 42 | httpmock.REST("GET", "repos/OWNER/REPO/actions/caches"), |
| 43 | httpmock.StringResponse(`{"actions_caches": [{"id": 1}, {"id": 2}], "total_count": 2}`), |
| 44 | ) |
| 45 | }, |
| 46 | wantsCount: 1, |
| 47 | }, |
| 48 | { |
| 49 | name: "negative limit returns all caches", |
| 50 | opts: GetCachesOptions{Limit: -1}, |
| 51 | stubs: func(reg *httpmock.Registry) { |
| 52 | reg.Register( |
| 53 | httpmock.REST("GET", "repos/OWNER/REPO/actions/caches"), |
| 54 | httpmock.StringResponse(`{"actions_caches": [{"id": 1}, {"id": 2}], "total_count": 2}`), |
| 55 | ) |
| 56 | }, |
| 57 | wantsCount: 2, |
| 58 | }, |
| 59 | } |
| 60 | |
| 61 | for _, tt := range tests { |
| 62 | t.Run(tt.name, func(t *testing.T) { |
| 63 | reg := &httpmock.Registry{} |
| 64 | tt.stubs(reg) |
| 65 | httpClient := &http.Client{Transport: reg} |
| 66 | client := api.NewClientFromHTTP(httpClient) |
| 67 | repo, err := ghrepo.FromFullName("OWNER/REPO") |
| 68 | assert.NoError(t, err) |
| 69 | result, err := GetCaches(client, repo, tt.opts) |
| 70 | assert.NoError(t, err) |
| 71 | assert.Equal(t, tt.wantsCount, len(result.ActionsCaches)) |
| 72 | }) |
| 73 | } |
| 74 | } |
| 75 | |
| 76 | func TestCache_ExportData(t *testing.T) { |
nothing calls this directly
no test coverage detected