2018-03-22 17:11:03 -04:00
|
|
|
package service // import "github.com/docker/docker/volume/service"
|
2018-03-13 15:39:23 -04:00
|
|
|
|
|
|
|
import (
|
2018-03-22 17:11:03 -04:00
|
|
|
"context"
|
2018-03-13 15:39:23 -04:00
|
|
|
"io/ioutil"
|
|
|
|
"os"
|
|
|
|
"testing"
|
|
|
|
|
|
|
|
"github.com/docker/docker/volume"
|
|
|
|
volumedrivers "github.com/docker/docker/volume/drivers"
|
2018-03-22 17:11:03 -04:00
|
|
|
"github.com/docker/docker/volume/service/opts"
|
2018-03-13 15:39:23 -04:00
|
|
|
volumetestutils "github.com/docker/docker/volume/testutils"
|
2018-06-11 09:32:11 -04:00
|
|
|
"gotest.tools/assert"
|
2018-03-13 15:39:23 -04:00
|
|
|
)
|
|
|
|
|
|
|
|
func TestRestore(t *testing.T) {
|
|
|
|
t.Parallel()
|
|
|
|
|
|
|
|
dir, err := ioutil.TempDir("", "test-restore")
|
2018-03-13 15:28:34 -04:00
|
|
|
assert.NilError(t, err)
|
2018-03-13 15:39:23 -04:00
|
|
|
defer os.RemoveAll(dir)
|
|
|
|
|
2018-03-19 17:18:52 -04:00
|
|
|
drivers := volumedrivers.NewStore(nil)
|
2018-03-13 15:39:23 -04:00
|
|
|
driverName := "test-restore"
|
2018-03-19 17:18:52 -04:00
|
|
|
drivers.Register(volumetestutils.NewFakeDriver(driverName), driverName)
|
2018-03-13 15:39:23 -04:00
|
|
|
|
2018-03-22 17:11:03 -04:00
|
|
|
s, err := NewStore(dir, drivers)
|
2018-03-13 15:28:34 -04:00
|
|
|
assert.NilError(t, err)
|
2018-03-13 15:39:23 -04:00
|
|
|
defer s.Shutdown()
|
|
|
|
|
2018-03-22 17:11:03 -04:00
|
|
|
ctx := context.Background()
|
|
|
|
_, err = s.Create(ctx, "test1", driverName)
|
2018-03-13 15:28:34 -04:00
|
|
|
assert.NilError(t, err)
|
2018-03-13 15:39:23 -04:00
|
|
|
|
|
|
|
testLabels := map[string]string{"a": "1"}
|
|
|
|
testOpts := map[string]string{"foo": "bar"}
|
2018-03-22 17:11:03 -04:00
|
|
|
_, err = s.Create(ctx, "test2", driverName, opts.WithCreateOptions(testOpts), opts.WithCreateLabels(testLabels))
|
2018-03-13 15:28:34 -04:00
|
|
|
assert.NilError(t, err)
|
2018-03-13 15:39:23 -04:00
|
|
|
|
|
|
|
s.Shutdown()
|
|
|
|
|
2018-03-22 17:11:03 -04:00
|
|
|
s, err = NewStore(dir, drivers)
|
2018-03-13 15:28:34 -04:00
|
|
|
assert.NilError(t, err)
|
2018-03-13 15:39:23 -04:00
|
|
|
|
2018-03-22 17:11:03 -04:00
|
|
|
v, err := s.Get(ctx, "test1")
|
2018-03-13 15:28:34 -04:00
|
|
|
assert.NilError(t, err)
|
2018-03-13 15:39:23 -04:00
|
|
|
|
|
|
|
dv := v.(volume.DetailedVolume)
|
|
|
|
var nilMap map[string]string
|
2018-03-13 15:28:34 -04:00
|
|
|
assert.DeepEqual(t, nilMap, dv.Options())
|
|
|
|
assert.DeepEqual(t, nilMap, dv.Labels())
|
2018-03-13 15:39:23 -04:00
|
|
|
|
2018-03-22 17:11:03 -04:00
|
|
|
v, err = s.Get(ctx, "test2")
|
2018-03-13 15:28:34 -04:00
|
|
|
assert.NilError(t, err)
|
2018-03-13 15:39:23 -04:00
|
|
|
dv = v.(volume.DetailedVolume)
|
2018-03-13 15:28:34 -04:00
|
|
|
assert.DeepEqual(t, testOpts, dv.Options())
|
|
|
|
assert.DeepEqual(t, testLabels, dv.Labels())
|
2018-03-13 15:39:23 -04:00
|
|
|
}
|