forked from TrueCloudLab/restic
repository: Refactor Config
This commit is contained in:
parent
867f6c8e24
commit
c553a57e0d
3 changed files with 146 additions and 54 deletions
53
repository/config_test.go
Normal file
53
repository/config_test.go
Normal file
|
@ -0,0 +1,53 @@
|
|||
package repository_test
|
||||
|
||||
import (
|
||||
"testing"
|
||||
|
||||
"github.com/restic/restic/backend"
|
||||
"github.com/restic/restic/repository"
|
||||
. "github.com/restic/restic/test"
|
||||
)
|
||||
|
||||
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
|
||||
}
|
||||
|
||||
cfg1, err := repository.CreateConfig(saver(save))
|
||||
OK(t, err)
|
||||
|
||||
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)
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue