summaryrefslogtreecommitdiffstats
path: root/vendor/github.com/hashicorp/go-immutable-radix
diff options
context:
space:
mode:
Diffstat (limited to 'vendor/github.com/hashicorp/go-immutable-radix')
-rw-r--r--vendor/github.com/hashicorp/go-immutable-radix/iradix.go7
-rw-r--r--vendor/github.com/hashicorp/go-immutable-radix/iradix_test.go37
2 files changed, 42 insertions, 2 deletions
diff --git a/vendor/github.com/hashicorp/go-immutable-radix/iradix.go b/vendor/github.com/hashicorp/go-immutable-radix/iradix.go
index c7172c406..e5e6e57f2 100644
--- a/vendor/github.com/hashicorp/go-immutable-radix/iradix.go
+++ b/vendor/github.com/hashicorp/go-immutable-radix/iradix.go
@@ -338,6 +338,11 @@ func (t *Txn) delete(parent, n *Node, search []byte) (*Node, *leafNode) {
if !n.isLeaf() {
return nil, nil
}
+ // Copy the pointer in case we are in a transaction that already
+ // modified this node since the node will be reused. Any changes
+ // made to the node will not affect returning the original leaf
+ // value.
+ oldLeaf := n.leaf
// Remove the leaf node
nc := t.writeNode(n, true)
@@ -347,7 +352,7 @@ func (t *Txn) delete(parent, n *Node, search []byte) (*Node, *leafNode) {
if n != t.root && len(nc.edges) == 1 {
t.mergeChild(nc)
}
- return nc, n.leaf
+ return nc, oldLeaf
}
// Look for an edge
diff --git a/vendor/github.com/hashicorp/go-immutable-radix/iradix_test.go b/vendor/github.com/hashicorp/go-immutable-radix/iradix_test.go
index bc9c77c20..326299de8 100644
--- a/vendor/github.com/hashicorp/go-immutable-radix/iradix_test.go
+++ b/vendor/github.com/hashicorp/go-immutable-radix/iradix_test.go
@@ -173,7 +173,7 @@ func TestRoot(t *testing.T) {
}
val, ok := r.Get(nil)
if !ok || val != true {
- t.Fatalf("bad: %v %#v", val)
+ t.Fatalf("bad: %#v", val)
}
r, val, ok = r.Delete(nil)
if !ok || val != true {
@@ -1494,3 +1494,38 @@ func TestTrackMutate_cachedNodeChange(t *testing.T) {
}
}
}
+
+func TestLenTxn(t *testing.T) {
+ r := New()
+
+ if r.Len() != 0 {
+ t.Fatalf("not starting with empty tree")
+ }
+
+ txn := r.Txn()
+ keys := []string{
+ "foo/bar/baz",
+ "foo/baz/bar",
+ "foo/zip/zap",
+ "foobar",
+ "nochange",
+ }
+ for _, k := range keys {
+ txn.Insert([]byte(k), nil)
+ }
+ r = txn.Commit()
+
+ if r.Len() != len(keys) {
+ t.Fatalf("bad: expected %d, got %d", len(keys), r.Len())
+ }
+
+ txn = r.Txn()
+ for _, k := range keys {
+ txn.Delete([]byte(k))
+ }
+ r = txn.Commit()
+
+ if r.Len() != 0 {
+ t.Fatalf("tree len should be zero, got %d", r.Len())
+ }
+}