2018-03-13 15:39:23 -04:00
|
|
|
package store
|
|
|
|
|
|
|
|
import (
|
|
|
|
"io/ioutil"
|
|
|
|
"os"
|
|
|
|
"testing"
|
|
|
|
|
|
|
|
"github.com/docker/docker/volume"
|
|
|
|
volumedrivers "github.com/docker/docker/volume/drivers"
|
|
|
|
volumetestutils "github.com/docker/docker/volume/testutils"
|
2018-03-13 15:28:34 -04:00
|
|
|
"github.com/gotestyourself/gotestyourself/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-19 17:18:52 -04:00
|
|
|
s, err := New(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()
|
|
|
|
|
|
|
|
_, err = s.Create("test1", driverName, nil, nil)
|
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"}
|
|
|
|
_, err = s.Create("test2", driverName, testOpts, 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-19 17:18:52 -04:00
|
|
|
s, err = New(dir, drivers)
|
2018-03-13 15:28:34 -04:00
|
|
|
assert.NilError(t, err)
|
2018-03-13 15:39:23 -04:00
|
|
|
|
|
|
|
v, err := s.Get("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
|
|
|
|
|
|
|
v, err = s.Get("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
|
|
|
}
|