TEST_F(EncryptedRecordTest, TestFragmentedWrite) {
  TLSMessage msg{ContentType::application_data, IOBuf::create(0x4a00)};
  msg.fragment->append(0x4a00);
  memset(msg.fragment->writableData(), 0x1, msg.fragment->length());

  Sequence s;
  EXPECT_CALL(*writeAead_, _encrypt(_, _, 0))
      .InSequence(s)
      .WillOnce(
          Invoke([](std::unique_ptr<IOBuf>& /*buf*/, const IOBuf*, uint64_t) {
            return getBuf("aaaa");
          }));
  EXPECT_CALL(*writeAead_, _encrypt(_, _, 1))
      .InSequence(s)
      .WillOnce(
          Invoke([](std::unique_ptr<IOBuf>& /*buf*/, const IOBuf*, uint64_t) {
            return getBuf("bbbb");
          }));
  auto outBuf = write_.write(std::move(msg));
  expectSame(outBuf.data, "1703034001aaaa1703030a01bbbb");
}
TEST_F(EncryptedRecordTest, TestFragmentedWrite) {
  TLSMessage msg{ContentType::application_data, IOBuf::create(0x4a00)};
  msg.fragment->append(0x4a00);
  memset(msg.fragment->writableData(), 0x1, msg.fragment->length());

  Sequence s;
  EXPECT_CALL(*writeAead_, _encrypt(_, _, 0))
      .InSequence(s)
      .WillOnce(
          Invoke([](std::unique_ptr<IOBuf>&  , const IOBuf*, uint64_t) {
            return getBuf("aaaa");
          }));
  EXPECT_CALL(*writeAead_, _encrypt(_, _, 1))
      .InSequence(s)
      .WillOnce(
          Invoke([](std::unique_ptr<IOBuf>&  , const IOBuf*, uint64_t) {
            return getBuf("bbbb");
          }));
  auto outBuf = write_.write(std::move(msg));
  expectSame(outBuf.data, "1703034001aaaa1703030a01bbbb");
}