2015-07-02 20:36:31 +00:00
|
|
|
package repository_test
|
|
|
|
|
|
|
|
import (
|
|
|
|
"testing"
|
|
|
|
|
2016-02-14 14:29:28 +00:00
|
|
|
"restic/backend"
|
|
|
|
"restic/repository"
|
|
|
|
. "restic/test"
|
2015-07-02 20:36:31 +00:00
|
|
|
)
|
|
|
|
|
|
|
|
type saver func(backend.Type, interface{}) (backend.ID, error)
|
|
|
|
|
|
|
|
func (s saver) SaveJSONUnpacked(t backend.Type, arg interface{}) (backend.ID, error) {
|
|
|
|
return s(t, arg)
|
|
|
|
}
|
|
|
|
|
|
|
|
type loader func(backend.Type, backend.ID, interface{}) error
|
|
|
|
|
|
|
|
func (l loader) LoadJSONUnpacked(t backend.Type, id backend.ID, arg interface{}) error {
|
|
|
|
return l(t, id, arg)
|
|
|
|
}
|
|
|
|
|
|
|
|
func TestConfig(t *testing.T) {
|
|
|
|
resultConfig := repository.Config{}
|
|
|
|
save := func(tpe backend.Type, arg interface{}) (backend.ID, error) {
|
|
|
|
Assert(t, tpe == backend.Config,
|
|
|
|
"wrong backend type: got %v, wanted %v",
|
|
|
|
tpe, backend.Config)
|
|
|
|
|
|
|
|
cfg := arg.(repository.Config)
|
|
|
|
resultConfig = cfg
|
|
|
|
return backend.ID{}, nil
|
|
|
|
}
|
|
|
|
|
2016-07-31 14:27:36 +00:00
|
|
|
cfg1, err := repository.CreateConfig()
|
2015-07-02 20:36:31 +00:00
|
|
|
OK(t, err)
|
|
|
|
|
2016-07-31 14:27:36 +00:00
|
|
|
_, err = saver(save).SaveJSONUnpacked(backend.Config, cfg1)
|
|
|
|
|
2015-07-02 20:36:31 +00:00
|
|
|
load := func(tpe backend.Type, id backend.ID, arg interface{}) error {
|
|
|
|
Assert(t, tpe == backend.Config,
|
|
|
|
"wrong backend type: got %v, wanted %v",
|
|
|
|
tpe, backend.Config)
|
|
|
|
|
|
|
|
cfg := arg.(*repository.Config)
|
|
|
|
*cfg = resultConfig
|
|
|
|
return nil
|
|
|
|
}
|
|
|
|
|
|
|
|
cfg2, err := repository.LoadConfig(loader(load))
|
|
|
|
OK(t, err)
|
|
|
|
|
|
|
|
Assert(t, cfg1 == cfg2,
|
|
|
|
"configs aren't equal: %v != %v", cfg1, cfg2)
|
|
|
|
}
|