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 (
|
|
|
|
"os"
|
|
|
|
"path/filepath"
|
|
|
|
"testing"
|
|
|
|
"time"
|
|
|
|
|
2018-09-11 18:12:55 -04:00
|
|
|
bolt "go.etcd.io/bbolt"
|
2020-02-07 08:39:24 -05:00
|
|
|
"gotest.tools/v3/assert"
|
|
|
|
is "gotest.tools/v3/assert/cmp"
|
2018-03-13 15:39:23 -04:00
|
|
|
)
|
|
|
|
|
|
|
|
func TestSetGetMeta(t *testing.T) {
|
|
|
|
t.Parallel()
|
|
|
|
|
2021-08-24 06:10:50 -04:00
|
|
|
dir, err := os.MkdirTemp("", "test-set-get")
|
2018-03-13 15:28:34 -04:00
|
|
|
assert.NilError(t, err)
|
2018-03-13 15:39:23 -04:00
|
|
|
defer os.RemoveAll(dir)
|
|
|
|
|
|
|
|
db, err := bolt.Open(filepath.Join(dir, "db"), 0600, &bolt.Options{Timeout: 1 * time.Second})
|
2018-03-13 15:28:34 -04:00
|
|
|
assert.NilError(t, err)
|
2018-03-13 15:39:23 -04:00
|
|
|
|
|
|
|
store := &VolumeStore{db: db}
|
2022-05-31 11:01:43 -04:00
|
|
|
defer store.Shutdown()
|
2018-03-13 15:39:23 -04:00
|
|
|
|
|
|
|
_, err = store.getMeta("test")
|
2018-03-13 15:28:34 -04:00
|
|
|
assert.Assert(t, is.ErrorContains(err, ""))
|
2018-03-13 15:39:23 -04:00
|
|
|
|
|
|
|
err = db.Update(func(tx *bolt.Tx) error {
|
|
|
|
_, err := tx.CreateBucket(volumeBucketName)
|
|
|
|
return err
|
|
|
|
})
|
2018-03-13 15:28:34 -04:00
|
|
|
assert.NilError(t, err)
|
2018-03-13 15:39:23 -04:00
|
|
|
|
|
|
|
meta, err := store.getMeta("test")
|
2018-03-13 15:28:34 -04:00
|
|
|
assert.NilError(t, err)
|
|
|
|
assert.DeepEqual(t, volumeMetadata{}, meta)
|
2018-03-13 15:39:23 -04:00
|
|
|
|
|
|
|
testMeta := volumeMetadata{
|
|
|
|
Name: "test",
|
|
|
|
Driver: "fake",
|
|
|
|
Labels: map[string]string{"a": "1", "b": "2"},
|
|
|
|
Options: map[string]string{"foo": "bar"},
|
|
|
|
}
|
|
|
|
err = store.setMeta("test", testMeta)
|
2018-03-13 15:28:34 -04:00
|
|
|
assert.NilError(t, err)
|
2018-03-13 15:39:23 -04:00
|
|
|
|
|
|
|
meta, err = store.getMeta("test")
|
2018-03-13 15:28:34 -04:00
|
|
|
assert.NilError(t, err)
|
|
|
|
assert.DeepEqual(t, testMeta, meta)
|
2018-03-13 15:39:23 -04:00
|
|
|
}
|