| 1 |
|
| 2 |
|
| 3 |
|
| 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 |
|
| 19 |
|
| 20 |
const budget int64 = 50e9 |
| 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 |
|
| 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 |
| 33 |
cfg := env.Editor.Config() |
| 34 |
cfg.Settings["maxFileCacheBytes"] = newBudget |
| 35 |
env.ChangeConfiguration(cfg) |
| 36 |
env.AfterChange() |
| 37 |
|
| 38 |
|
| 39 |
if got := filecache.SetBudget(-1); got != int64(newBudget) { |
| 40 |
t.Errorf("updated budget: got %d, want %d", got, newBudget) |
| 41 |
} |
| 42 |
}) |
| 43 |
} |