2018-03-22 21:11:03 +00:00
|
|
|
package service // import "github.com/docker/docker/volume/service"
|
2018-03-13 19:39:23 +00:00
|
|
|
|
|
|
|
import (
|
|
|
|
"os"
|
|
|
|
"path/filepath"
|
|
|
|
"testing"
|
|
|
|
"time"
|
|
|
|
|
2018-09-11 22:12:55 +00:00
|
|
|
bolt "go.etcd.io/bbolt"
|
2020-02-07 13:39:24 +00:00
|
|
|
"gotest.tools/v3/assert"
|
|
|
|
is "gotest.tools/v3/assert/cmp"
|
2018-03-13 19:39:23 +00:00
|
|
|
)
|
|
|
|
|
|
|
|
func TestSetGetMeta(t *testing.T) {
|
|
|
|
t.Parallel()
|
|
|
|
|
2021-08-24 10:10:50 +00:00
|
|
|
dir, err := os.MkdirTemp("", "test-set-get")
|
2018-03-13 19:28:34 +00:00
|
|
|
assert.NilError(t, err)
|
2018-03-13 19:39:23 +00:00
|
|
|
defer os.RemoveAll(dir)
|
|
|
|
|
|
|
|
db, err := bolt.Open(filepath.Join(dir, "db"), 0600, &bolt.Options{Timeout: 1 * time.Second})
|
2018-03-13 19:28:34 +00:00
|
|
|
assert.NilError(t, err)
|
2018-03-13 19:39:23 +00:00
|
|
|
|
|
|
|
store := &VolumeStore{db: db}
|
2022-05-31 15:01:43 +00:00
|
|
|
defer store.Shutdown()
|
2018-03-13 19:39:23 +00:00
|
|
|
|
|
|
|
_, err = store.getMeta("test")
|
2018-03-13 19:28:34 +00:00
|
|
|
assert.Assert(t, is.ErrorContains(err, ""))
|
2018-03-13 19:39:23 +00:00
|
|
|
|
|
|
|
err = db.Update(func(tx *bolt.Tx) error {
|
|
|
|
_, err := tx.CreateBucket(volumeBucketName)
|
|
|
|
return err
|
|
|
|
})
|
2018-03-13 19:28:34 +00:00
|
|
|
assert.NilError(t, err)
|
2018-03-13 19:39:23 +00:00
|
|
|
|
|
|
|
meta, err := store.getMeta("test")
|
2018-03-13 19:28:34 +00:00
|
|
|
assert.NilError(t, err)
|
|
|
|
assert.DeepEqual(t, volumeMetadata{}, meta)
|
2018-03-13 19:39:23 +00: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 19:28:34 +00:00
|
|
|
assert.NilError(t, err)
|
2018-03-13 19:39:23 +00:00
|
|
|
|
|
|
|
meta, err = store.getMeta("test")
|
2018-03-13 19:28:34 +00:00
|
|
|
assert.NilError(t, err)
|
|
|
|
assert.DeepEqual(t, testMeta, meta)
|
2018-03-13 19:39:23 +00:00
|
|
|
}
|