restic: speed up repository config initialization in tests

Avoid redundant polynomial generation, which takes a millisecond or so.
This commit is contained in:
Michael Eischer
2026-06-14 21:38:09 +02:00
parent 440d925467
commit 1174e97b30
3 changed files with 10 additions and 9 deletions
+1 -4
View File
@@ -919,13 +919,10 @@ func (r *Repository) Init(ctx context.Context, version uint, password string, ch
return err
}
cfg, err := restic.CreateConfig(version)
cfg, err := restic.CreateConfig(version, chunkerPolynomial)
if err != nil {
return err
}
if chunkerPolynomial != nil {
cfg.ChunkerPolynomial = *chunkerPolynomial
}
return r.init(ctx, password, cfg)
}
+8 -4
View File
@@ -28,15 +28,19 @@ const StableRepoVersion = 2
// CreateConfig creates a config file with a randomly selected polynomial and
// ID.
func CreateConfig(version uint) (Config, error) {
func CreateConfig(version uint, pol *chunker.Pol) (Config, error) {
var (
err error
cfg Config
)
cfg.ChunkerPolynomial, err = chunker.RandomPolynomial()
if err != nil {
return Config{}, errors.Wrap(err, "chunker.RandomPolynomial")
if pol == nil {
cfg.ChunkerPolynomial, err = chunker.RandomPolynomial()
if err != nil {
return Config{}, errors.Wrap(err, "chunker.RandomPolynomial")
}
} else {
cfg.ChunkerPolynomial = *pol
}
cfg.ID = NewRandomID().String()
+1 -1
View File
@@ -43,7 +43,7 @@ func TestConfig(t *testing.T) {
return restic.ID{}, nil
}
cfg1, err := restic.CreateConfig(restic.MaxRepoVersion)
cfg1, err := restic.CreateConfig(restic.MaxRepoVersion, nil)
rtest.OK(t, err)
err = restic.SaveConfig(context.TODO(), saver{save}, cfg1)