Ensure that a bucket can write a key/value.
(t *testing.T)
| 124 | |
| 125 | // Ensure that a bucket can write a key/value. |
| 126 | func TestBucket_Put(t *testing.T) { |
| 127 | db := btesting.MustCreateDB(t) |
| 128 | if err := db.Update(func(tx *bolt.Tx) error { |
| 129 | b, err := tx.CreateBucket([]byte("widgets")) |
| 130 | if err != nil { |
| 131 | t.Fatal(err) |
| 132 | } |
| 133 | if err := b.Put([]byte("foo"), []byte("bar")); err != nil { |
| 134 | t.Fatal(err) |
| 135 | } |
| 136 | |
| 137 | v := tx.Bucket([]byte("widgets")).Get([]byte("foo")) |
| 138 | if !bytes.Equal([]byte("bar"), v) { |
| 139 | t.Fatalf("unexpected value: %v", v) |
| 140 | } |
| 141 | return nil |
| 142 | }); err != nil { |
| 143 | t.Fatal(err) |
| 144 | } |
| 145 | } |
| 146 | |
| 147 | // Ensure that a bucket can rewrite a key in the same transaction. |
| 148 | func TestBucket_Put_Repeat(t *testing.T) { |
nothing calls this directly
no test coverage detected