github.com/wozhu6104/docker@v20.10.10+incompatible/volume/service/db_test.go (about) 1 package service // import "github.com/docker/docker/volume/service" 2 3 import ( 4 "io/ioutil" 5 "os" 6 "path/filepath" 7 "testing" 8 "time" 9 10 bolt "go.etcd.io/bbolt" 11 "gotest.tools/v3/assert" 12 is "gotest.tools/v3/assert/cmp" 13 ) 14 15 func TestSetGetMeta(t *testing.T) { 16 t.Parallel() 17 18 dir, err := ioutil.TempDir("", "test-set-get") 19 assert.NilError(t, err) 20 defer os.RemoveAll(dir) 21 22 db, err := bolt.Open(filepath.Join(dir, "db"), 0600, &bolt.Options{Timeout: 1 * time.Second}) 23 assert.NilError(t, err) 24 25 store := &VolumeStore{db: db} 26 27 _, err = store.getMeta("test") 28 assert.Assert(t, is.ErrorContains(err, "")) 29 30 err = db.Update(func(tx *bolt.Tx) error { 31 _, err := tx.CreateBucket(volumeBucketName) 32 return err 33 }) 34 assert.NilError(t, err) 35 36 meta, err := store.getMeta("test") 37 assert.NilError(t, err) 38 assert.DeepEqual(t, volumeMetadata{}, meta) 39 40 testMeta := volumeMetadata{ 41 Name: "test", 42 Driver: "fake", 43 Labels: map[string]string{"a": "1", "b": "2"}, 44 Options: map[string]string{"foo": "bar"}, 45 } 46 err = store.setMeta("test", testMeta) 47 assert.NilError(t, err) 48 49 meta, err = store.getMeta("test") 50 assert.NilError(t, err) 51 assert.DeepEqual(t, testMeta, meta) 52 }