Exemple #1
0
func TestConfig(t *testing.T) {
	resultConfig := restic.Config{}
	save := func(tpe restic.FileType, arg interface{}) (restic.ID, error) {
		Assert(t, tpe == restic.ConfigFile,
			"wrong backend type: got %v, wanted %v",
			tpe, restic.ConfigFile)

		cfg := arg.(restic.Config)
		resultConfig = cfg
		return restic.ID{}, nil
	}

	cfg1, err := restic.CreateConfig()
	OK(t, err)

	_, err = saver(save).SaveJSONUnpacked(restic.ConfigFile, cfg1)

	load := func(tpe restic.FileType, id restic.ID, arg interface{}) error {
		Assert(t, tpe == restic.ConfigFile,
			"wrong backend type: got %v, wanted %v",
			tpe, restic.ConfigFile)

		cfg := arg.(*restic.Config)
		*cfg = resultConfig
		return nil
	}

	cfg2, err := restic.LoadConfig(loader(load))
	OK(t, err)

	Assert(t, cfg1 == cfg2,
		"configs aren't equal: %v != %v", cfg1, cfg2)
}
Exemple #2
0
// SearchKey finds a key with the supplied password, afterwards the config is
// read and parsed. It tries at most maxKeys key files in the repo.
func (r *Repository) SearchKey(password string, maxKeys int) error {
	key, err := SearchKey(r, password, maxKeys)
	if err != nil {
		return err
	}

	r.key = key.master
	r.packerManager.key = key.master
	r.keyName = key.Name()
	r.cfg, err = restic.LoadConfig(r)
	return err
}