Debian Codegraph @

gopls/internal/test/integration/misc/filecache_test.go

raw symbols SCIP
1 // Copyright 2026 The Go Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style
3 // license that can be found in the LICENSE file.
4
5 package misc
6
7 import (
8 "testing"
9
10 "golang.org/x/tools/gopls/internal/filecache"
11 "golang.org/x/tools/gopls/internal/test/integration"
12 )
13
14 func TestMaxFileCacheBytes(t *testing.T) {
15 before := filecache.SetBudget(-1)
16 defer filecache.SetBudget(before)
17
18 // Use a value large enough to ensure there are no
19 // side effects, as file cache GC is global.
20 const budget int64 = 50e9 // 50GB
21
22 integration.WithOptions(
23 integration.Settings(map[string]any{
24 "maxFileCacheBytes": budget,
25 }),
26 ).Run(t, "", func(t *testing.T, env *integration.Env) {
27 // Verify that budget is set.
28 if got := filecache.SetBudget(-1); got != int64(budget) {
29 t.Errorf("initial budget: got %d, want %d", got, budget)
30 }
31
32 const newBudget int64 = 55e9 // 55GB
33 cfg := env.Editor.Config()
34 cfg.Settings["maxFileCacheBytes"] = newBudget
35 env.ChangeConfiguration(cfg)
36 env.AfterChange()
37
38 // Verify that the budget was updated.
39 if got := filecache.SetBudget(-1); got != int64(newBudget) {
40 t.Errorf("updated budget: got %d, want %d", got, newBudget)
41 }
42 })
43 }