1
0
mirror of https://github.com/restic/restic.git synced 2024-06-25 07:47:44 +02:00
restic/internal/restic/config_test.go

66 lines
1.4 KiB
Go
Raw Normal View History

2016-08-31 22:39:36 +02:00
package restic_test
2015-07-02 22:36:31 +02:00
import (
2017-06-05 23:56:59 +02:00
"context"
2015-07-02 22:36:31 +02:00
"testing"
2017-07-24 17:42:25 +02:00
"github.com/restic/restic/internal/restic"
2017-10-02 15:06:39 +02:00
rtest "github.com/restic/restic/internal/test"
2015-07-02 22:36:31 +02:00
)
type saver struct {
fn func(restic.FileType, []byte) (restic.ID, error)
}
func (s saver) SaveUnpacked(_ context.Context, t restic.FileType, buf []byte) (restic.ID, error) {
return s.fn(t, buf)
}
2015-07-02 22:36:31 +02:00
func (s saver) Connections() uint {
return 2
2015-07-02 22:36:31 +02:00
}
type loader struct {
fn func(restic.FileType, restic.ID) ([]byte, error)
}
func (l loader) LoadUnpacked(_ context.Context, t restic.FileType, id restic.ID) (data []byte, err error) {
return l.fn(t, id)
}
2015-07-02 22:36:31 +02:00
func (l loader) Connections() uint {
return 2
2015-07-02 22:36:31 +02:00
}
func TestConfig(t *testing.T) {
var resultBuf []byte
save := func(tpe restic.FileType, buf []byte) (restic.ID, error) {
2017-10-02 15:06:39 +02:00
rtest.Assert(t, tpe == restic.ConfigFile,
2015-07-02 22:36:31 +02:00
"wrong backend type: got %v, wanted %v",
2016-08-31 20:29:54 +02:00
tpe, restic.ConfigFile)
2015-07-02 22:36:31 +02:00
resultBuf = buf
2016-08-31 20:29:54 +02:00
return restic.ID{}, nil
2015-07-02 22:36:31 +02:00
}
cfg1, err := restic.CreateConfig(restic.MaxRepoVersion)
2017-10-02 15:06:39 +02:00
rtest.OK(t, err)
2015-07-02 22:36:31 +02:00
err = restic.SaveConfig(context.TODO(), saver{save}, cfg1)
rtest.OK(t, err)
load := func(tpe restic.FileType, id restic.ID) ([]byte, error) {
2017-10-02 15:06:39 +02:00
rtest.Assert(t, tpe == restic.ConfigFile,
2015-07-02 22:36:31 +02:00
"wrong backend type: got %v, wanted %v",
2016-08-31 20:29:54 +02:00
tpe, restic.ConfigFile)
2015-07-02 22:36:31 +02:00
return resultBuf, nil
2015-07-02 22:36:31 +02:00
}
cfg2, err := restic.LoadConfig(context.TODO(), loader{load})
2017-10-02 15:06:39 +02:00
rtest.OK(t, err)
2015-07-02 22:36:31 +02:00
2017-10-02 15:06:39 +02:00
rtest.Assert(t, cfg1 == cfg2,
2015-07-02 22:36:31 +02:00
"configs aren't equal: %v != %v", cfg1, cfg2)
}