2015-07-02 20:36:31 +00:00
|
|
|
package repository_test
|
|
|
|
|
|
|
|
import (
|
2016-08-31 18:29:54 +00:00
|
|
|
"restic"
|
2015-07-02 20:36:31 +00:00
|
|
|
"testing"
|
|
|
|
|
2016-02-14 14:29:28 +00:00
|
|
|
"restic/repository"
|
|
|
|
. "restic/test"
|
2015-07-02 20:36:31 +00:00
|
|
|
)
|
|
|
|
|
2016-08-31 18:29:54 +00:00
|
|
|
type saver func(restic.FileType, interface{}) (restic.ID, error)
|
2015-07-02 20:36:31 +00:00
|
|
|
|
2016-08-31 18:29:54 +00:00
|
|
|
func (s saver) SaveJSONUnpacked(t restic.FileType, arg interface{}) (restic.ID, error) {
|
2015-07-02 20:36:31 +00:00
|
|
|
return s(t, arg)
|
|
|
|
}
|
|
|
|
|
2016-08-31 18:29:54 +00:00
|
|
|
type loader func(restic.FileType, restic.ID, interface{}) error
|
2015-07-02 20:36:31 +00:00
|
|
|
|
2016-08-31 18:29:54 +00:00
|
|
|
func (l loader) LoadJSONUnpacked(t restic.FileType, id restic.ID, arg interface{}) error {
|
2015-07-02 20:36:31 +00:00
|
|
|
return l(t, id, arg)
|
|
|
|
}
|
|
|
|
|
|
|
|
func TestConfig(t *testing.T) {
|
|
|
|
resultConfig := repository.Config{}
|
2016-08-31 18:29:54 +00:00
|
|
|
save := func(tpe restic.FileType, arg interface{}) (restic.ID, error) {
|
|
|
|
Assert(t, tpe == restic.ConfigFile,
|
2015-07-02 20:36:31 +00:00
|
|
|
"wrong backend type: got %v, wanted %v",
|
2016-08-31 18:29:54 +00:00
|
|
|
tpe, restic.ConfigFile)
|
2015-07-02 20:36:31 +00:00
|
|
|
|
|
|
|
cfg := arg.(repository.Config)
|
|
|
|
resultConfig = cfg
|
2016-08-31 18:29:54 +00:00
|
|
|
return restic.ID{}, nil
|
2015-07-02 20:36:31 +00:00
|
|
|
}
|
|
|
|
|
2016-07-31 14:27:36 +00:00
|
|
|
cfg1, err := repository.CreateConfig()
|
2015-07-02 20:36:31 +00:00
|
|
|
OK(t, err)
|
|
|
|
|
2016-08-31 18:29:54 +00:00
|
|
|
_, err = saver(save).SaveJSONUnpacked(restic.ConfigFile, cfg1)
|
2016-07-31 14:27:36 +00:00
|
|
|
|
2016-08-31 18:29:54 +00:00
|
|
|
load := func(tpe restic.FileType, id restic.ID, arg interface{}) error {
|
|
|
|
Assert(t, tpe == restic.ConfigFile,
|
2015-07-02 20:36:31 +00:00
|
|
|
"wrong backend type: got %v, wanted %v",
|
2016-08-31 18:29:54 +00:00
|
|
|
tpe, restic.ConfigFile)
|
2015-07-02 20:36:31 +00:00
|
|
|
|
|
|
|
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)
|
|
|
|
}
|