Skip to content

Commit eaf8239

Browse files
committed
loopdb: allow restored databases to contain nil values
1 parent 3e71ff0 commit eaf8239

File tree

1 file changed

+10
-2
lines changed

1 file changed

+10
-2
lines changed

loopdb/raw_db_test.go

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@ package loopdb
22

33
import (
44
"encoding/hex"
5-
"errors"
65
"fmt"
76
"strings"
87

@@ -88,6 +87,15 @@ func restoreDB(bucket *bbolt.Bucket, data map[string]interface{}) error {
8887
for k, v := range data {
8988
key := []byte(k)
9089

90+
// Store nil values.
91+
if v == nil {
92+
err := bucket.Put(key, nil)
93+
if err != nil {
94+
return err
95+
}
96+
continue
97+
}
98+
9199
switch value := v.(type) {
92100

93101
// Key contains value.
@@ -109,7 +117,7 @@ func restoreDB(bucket *bbolt.Bucket, data map[string]interface{}) error {
109117
}
110118

111119
default:
112-
return errors.New("invalid type")
120+
return fmt.Errorf("invalid type %T", value)
113121
}
114122
}
115123

0 commit comments

Comments
 (0)