2
2
mirror of https://github.com/octoleo/restic.git synced 2024-05-28 22:50:48 +00:00
restic/internal/restic/config_test.go

57 lines
1.4 KiB
Go
Raw Normal View History

2016-08-31 20:39:36 +00:00
package restic_test
2015-07-02 20:36:31 +00:00
import (
2017-06-05 21:56:59 +00:00
"context"
2015-07-02 20:36:31 +00:00
"testing"
2017-07-24 15:42:25 +00:00
"github.com/restic/restic/internal/restic"
2017-10-02 13:06:39 +00:00
rtest "github.com/restic/restic/internal/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)
}
2017-06-05 21:56:59 +00:00
type loader func(context.Context, restic.FileType, restic.ID, interface{}) error
2015-07-02 20:36:31 +00:00
2017-06-05 21:56:59 +00:00
func (l loader) LoadJSONUnpacked(ctx context.Context, t restic.FileType, id restic.ID, arg interface{}) error {
return l(ctx, t, id, arg)
2015-07-02 20:36:31 +00:00
}
func TestConfig(t *testing.T) {
2016-08-31 20:39:36 +00:00
resultConfig := restic.Config{}
2016-08-31 18:29:54 +00:00
save := func(tpe restic.FileType, arg interface{}) (restic.ID, error) {
2017-10-02 13:06:39 +00:00
rtest.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
2016-08-31 20:39:36 +00:00
cfg := arg.(restic.Config)
2015-07-02 20:36:31 +00:00
resultConfig = cfg
2016-08-31 18:29:54 +00:00
return restic.ID{}, nil
2015-07-02 20:36:31 +00:00
}
cfg1, err := restic.CreateConfig(restic.MaxRepoVersion)
2017-10-02 13:06:39 +00:00
rtest.OK(t, err)
2015-07-02 20:36:31 +00:00
2016-08-31 18:29:54 +00:00
_, err = saver(save).SaveJSONUnpacked(restic.ConfigFile, cfg1)
rtest.OK(t, err)
2017-06-05 21:56:59 +00:00
load := func(ctx context.Context, tpe restic.FileType, id restic.ID, arg interface{}) error {
2017-10-02 13:06:39 +00:00
rtest.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
2016-08-31 20:39:36 +00:00
cfg := arg.(*restic.Config)
2015-07-02 20:36:31 +00:00
*cfg = resultConfig
return nil
}
2017-06-05 21:56:59 +00:00
cfg2, err := restic.LoadConfig(context.TODO(), loader(load))
2017-10-02 13:06:39 +00:00
rtest.OK(t, err)
2015-07-02 20:36:31 +00:00
2017-10-02 13:06:39 +00:00
rtest.Assert(t, cfg1 == cfg2,
2015-07-02 20:36:31 +00:00
"configs aren't equal: %v != %v", cfg1, cfg2)
}