MCPcopy
hub / github.com/etcd-io/bbolt / TestSurgery_ClearPage

Function TestSurgery_ClearPage

cmd/bbolt/command/command_surgery_test.go:104–137  ·  view source on GitHub ↗

TODO(ahrtr): add test case below for `surgery clear-page` command: 1. The page is a branch page. All its children should become free pages.

(t *testing.T)

Source from the content-addressed store, hash-verified

102// TODO(ahrtr): add test case below for `surgery clear-page` command:
103// 1. The page is a branch page. All its children should become free pages.
104func TestSurgery_ClearPage(t *testing.T) {
105 pageSize := 4096
106 db := btesting.MustCreateDBWithOption(t, &bolt.Options{PageSize: pageSize})
107 srcPath := db.Path()
108
109 // Insert some sample data
110 t.Log("Insert some sample data")
111 err := db.Fill([]byte("data"), 1, 20,
112 func(tx int, k int) []byte { return []byte(fmt.Sprintf("%04d", k)) },
113 func(tx int, k int) []byte { return make([]byte, 10) },
114 )
115 require.NoError(t, err)
116
117 defer requireDBNoChange(t, dbData(t, srcPath), srcPath)
118
119 // clear page 3
120 t.Log("clear page 3")
121 rootCmd := command.NewRootCommand()
122 output := filepath.Join(t.TempDir(), "dstdb")
123 rootCmd.SetArgs([]string{
124 "surgery", "clear-page", srcPath,
125 "--output", output,
126 "--pageId", "3",
127 })
128 err = rootCmd.Execute()
129 require.NoError(t, err)
130
131 t.Log("Verify result")
132 dstPageId3Data := readPage(t, output, 3, pageSize)
133
134 p := common.LoadPage(dstPageId3Data)
135 assert.Equal(t, uint16(0), p.Count())
136 assert.Equal(t, uint32(0), p.Overflow())
137}
138
139func TestSurgery_ClearPageElements_Without_Overflow(t *testing.T) {
140 testCases := []struct {

Callers

nothing calls this directly

Calls 10

MustCreateDBWithOptionFunction · 0.92
NewRootCommandFunction · 0.92
LoadPageFunction · 0.92
requireDBNoChangeFunction · 0.85
dbDataFunction · 0.85
readPageFunction · 0.85
FillMethod · 0.80
OverflowMethod · 0.80
CountMethod · 0.65
PathMethod · 0.45

Tested by

no test coverage detected