github.com/demonoid81/moby@v0.0.0-20200517203328-62dd8e17c460/volume/service/restore_test.go (about)

     1  package service // import "github.com/demonoid81/moby/volume/service"
     2  
     3  import (
     4  	"context"
     5  	"io/ioutil"
     6  	"os"
     7  	"testing"
     8  
     9  	"github.com/demonoid81/moby/volume"
    10  	volumedrivers "github.com/demonoid81/moby/volume/drivers"
    11  	"github.com/demonoid81/moby/volume/service/opts"
    12  	volumetestutils "github.com/demonoid81/moby/volume/testutils"
    13  	"gotest.tools/v3/assert"
    14  )
    15  
    16  func TestRestore(t *testing.T) {
    17  	t.Parallel()
    18  
    19  	dir, err := ioutil.TempDir("", "test-restore")
    20  	assert.NilError(t, err)
    21  	defer os.RemoveAll(dir)
    22  
    23  	drivers := volumedrivers.NewStore(nil)
    24  	driverName := "test-restore"
    25  	drivers.Register(volumetestutils.NewFakeDriver(driverName), driverName)
    26  
    27  	s, err := NewStore(dir, drivers)
    28  	assert.NilError(t, err)
    29  	defer s.Shutdown()
    30  
    31  	ctx := context.Background()
    32  	_, err = s.Create(ctx, "test1", driverName)
    33  	assert.NilError(t, err)
    34  
    35  	testLabels := map[string]string{"a": "1"}
    36  	testOpts := map[string]string{"foo": "bar"}
    37  	_, err = s.Create(ctx, "test2", driverName, opts.WithCreateOptions(testOpts), opts.WithCreateLabels(testLabels))
    38  	assert.NilError(t, err)
    39  
    40  	s.Shutdown()
    41  
    42  	s, err = NewStore(dir, drivers)
    43  	assert.NilError(t, err)
    44  
    45  	v, err := s.Get(ctx, "test1")
    46  	assert.NilError(t, err)
    47  
    48  	dv := v.(volume.DetailedVolume)
    49  	var nilMap map[string]string
    50  	assert.DeepEqual(t, nilMap, dv.Options())
    51  	assert.DeepEqual(t, nilMap, dv.Labels())
    52  
    53  	v, err = s.Get(ctx, "test2")
    54  	assert.NilError(t, err)
    55  	dv = v.(volume.DetailedVolume)
    56  	assert.DeepEqual(t, testOpts, dv.Options())
    57  	assert.DeepEqual(t, testLabels, dv.Labels())
    58  }