(t *testing.T)
| 17 | ) |
| 18 | |
| 19 | func TestPageItemCommand_Run(t *testing.T) { |
| 20 | testCases := []struct { |
| 21 | name string |
| 22 | printable bool |
| 23 | itemId string |
| 24 | expectedKey string |
| 25 | expectedValue string |
| 26 | }{ |
| 27 | { |
| 28 | name: "printable items", |
| 29 | printable: true, |
| 30 | itemId: "0", |
| 31 | expectedKey: "key_0", |
| 32 | expectedValue: "value_0", |
| 33 | }, |
| 34 | { |
| 35 | name: "non printable items", |
| 36 | printable: false, |
| 37 | itemId: "0", |
| 38 | expectedKey: hex.EncodeToString(convertInt64IntoBytes(0 + 1)), |
| 39 | expectedValue: hex.EncodeToString(convertInt64IntoBytes(0 + 2)), |
| 40 | }, |
| 41 | } |
| 42 | |
| 43 | for _, tc := range testCases { |
| 44 | t.Run(tc.name, func(t *testing.T) { |
| 45 | db := btesting.MustCreateDBWithOption(t, &bolt.Options{PageSize: 4096}) |
| 46 | srcPath := db.Path() |
| 47 | |
| 48 | t.Log("Inserting some sample data") |
| 49 | err := db.Update(func(tx *bolt.Tx) error { |
| 50 | b, bErr := tx.CreateBucketIfNotExists([]byte("data")) |
| 51 | if bErr != nil { |
| 52 | return bErr |
| 53 | } |
| 54 | |
| 55 | for i := 0; i < 100; i++ { |
| 56 | if tc.printable { |
| 57 | if bErr = b.Put([]byte(fmt.Sprintf("key_%d", i)), []byte(fmt.Sprintf("value_%d", i))); bErr != nil { |
| 58 | return bErr |
| 59 | } |
| 60 | } else { |
| 61 | k, v := convertInt64IntoBytes(int64(i+1)), convertInt64IntoBytes(int64(i+2)) |
| 62 | if bErr = b.Put(k, v); bErr != nil { |
| 63 | return bErr |
| 64 | } |
| 65 | } |
| 66 | } |
| 67 | return nil |
| 68 | }) |
| 69 | require.NoError(t, err) |
| 70 | require.NoError(t, db.Close()) |
| 71 | defer requireDBNoChange(t, dbData(t, srcPath), srcPath) |
| 72 | |
| 73 | meta := readMetaPage(t, srcPath) |
| 74 | leafPageId := 0 |
| 75 | for i := 2; i < int(meta.Pgid()); i++ { |
| 76 | p, _, err := guts_cli.ReadPage(srcPath, uint64(i)) |
nothing calls this directly
no test coverage detected