Files
go-github/github/actions_cache_test.go

1000 lines
31 KiB
Go

// Copyright 2022 The go-github AUTHORS. All rights reserved.
//
// Use of this source code is governed by a BSD-style
// license that can be found in the LICENSE file.
package github
import (
"fmt"
"net/http"
"testing"
"github.com/google/go-cmp/cmp"
)
func TestActionsService_ListCaches(t *testing.T) {
t.Parallel()
client, mux, _ := setup(t)
mux.HandleFunc("/repos/o/r/actions/caches", func(w http.ResponseWriter, r *http.Request) {
testMethod(t, r, "GET")
testFormValues(t, r, values{"page": "2"})
fmt.Fprint(w,
`{
"total_count":1,
"actions_caches":[{"id":1}]
}`,
)
})
opts := &ActionsCacheListOptions{ListOptions: ListOptions{Page: 2}}
ctx := t.Context()
cacheList, _, err := client.Actions.ListCaches(ctx, "o", "r", opts)
if err != nil {
t.Errorf("Actions.ListCaches returned error: %v", err)
}
want := &ActionsCacheList{TotalCount: 1, ActionsCaches: []*ActionsCache{{ID: new(int64(1))}}}
if !cmp.Equal(cacheList, want) {
t.Errorf("Actions.ListCaches returned %+v, want %+v", cacheList, want)
}
const methodName = "ListCaches"
testBadOptions(t, methodName, func() (err error) {
_, _, err = client.Actions.ListCaches(ctx, "\n", "\n", opts)
return err
})
testNewRequestAndDoFailure(t, methodName, client, func() (*Response, error) {
got, resp, err := client.Actions.ListCaches(ctx, "o", "r", opts)
if got != nil {
t.Errorf("testNewRequestAndDoFailure %v = %#v, want nil", methodName, got)
}
return resp, err
})
}
func TestActionsService_ListCaches_invalidOwner(t *testing.T) {
t.Parallel()
client, _, _ := setup(t)
ctx := t.Context()
_, _, err := client.Actions.ListCaches(ctx, "%", "r", nil)
testURLParseError(t, err)
}
func TestActionsService_ListCaches_invalidRepo(t *testing.T) {
t.Parallel()
client, _, _ := setup(t)
ctx := t.Context()
_, _, err := client.Actions.ListCaches(ctx, "o", "%", nil)
testURLParseError(t, err)
}
func TestActionsService_ListCaches_notFound(t *testing.T) {
t.Parallel()
client, mux, _ := setup(t)
mux.HandleFunc("/repos/o/r/actions/caches", func(w http.ResponseWriter, r *http.Request) {
testMethod(t, r, "GET")
w.WriteHeader(http.StatusNotFound)
})
ctx := t.Context()
caches, resp, err := client.Actions.ListCaches(ctx, "o", "r", nil)
if err == nil {
t.Error("Expected HTTP 404 response")
}
if got, want := resp.Response.StatusCode, http.StatusNotFound; got != want {
t.Errorf("Actions.ListCaches return status %v, want %v", got, want)
}
if caches != nil {
t.Errorf("Actions.ListCaches return %+v, want nil", caches)
}
}
func TestActionsService_DeleteCachesByKey(t *testing.T) {
t.Parallel()
client, mux, _ := setup(t)
mux.HandleFunc("/repos/o/r/actions/caches", func(_ http.ResponseWriter, r *http.Request) {
testMethod(t, r, "DELETE")
testFormValues(t, r, values{"key": "1", "ref": "main"})
})
ctx := t.Context()
_, err := client.Actions.DeleteCachesByKey(ctx, "o", "r", "1", new("main"))
if err != nil {
t.Errorf("Actions.DeleteCachesByKey return error: %v", err)
}
const methodName = "DeleteCachesByKey"
testBadOptions(t, methodName, func() (err error) {
_, err = client.Actions.DeleteCachesByKey(ctx, "\n", "\n", "\n", new("\n"))
return err
})
testNewRequestAndDoFailure(t, methodName, client, func() (*Response, error) {
return client.Actions.DeleteCachesByKey(ctx, "o", "r", "1", new("main"))
})
}
func TestActionsService_DeleteCachesByKey_invalidOwner(t *testing.T) {
t.Parallel()
client, _, _ := setup(t)
ctx := t.Context()
_, err := client.Actions.DeleteCachesByKey(ctx, "%", "r", "1", new("main"))
testURLParseError(t, err)
}
func TestActionsService_DeleteCachesByKey_invalidRepo(t *testing.T) {
t.Parallel()
client, _, _ := setup(t)
ctx := t.Context()
_, err := client.Actions.DeleteCachesByKey(ctx, "o", "%", "1", new("main"))
testURLParseError(t, err)
}
func TestActionsService_DeleteCachesByKey_notFound(t *testing.T) {
t.Parallel()
client, mux, _ := setup(t)
mux.HandleFunc("/repos/o/r/actions/artifacts/1", func(w http.ResponseWriter, r *http.Request) {
testMethod(t, r, "DELETE")
w.WriteHeader(http.StatusNotFound)
})
ctx := t.Context()
resp, err := client.Actions.DeleteCachesByKey(ctx, "o", "r", "1", new("main"))
if err == nil {
t.Error("Expected HTTP 404 response")
}
if got, want := resp.Response.StatusCode, http.StatusNotFound; got != want {
t.Errorf("Actions.DeleteCachesByKey return status %v, want %v", got, want)
}
}
func TestActionsService_DeleteCachesByID(t *testing.T) {
t.Parallel()
client, mux, _ := setup(t)
mux.HandleFunc("/repos/o/r/actions/caches/1", func(_ http.ResponseWriter, r *http.Request) {
testMethod(t, r, "DELETE")
})
ctx := t.Context()
_, err := client.Actions.DeleteCachesByID(ctx, "o", "r", 1)
if err != nil {
t.Errorf("Actions.DeleteCachesByID return error: %v", err)
}
const methodName = "DeleteCachesByID"
testBadOptions(t, methodName, func() (err error) {
_, err = client.Actions.DeleteCachesByID(ctx, "\n", "\n", 0)
return err
})
testNewRequestAndDoFailure(t, methodName, client, func() (*Response, error) {
return client.Actions.DeleteCachesByID(ctx, "o", "r", 1)
})
}
func TestActionsService_DeleteCachesByID_invalidOwner(t *testing.T) {
t.Parallel()
client, _, _ := setup(t)
ctx := t.Context()
_, err := client.Actions.DeleteCachesByID(ctx, "%", "r", 1)
testURLParseError(t, err)
}
func TestActionsService_DeleteCachesByID_invalidRepo(t *testing.T) {
t.Parallel()
client, _, _ := setup(t)
ctx := t.Context()
_, err := client.Actions.DeleteCachesByID(ctx, "o", "%", 1)
testURLParseError(t, err)
}
func TestActionsService_DeleteCachesByID_notFound(t *testing.T) {
t.Parallel()
client, mux, _ := setup(t)
mux.HandleFunc("repos/o/r/actions/caches/1", func(w http.ResponseWriter, r *http.Request) {
testMethod(t, r, "DELETE")
w.WriteHeader(http.StatusNotFound)
})
ctx := t.Context()
resp, err := client.Actions.DeleteCachesByID(ctx, "o", "r", 1)
if err == nil {
t.Error("Expected HTTP 404 response")
}
if got, want := resp.Response.StatusCode, http.StatusNotFound; got != want {
t.Errorf("Actions.DeleteCachesByID return status %v, want %v", got, want)
}
}
func TestActionsService_GetCacheUsageForRepo(t *testing.T) {
t.Parallel()
client, mux, _ := setup(t)
mux.HandleFunc("/repos/o/r/actions/cache/usage", func(w http.ResponseWriter, r *http.Request) {
testMethod(t, r, "GET")
fmt.Fprint(w,
`{
"full_name":"test-cache",
"active_caches_size_in_bytes":1000,
"active_caches_count":1
}`,
)
})
ctx := t.Context()
cacheUse, _, err := client.Actions.GetCacheUsageForRepo(ctx, "o", "r")
if err != nil {
t.Errorf("Actions.GetCacheUsageForRepo returned error: %v", err)
}
want := &ActionsCacheUsage{FullName: "test-cache", ActiveCachesSizeInBytes: 1000, ActiveCachesCount: 1}
if !cmp.Equal(cacheUse, want) {
t.Errorf("Actions.GetCacheUsageForRepo returned %+v, want %+v", cacheUse, want)
}
const methodName = "GetCacheUsageForRepo"
testBadOptions(t, methodName, func() (err error) {
_, _, err = client.Actions.GetCacheUsageForRepo(ctx, "\n", "\n")
return err
})
testNewRequestAndDoFailure(t, methodName, client, func() (*Response, error) {
got, resp, err := client.Actions.GetCacheUsageForRepo(ctx, "o", "r")
if got != nil {
t.Errorf("testNewRequestAndDoFailure %v = %#v, want nil", methodName, got)
}
return resp, err
})
}
func TestActionsService_GetCacheUsageForRepo_invalidOwner(t *testing.T) {
t.Parallel()
client, _, _ := setup(t)
ctx := t.Context()
_, _, err := client.Actions.GetCacheUsageForRepo(ctx, "%", "r")
testURLParseError(t, err)
}
func TestActionsService_GetCacheUsageForRepo_invalidRepo(t *testing.T) {
t.Parallel()
client, _, _ := setup(t)
ctx := t.Context()
_, _, err := client.Actions.GetCacheUsageForRepo(ctx, "o", "%")
testURLParseError(t, err)
}
func TestActionsService_GetCacheUsageForRepo_notFound(t *testing.T) {
t.Parallel()
client, mux, _ := setup(t)
mux.HandleFunc("/repos/o/r/actions/cache/usage", func(w http.ResponseWriter, r *http.Request) {
testMethod(t, r, "GET")
w.WriteHeader(http.StatusNotFound)
})
ctx := t.Context()
caches, resp, err := client.Actions.GetCacheUsageForRepo(ctx, "o", "r")
if err == nil {
t.Error("Expected HTTP 404 response")
}
if got, want := resp.Response.StatusCode, http.StatusNotFound; got != want {
t.Errorf("Actions.GetCacheUsageForRepo return status %v, want %v", got, want)
}
if caches != nil {
t.Errorf("Actions.GetCacheUsageForRepo return %+v, want nil", caches)
}
}
func TestActionsService_ListCacheUsageByRepoForOrg(t *testing.T) {
t.Parallel()
client, mux, _ := setup(t)
mux.HandleFunc("/orgs/o/actions/cache/usage-by-repository", func(w http.ResponseWriter, r *http.Request) {
testMethod(t, r, "GET")
testFormValues(t, r, values{"page": "2", "per_page": "1"})
fmt.Fprint(w,
`{
"total_count":1,
"repository_cache_usages":[{"full_name":"test-cache","active_caches_size_in_bytes":1000,"active_caches_count":1}]
}`,
)
})
opts := &ListOptions{PerPage: 1, Page: 2}
ctx := t.Context()
cacheList, _, err := client.Actions.ListCacheUsageByRepoForOrg(ctx, "o", opts)
if err != nil {
t.Errorf("Actions.ListCacheUsageByRepoForOrg returned error: %v", err)
}
want := &ActionsCacheUsageList{TotalCount: 1, RepoCacheUsage: []*ActionsCacheUsage{{FullName: "test-cache", ActiveCachesSizeInBytes: 1000, ActiveCachesCount: 1}}}
if !cmp.Equal(cacheList, want) {
t.Errorf("Actions.ListCacheUsageByRepoForOrg returned %+v, want %+v", cacheList, want)
}
const methodName = "ListCacheUsageByRepoForOrg"
testBadOptions(t, methodName, func() (err error) {
_, _, err = client.Actions.ListCacheUsageByRepoForOrg(ctx, "\n", opts)
return err
})
testNewRequestAndDoFailure(t, methodName, client, func() (*Response, error) {
got, resp, err := client.Actions.ListCacheUsageByRepoForOrg(ctx, "o", opts)
if got != nil {
t.Errorf("testNewRequestAndDoFailure %v = %#v, want nil", methodName, got)
}
return resp, err
})
}
func TestActionsService_ListCacheUsageByRepoForOrg_invalidOrganization(t *testing.T) {
t.Parallel()
client, _, _ := setup(t)
ctx := t.Context()
_, _, err := client.Actions.ListCacheUsageByRepoForOrg(ctx, "%", nil)
testURLParseError(t, err)
}
func TestActionsService_ListCacheUsageByRepoForOrg_notFound(t *testing.T) {
t.Parallel()
client, mux, _ := setup(t)
mux.HandleFunc("/orgs/o/actions/cache/usage-by-repository", func(w http.ResponseWriter, r *http.Request) {
testMethod(t, r, "GET")
w.WriteHeader(http.StatusNotFound)
})
ctx := t.Context()
caches, resp, err := client.Actions.ListCacheUsageByRepoForOrg(ctx, "o", nil)
if err == nil {
t.Error("Expected HTTP 404 response")
}
if got, want := resp.Response.StatusCode, http.StatusNotFound; got != want {
t.Errorf("Actions.ListCacheUsageByRepoForOrg return status %v, want %v", got, want)
}
if caches != nil {
t.Errorf("Actions.ListCacheUsageByRepoForOrg return %+v, want nil", caches)
}
}
func TestActionsService_GetCacheUsageForOrg(t *testing.T) {
t.Parallel()
client, mux, _ := setup(t)
mux.HandleFunc("/orgs/o/actions/cache/usage", func(w http.ResponseWriter, r *http.Request) {
testMethod(t, r, "GET")
fmt.Fprint(w,
`{
"total_active_caches_size_in_bytes":1000,
"total_active_caches_count":1
}`,
)
})
ctx := t.Context()
cache, _, err := client.Actions.GetTotalCacheUsageForOrg(ctx, "o")
if err != nil {
t.Errorf("Actions.GetTotalCacheUsageForOrg returned error: %v", err)
}
want := &TotalCacheUsage{TotalActiveCachesUsageSizeInBytes: 1000, TotalActiveCachesCount: 1}
if !cmp.Equal(cache, want) {
t.Errorf("Actions.GetTotalCacheUsageForOrg returned %+v, want %+v", cache, want)
}
const methodName = "GetTotalCacheUsageForOrg"
testBadOptions(t, methodName, func() (err error) {
_, _, err = client.Actions.GetTotalCacheUsageForOrg(ctx, "\n")
return err
})
testNewRequestAndDoFailure(t, methodName, client, func() (*Response, error) {
got, resp, err := client.Actions.GetTotalCacheUsageForOrg(ctx, "o")
if got != nil {
t.Errorf("testNewRequestAndDoFailure %v = %#v, want nil", methodName, got)
}
return resp, err
})
}
func TestActionsService_GetCacheUsageForOrg_invalidOrganization(t *testing.T) {
t.Parallel()
client, _, _ := setup(t)
ctx := t.Context()
_, _, err := client.Actions.GetTotalCacheUsageForOrg(ctx, "%")
testURLParseError(t, err)
}
func TestActionsService_GetCacheUsageForOrg_notFound(t *testing.T) {
t.Parallel()
client, mux, _ := setup(t)
mux.HandleFunc("/orgs/o/actions/cache/usage", func(w http.ResponseWriter, r *http.Request) {
testMethod(t, r, "GET")
w.WriteHeader(http.StatusNotFound)
})
ctx := t.Context()
caches, resp, err := client.Actions.GetTotalCacheUsageForOrg(ctx, "o")
if err == nil {
t.Error("Expected HTTP 404 response")
}
if got, want := resp.Response.StatusCode, http.StatusNotFound; got != want {
t.Errorf("Actions.GetTotalCacheUsageForOrg return status %v, want %v", got, want)
}
if caches != nil {
t.Errorf("Actions.GetTotalCacheUsageForOrg return %+v, want nil", caches)
}
}
func TestActionsService_GetCacheUsageForEnterprise(t *testing.T) {
t.Parallel()
client, mux, _ := setup(t)
mux.HandleFunc("/enterprises/e/actions/cache/usage", func(w http.ResponseWriter, r *http.Request) {
testMethod(t, r, "GET")
fmt.Fprint(w,
`{
"total_active_caches_size_in_bytes":1000,
"total_active_caches_count":1
}`,
)
})
ctx := t.Context()
cache, _, err := client.Actions.GetTotalCacheUsageForEnterprise(ctx, "e")
if err != nil {
t.Errorf("Actions.GetTotalCacheUsageForEnterprise returned error: %v", err)
}
want := &TotalCacheUsage{TotalActiveCachesUsageSizeInBytes: 1000, TotalActiveCachesCount: 1}
if !cmp.Equal(cache, want) {
t.Errorf("Actions.GetTotalCacheUsageForEnterprise returned %+v, want %+v", cache, want)
}
const methodName = "GetTotalCacheUsageForEnterprise"
testBadOptions(t, methodName, func() (err error) {
_, _, err = client.Actions.GetTotalCacheUsageForEnterprise(ctx, "\n")
return err
})
testNewRequestAndDoFailure(t, methodName, client, func() (*Response, error) {
got, resp, err := client.Actions.GetTotalCacheUsageForEnterprise(ctx, "e")
if got != nil {
t.Errorf("testNewRequestAndDoFailure %v = %#v, want nil", methodName, got)
}
return resp, err
})
}
func TestActionsService_GetCacheUsageForEnterprise_invalidEnterprise(t *testing.T) {
t.Parallel()
client, _, _ := setup(t)
ctx := t.Context()
_, _, err := client.Actions.GetTotalCacheUsageForEnterprise(ctx, "%")
testURLParseError(t, err)
}
func TestActionsService_GetCacheUsageForEnterprise_notFound(t *testing.T) {
t.Parallel()
client, mux, _ := setup(t)
mux.HandleFunc("/enterprises/e/actions/cache/usage", func(w http.ResponseWriter, r *http.Request) {
testMethod(t, r, "GET")
w.WriteHeader(http.StatusNotFound)
})
ctx := t.Context()
caches, resp, err := client.Actions.GetTotalCacheUsageForEnterprise(ctx, "o")
if err == nil {
t.Error("Expected HTTP 404 response")
}
if got, want := resp.Response.StatusCode, http.StatusNotFound; got != want {
t.Errorf("Actions.GetTotalCacheUsageForEnterprise return status %v, want %v", got, want)
}
if caches != nil {
t.Errorf("Actions.GetTotalCacheUsageForEnterprise return %+v, want nil", caches)
}
}
func TestActionsService_GetCacheRetentionLimitForOrg(t *testing.T) {
t.Parallel()
client, mux, _ := setup(t)
mux.HandleFunc("/organizations/o/actions/cache/retention-limit", func(w http.ResponseWriter, r *http.Request) {
testMethod(t, r, "GET")
fmt.Fprint(w, `{"max_cache_retention_days":14}`)
})
ctx := t.Context()
limit, _, err := client.Actions.GetCacheRetentionLimitForOrg(ctx, "o")
if err != nil {
t.Errorf("Actions.GetCacheRetentionLimitForOrg returned error: %v", err)
}
want := &ActionsCacheRetentionLimit{MaxCacheRetentionDays: new(14)}
if !cmp.Equal(limit, want) {
t.Errorf("Actions.GetCacheRetentionLimitForOrg returned %+v, want %+v", limit, want)
}
const methodName = "GetCacheRetentionLimitForOrg"
testBadOptions(t, methodName, func() (err error) {
_, _, err = client.Actions.GetCacheRetentionLimitForOrg(ctx, "\n")
return err
})
testNewRequestAndDoFailure(t, methodName, client, func() (*Response, error) {
got, resp, err := client.Actions.GetCacheRetentionLimitForOrg(ctx, "o")
if got != nil {
t.Errorf("testNewRequestAndDoFailure %v = %#v, want nil", methodName, got)
}
return resp, err
})
}
func TestActionsService_GetCacheRetentionLimitForOrg_invalidOrganization(t *testing.T) {
t.Parallel()
client, _, _ := setup(t)
ctx := t.Context()
_, _, err := client.Actions.GetCacheRetentionLimitForOrg(ctx, "%")
testURLParseError(t, err)
}
func TestActionsService_GetCacheRetentionLimitForOrg_notFound(t *testing.T) {
t.Parallel()
client, mux, _ := setup(t)
mux.HandleFunc("/organizations/o/actions/cache/retention-limit", func(w http.ResponseWriter, r *http.Request) {
testMethod(t, r, "GET")
w.WriteHeader(http.StatusNotFound)
})
ctx := t.Context()
limit, resp, err := client.Actions.GetCacheRetentionLimitForOrg(ctx, "o")
if err == nil {
t.Error("Expected HTTP 404 response")
}
if got, want := resp.Response.StatusCode, http.StatusNotFound; got != want {
t.Errorf("Actions.GetCacheRetentionLimitForOrg return status %v, want %v", got, want)
}
if limit != nil {
t.Errorf("Actions.GetCacheRetentionLimitForOrg return %+v, want nil", limit)
}
}
func TestActionsService_SetCacheRetentionLimitForOrg(t *testing.T) {
t.Parallel()
client, mux, _ := setup(t)
input := ActionsCacheRetentionLimit{MaxCacheRetentionDays: new(14)}
mux.HandleFunc("/organizations/o/actions/cache/retention-limit", func(w http.ResponseWriter, r *http.Request) {
testMethod(t, r, "PUT")
testJSONBody(t, r, input)
w.WriteHeader(http.StatusNoContent)
})
ctx := t.Context()
resp, err := client.Actions.SetCacheRetentionLimitForOrg(ctx, "o", input)
if err != nil {
t.Errorf("Actions.SetCacheRetentionLimitForOrg returned error: %v", err)
}
if got, want := resp.StatusCode, http.StatusNoContent; got != want {
t.Errorf("Actions.SetCacheRetentionLimitForOrg return status %v, want %v", got, want)
}
const methodName = "SetCacheRetentionLimitForOrg"
testBadOptions(t, methodName, func() (err error) {
_, err = client.Actions.SetCacheRetentionLimitForOrg(ctx, "\n", input)
return err
})
testNewRequestAndDoFailure(t, methodName, client, func() (*Response, error) {
return client.Actions.SetCacheRetentionLimitForOrg(ctx, "o", input)
})
}
func TestActionsService_SetCacheRetentionLimitForOrg_invalidOrganization(t *testing.T) {
t.Parallel()
client, _, _ := setup(t)
ctx := t.Context()
_, err := client.Actions.SetCacheRetentionLimitForOrg(ctx, "%", ActionsCacheRetentionLimit{})
testURLParseError(t, err)
}
func TestActionsService_GetCacheStorageLimitForOrg(t *testing.T) {
t.Parallel()
client, mux, _ := setup(t)
mux.HandleFunc("/organizations/o/actions/cache/storage-limit", func(w http.ResponseWriter, r *http.Request) {
testMethod(t, r, "GET")
fmt.Fprint(w, `{"max_cache_size_gb":10}`)
})
ctx := t.Context()
limit, _, err := client.Actions.GetCacheStorageLimitForOrg(ctx, "o")
if err != nil {
t.Errorf("Actions.GetCacheStorageLimitForOrg returned error: %v", err)
}
want := &ActionsCacheStorageLimit{MaxCacheSizeGB: new(10)}
if !cmp.Equal(limit, want) {
t.Errorf("Actions.GetCacheStorageLimitForOrg returned %+v, want %+v", limit, want)
}
const methodName = "GetCacheStorageLimitForOrg"
testBadOptions(t, methodName, func() (err error) {
_, _, err = client.Actions.GetCacheStorageLimitForOrg(ctx, "\n")
return err
})
testNewRequestAndDoFailure(t, methodName, client, func() (*Response, error) {
got, resp, err := client.Actions.GetCacheStorageLimitForOrg(ctx, "o")
if got != nil {
t.Errorf("testNewRequestAndDoFailure %v = %#v, want nil", methodName, got)
}
return resp, err
})
}
func TestActionsService_GetCacheStorageLimitForOrg_invalidOrganization(t *testing.T) {
t.Parallel()
client, _, _ := setup(t)
ctx := t.Context()
_, _, err := client.Actions.GetCacheStorageLimitForOrg(ctx, "%")
testURLParseError(t, err)
}
func TestActionsService_GetCacheStorageLimitForOrg_notFound(t *testing.T) {
t.Parallel()
client, mux, _ := setup(t)
mux.HandleFunc("/organizations/o/actions/cache/storage-limit", func(w http.ResponseWriter, r *http.Request) {
testMethod(t, r, "GET")
w.WriteHeader(http.StatusNotFound)
})
ctx := t.Context()
limit, resp, err := client.Actions.GetCacheStorageLimitForOrg(ctx, "o")
if err == nil {
t.Error("Expected HTTP 404 response")
}
if got, want := resp.Response.StatusCode, http.StatusNotFound; got != want {
t.Errorf("Actions.GetCacheStorageLimitForOrg return status %v, want %v", got, want)
}
if limit != nil {
t.Errorf("Actions.GetCacheStorageLimitForOrg return %+v, want nil", limit)
}
}
func TestActionsService_SetCacheStorageLimitForOrg(t *testing.T) {
t.Parallel()
client, mux, _ := setup(t)
input := ActionsCacheStorageLimit{MaxCacheSizeGB: new(10)}
mux.HandleFunc("/organizations/o/actions/cache/storage-limit", func(w http.ResponseWriter, r *http.Request) {
testMethod(t, r, "PUT")
testJSONBody(t, r, input)
w.WriteHeader(http.StatusNoContent)
})
ctx := t.Context()
resp, err := client.Actions.SetCacheStorageLimitForOrg(ctx, "o", input)
if err != nil {
t.Errorf("Actions.SetCacheStorageLimitForOrg returned error: %v", err)
}
if got, want := resp.StatusCode, http.StatusNoContent; got != want {
t.Errorf("Actions.SetCacheStorageLimitForOrg return status %v, want %v", got, want)
}
const methodName = "SetCacheStorageLimitForOrg"
testBadOptions(t, methodName, func() (err error) {
_, err = client.Actions.SetCacheStorageLimitForOrg(ctx, "\n", input)
return err
})
testNewRequestAndDoFailure(t, methodName, client, func() (*Response, error) {
return client.Actions.SetCacheStorageLimitForOrg(ctx, "o", input)
})
}
func TestActionsService_SetCacheStorageLimitForOrg_invalidOrganization(t *testing.T) {
t.Parallel()
client, _, _ := setup(t)
ctx := t.Context()
_, err := client.Actions.SetCacheStorageLimitForOrg(ctx, "%", ActionsCacheStorageLimit{})
testURLParseError(t, err)
}
func TestActionsService_GetCacheRetentionLimitForRepo(t *testing.T) {
t.Parallel()
client, mux, _ := setup(t)
mux.HandleFunc("/repos/o/r/actions/cache/retention-limit", func(w http.ResponseWriter, r *http.Request) {
testMethod(t, r, "GET")
fmt.Fprint(w, `{"max_cache_retention_days":14}`)
})
ctx := t.Context()
limit, _, err := client.Actions.GetCacheRetentionLimitForRepo(ctx, "o", "r")
if err != nil {
t.Errorf("Actions.GetCacheRetentionLimitForRepo returned error: %v", err)
}
want := &ActionsCacheRetentionLimit{MaxCacheRetentionDays: new(14)}
if !cmp.Equal(limit, want) {
t.Errorf("Actions.GetCacheRetentionLimitForRepo returned %+v, want %+v", limit, want)
}
const methodName = "GetCacheRetentionLimitForRepo"
testBadOptions(t, methodName, func() (err error) {
_, _, err = client.Actions.GetCacheRetentionLimitForRepo(ctx, "\n", "\n")
return err
})
testNewRequestAndDoFailure(t, methodName, client, func() (*Response, error) {
got, resp, err := client.Actions.GetCacheRetentionLimitForRepo(ctx, "o", "r")
if got != nil {
t.Errorf("testNewRequestAndDoFailure %v = %#v, want nil", methodName, got)
}
return resp, err
})
}
func TestActionsService_SetCacheRetentionLimitForRepo(t *testing.T) {
t.Parallel()
client, mux, _ := setup(t)
input := ActionsCacheRetentionLimit{MaxCacheRetentionDays: new(14)}
mux.HandleFunc("/repos/o/r/actions/cache/retention-limit", func(w http.ResponseWriter, r *http.Request) {
testMethod(t, r, "PUT")
testJSONBody(t, r, input)
w.WriteHeader(http.StatusNoContent)
})
ctx := t.Context()
resp, err := client.Actions.SetCacheRetentionLimitForRepo(ctx, "o", "r", input)
if err != nil {
t.Errorf("Actions.SetCacheRetentionLimitForRepo returned error: %v", err)
}
if got, want := resp.StatusCode, http.StatusNoContent; got != want {
t.Errorf("Actions.SetCacheRetentionLimitForRepo return status %v, want %v", got, want)
}
const methodName = "SetCacheRetentionLimitForRepo"
testBadOptions(t, methodName, func() (err error) {
_, err = client.Actions.SetCacheRetentionLimitForRepo(ctx, "\n", "\n", input)
return err
})
testNewRequestAndDoFailure(t, methodName, client, func() (*Response, error) {
return client.Actions.SetCacheRetentionLimitForRepo(ctx, "o", "r", input)
})
}
func TestActionsService_GetCacheStorageLimitForRepo(t *testing.T) {
t.Parallel()
client, mux, _ := setup(t)
mux.HandleFunc("/repos/o/r/actions/cache/storage-limit", func(w http.ResponseWriter, r *http.Request) {
testMethod(t, r, "GET")
fmt.Fprint(w, `{"max_cache_size_gb":10}`)
})
ctx := t.Context()
limit, _, err := client.Actions.GetCacheStorageLimitForRepo(ctx, "o", "r")
if err != nil {
t.Errorf("Actions.GetCacheStorageLimitForRepo returned error: %v", err)
}
want := &ActionsCacheStorageLimit{MaxCacheSizeGB: new(10)}
if !cmp.Equal(limit, want) {
t.Errorf("Actions.GetCacheStorageLimitForRepo returned %+v, want %+v", limit, want)
}
const methodName = "GetCacheStorageLimitForRepo"
testBadOptions(t, methodName, func() (err error) {
_, _, err = client.Actions.GetCacheStorageLimitForRepo(ctx, "\n", "\n")
return err
})
testNewRequestAndDoFailure(t, methodName, client, func() (*Response, error) {
got, resp, err := client.Actions.GetCacheStorageLimitForRepo(ctx, "o", "r")
if got != nil {
t.Errorf("testNewRequestAndDoFailure %v = %#v, want nil", methodName, got)
}
return resp, err
})
}
func TestActionsService_SetCacheStorageLimitForRepo(t *testing.T) {
t.Parallel()
client, mux, _ := setup(t)
input := ActionsCacheStorageLimit{MaxCacheSizeGB: new(10)}
mux.HandleFunc("/repos/o/r/actions/cache/storage-limit", func(w http.ResponseWriter, r *http.Request) {
testMethod(t, r, "PUT")
testJSONBody(t, r, input)
w.WriteHeader(http.StatusNoContent)
})
ctx := t.Context()
resp, err := client.Actions.SetCacheStorageLimitForRepo(ctx, "o", "r", input)
if err != nil {
t.Errorf("Actions.SetCacheStorageLimitForRepo returned error: %v", err)
}
if got, want := resp.StatusCode, http.StatusNoContent; got != want {
t.Errorf("Actions.SetCacheStorageLimitForRepo return status %v, want %v", got, want)
}
const methodName = "SetCacheStorageLimitForRepo"
testBadOptions(t, methodName, func() (err error) {
_, err = client.Actions.SetCacheStorageLimitForRepo(ctx, "\n", "\n", input)
return err
})
testNewRequestAndDoFailure(t, methodName, client, func() (*Response, error) {
return client.Actions.SetCacheStorageLimitForRepo(ctx, "o", "r", input)
})
}
func TestActionsService_GetCacheRetentionLimitForEnterprise(t *testing.T) {
t.Parallel()
client, mux, _ := setup(t)
mux.HandleFunc("/enterprises/e/actions/cache/retention-limit", func(w http.ResponseWriter, r *http.Request) {
testMethod(t, r, "GET")
fmt.Fprint(w, `{"max_cache_retention_days":14}`)
})
ctx := t.Context()
limit, _, err := client.Actions.GetCacheRetentionLimitForEnterprise(ctx, "e")
if err != nil {
t.Errorf("Actions.GetCacheRetentionLimitForEnterprise returned error: %v", err)
}
want := &ActionsCacheRetentionLimit{MaxCacheRetentionDays: new(14)}
if !cmp.Equal(limit, want) {
t.Errorf("Actions.GetCacheRetentionLimitForEnterprise returned %+v, want %+v", limit, want)
}
const methodName = "GetCacheRetentionLimitForEnterprise"
testBadOptions(t, methodName, func() (err error) {
_, _, err = client.Actions.GetCacheRetentionLimitForEnterprise(ctx, "\n")
return err
})
testNewRequestAndDoFailure(t, methodName, client, func() (*Response, error) {
got, resp, err := client.Actions.GetCacheRetentionLimitForEnterprise(ctx, "e")
if got != nil {
t.Errorf("testNewRequestAndDoFailure %v = %#v, want nil", methodName, got)
}
return resp, err
})
}
func TestActionsService_SetCacheRetentionLimitForEnterprise(t *testing.T) {
t.Parallel()
client, mux, _ := setup(t)
input := ActionsCacheRetentionLimit{MaxCacheRetentionDays: new(14)}
mux.HandleFunc("/enterprises/e/actions/cache/retention-limit", func(w http.ResponseWriter, r *http.Request) {
testMethod(t, r, "PUT")
testJSONBody(t, r, input)
w.WriteHeader(http.StatusNoContent)
})
ctx := t.Context()
resp, err := client.Actions.SetCacheRetentionLimitForEnterprise(ctx, "e", input)
if err != nil {
t.Errorf("Actions.SetCacheRetentionLimitForEnterprise returned error: %v", err)
}
if got, want := resp.StatusCode, http.StatusNoContent; got != want {
t.Errorf("Actions.SetCacheRetentionLimitForEnterprise return status %v, want %v", got, want)
}
const methodName = "SetCacheRetentionLimitForEnterprise"
testBadOptions(t, methodName, func() (err error) {
_, err = client.Actions.SetCacheRetentionLimitForEnterprise(ctx, "\n", input)
return err
})
testNewRequestAndDoFailure(t, methodName, client, func() (*Response, error) {
return client.Actions.SetCacheRetentionLimitForEnterprise(ctx, "e", input)
})
}
func TestActionsService_GetCacheStorageLimitForEnterprise(t *testing.T) {
t.Parallel()
client, mux, _ := setup(t)
mux.HandleFunc("/enterprises/e/actions/cache/storage-limit", func(w http.ResponseWriter, r *http.Request) {
testMethod(t, r, "GET")
fmt.Fprint(w, `{"max_cache_size_gb":10}`)
})
ctx := t.Context()
limit, _, err := client.Actions.GetCacheStorageLimitForEnterprise(ctx, "e")
if err != nil {
t.Errorf("Actions.GetCacheStorageLimitForEnterprise returned error: %v", err)
}
want := &ActionsCacheStorageLimit{MaxCacheSizeGB: new(10)}
if !cmp.Equal(limit, want) {
t.Errorf("Actions.GetCacheStorageLimitForEnterprise returned %+v, want %+v", limit, want)
}
const methodName = "GetCacheStorageLimitForEnterprise"
testBadOptions(t, methodName, func() (err error) {
_, _, err = client.Actions.GetCacheStorageLimitForEnterprise(ctx, "\n")
return err
})
testNewRequestAndDoFailure(t, methodName, client, func() (*Response, error) {
got, resp, err := client.Actions.GetCacheStorageLimitForEnterprise(ctx, "e")
if got != nil {
t.Errorf("testNewRequestAndDoFailure %v = %#v, want nil", methodName, got)
}
return resp, err
})
}
func TestActionsService_SetCacheStorageLimitForEnterprise(t *testing.T) {
t.Parallel()
client, mux, _ := setup(t)
input := ActionsCacheStorageLimit{MaxCacheSizeGB: new(10)}
mux.HandleFunc("/enterprises/e/actions/cache/storage-limit", func(w http.ResponseWriter, r *http.Request) {
testMethod(t, r, "PUT")
testJSONBody(t, r, input)
w.WriteHeader(http.StatusNoContent)
})
ctx := t.Context()
resp, err := client.Actions.SetCacheStorageLimitForEnterprise(ctx, "e", input)
if err != nil {
t.Errorf("Actions.SetCacheStorageLimitForEnterprise returned error: %v", err)
}
if got, want := resp.StatusCode, http.StatusNoContent; got != want {
t.Errorf("Actions.SetCacheStorageLimitForEnterprise return status %v, want %v", got, want)
}
const methodName = "SetCacheStorageLimitForEnterprise"
testBadOptions(t, methodName, func() (err error) {
_, err = client.Actions.SetCacheStorageLimitForEnterprise(ctx, "\n", input)
return err
})
testNewRequestAndDoFailure(t, methodName, client, func() (*Response, error) {
return client.Actions.SetCacheStorageLimitForEnterprise(ctx, "e", input)
})
}