@@ -1623,6 +1623,111 @@ func TestBucket_Stats_Nested(t *testing.T) {
1623
1623
}
1624
1624
}
1625
1625
1626
+ func TestBucket_Inspect (t * testing.T ) {
1627
+ db := btesting .MustCreateDB (t )
1628
+
1629
+ expectedStructure := bolt.BucketStructure {
1630
+ Name : "root" ,
1631
+ KeyN : 0 ,
1632
+ Children : []bolt.BucketStructure {
1633
+ {
1634
+ Name : "b1" ,
1635
+ KeyN : 3 ,
1636
+ Children : []bolt.BucketStructure {
1637
+ {
1638
+ Name : "b1_1" ,
1639
+ KeyN : 6 ,
1640
+ },
1641
+ {
1642
+ Name : "b1_2" ,
1643
+ KeyN : 7 ,
1644
+ },
1645
+ {
1646
+ Name : "b1_3" ,
1647
+ KeyN : 8 ,
1648
+ },
1649
+ },
1650
+ },
1651
+ {
1652
+ Name : "b2" ,
1653
+ KeyN : 4 ,
1654
+ Children : []bolt.BucketStructure {
1655
+ {
1656
+ Name : "b2_1" ,
1657
+ KeyN : 10 ,
1658
+ },
1659
+ {
1660
+ Name : "b2_2" ,
1661
+ KeyN : 12 ,
1662
+ Children : []bolt.BucketStructure {
1663
+ {
1664
+ Name : "b2_2_1" ,
1665
+ KeyN : 2 ,
1666
+ },
1667
+ {
1668
+ Name : "b2_2_2" ,
1669
+ KeyN : 3 ,
1670
+ },
1671
+ },
1672
+ },
1673
+ {
1674
+ Name : "b2_3" ,
1675
+ KeyN : 11 ,
1676
+ },
1677
+ },
1678
+ },
1679
+ },
1680
+ }
1681
+
1682
+ type bucketItem struct {
1683
+ b * bolt.Bucket
1684
+ bs bolt.BucketStructure
1685
+ }
1686
+
1687
+ t .Log ("Populating the database" )
1688
+ err := db .Update (func (tx * bolt.Tx ) error {
1689
+ queue := []bucketItem {
1690
+ {
1691
+ b : nil ,
1692
+ bs : expectedStructure ,
1693
+ },
1694
+ }
1695
+
1696
+ for len (queue ) > 0 {
1697
+ item := queue [0 ]
1698
+ queue = queue [1 :]
1699
+
1700
+ if item .b != nil {
1701
+ for i := 0 ; i < item .bs .KeyN ; i ++ {
1702
+ err := item .b .Put ([]byte (fmt .Sprintf ("%02d" , i )), []byte (fmt .Sprintf ("%02d" , i )))
1703
+ require .NoError (t , err )
1704
+ }
1705
+
1706
+ for _ , child := range item .bs .Children {
1707
+ childBucket , err := item .b .CreateBucket ([]byte (child .Name ))
1708
+ require .NoError (t , err )
1709
+ queue = append (queue , bucketItem {b : childBucket , bs : child })
1710
+ }
1711
+ } else {
1712
+ for _ , child := range item .bs .Children {
1713
+ childBucket , err := tx .CreateBucket ([]byte (child .Name ))
1714
+ require .NoError (t , err )
1715
+ queue = append (queue , bucketItem {b : childBucket , bs : child })
1716
+ }
1717
+ }
1718
+ }
1719
+ return nil
1720
+ })
1721
+ require .NoError (t , err )
1722
+
1723
+ t .Log ("Inspecting the database" )
1724
+ _ = db .View (func (tx * bolt.Tx ) error {
1725
+ actualStructure := tx .Inspect ()
1726
+ assert .Equal (t , expectedStructure , actualStructure )
1727
+ return nil
1728
+ })
1729
+ }
1730
+
1626
1731
// Ensure a large bucket can calculate stats.
1627
1732
func TestBucket_Stats_Large (t * testing.T ) {
1628
1733
if testing .Short () {
0 commit comments