cache_opts: address PR comments

This commit is contained in:
Vladimir Buzuev 2020-05-04 11:01:38 -07:00
parent 512f37b369
commit 862cde393c
2 changed files with 40 additions and 8 deletions

View File

@ -93,7 +93,7 @@ func EnableCaching(enabled bool) error {
}
}
func GetCachedMemory() (int, int, error) {
func GetCachedMemory() (current int, allowed int, err error) {
return getSizetSizet(C.GIT_OPT_GET_CACHED_MEMORY)
}
@ -130,8 +130,7 @@ func getSizetSizet(opt C.int) (int, int, error) {
runtime.LockOSThread()
defer runtime.UnlockOSThread()
var val1 C.size_t
var val2 C.size_t
var val1, val2 C.size_t
err := C._go_git_opts_get_size_t_size_t(opt, &val1, &val2)
if err < 0 {
return 0, 0, MakeGitError(err)

View File

@ -48,3 +48,36 @@ func TestMmapSizes(t *testing.T) {
t.Fatal("Sizes don't match")
}
}
func TestEnableCaching(t *testing.T) {
err := EnableCaching(false)
checkFatal(t, err)
err = EnableCaching(true)
checkFatal(t, err)
}
func TestGetCachedMemory(t *testing.T) {
current, allowed, err := GetCachedMemory()
checkFatal(t, err)
if current < 0 {
t.Fatal("current < 0")
}
if allowed < 0 {
t.Fatal("allowed < 0")
}
}
func TestSetCacheMaxSize(t *testing.T) {
err := SetCacheMaxSize(0)
checkFatal(t, err)
err = SetCacheMaxSize(1024 * 1024)
checkFatal(t, err)
// revert to default 256MB
err = SetCacheMaxSize(256 * 1024 * 1024)
checkFatal(t, err)
}