TEST(ProxyProtocolConfigFactoryTest, TestCreateFactory) {
  Server::Configuration::NamedListenerFilterConfigFactory* factory =
      Registry::FactoryRegistry<Server::Configuration::NamedListenerFilterConfigFactory>::
          getFactory(ListenerFilters::ListenerFilterNames::get().ProxyProtocol);

  EXPECT_EQ(factory->name(), ListenerFilters::ListenerFilterNames::get().ProxyProtocol);

  const std::string yaml = R"EOF(
      rules:
        - tlv_type: 0x01
          on_tlv_present:
            key: "PP2_TYPE_ALPN"
        - tlv_type: 0x1a
          on_tlv_present:
            key: "PP2_TYPE_CUSTOMER_A"      
)EOF";

  ProtobufTypes::MessagePtr proto_config = factory->createEmptyConfigProto();
  TestUtility::loadFromYaml(yaml, *proto_config);

  Server::Configuration::MockListenerFactoryContext context;
  EXPECT_CALL(context, scope()).Times(1);
  EXPECT_CALL(context, messageValidationVisitor()).Times(1);
  Network::ListenerFilterFactoryCb cb =
      factory->createListenerFilterFactoryFromProto(*proto_config, nullptr, context);

  Network::MockListenerFilterManager manager;
  Network::ListenerFilterPtr added_filter;
  EXPECT_CALL(manager, addAcceptFilter_(_, _))
      .WillOnce(Invoke([&added_filter](const Network::ListenerFilterMatcherSharedPtr&,
                                       Network::ListenerFilterPtr& filter) {
        added_filter = std::move(filter);
      }));
  cb(manager);

  // Make sure we actually create the correct type!
  EXPECT_NE(dynamic_cast<ProxyProtocol::Filter*>(added_filter.get()), nullptr);
}
TEST(ProxyProtocolConfigFactoryTest, TestCreateFactory) {
  Server::Configuration::NamedListenerFilterConfigFactory* factory =
      Registry::FactoryRegistry<Server::Configuration::NamedListenerFilterConfigFactory>::
          getFactory(ListenerFilters::ListenerFilterNames::get().ProxyProtocol);

  EXPECT_EQ(factory->name(), ListenerFilters::ListenerFilterNames::get().ProxyProtocol);

  const std::string yaml = R"EOF(
      rules:
        - tlv_type: 0x01
          on_tlv_present:
            key: "PP2_TYPE_ALPN"
        - tlv_type: 0x1a
          on_tlv_present:
            key: "PP2_TYPE_CUSTOMER_A"      
)EOF";

  ProtobufTypes::MessagePtr proto_config = factory->createEmptyConfigProto();
  TestUtility::loadFromYaml(yaml, *proto_config);

  Server::Configuration::MockListenerFactoryContext context;
  EXPECT_CALL(context, scope()).Times(1);
  EXPECT_CALL(context, messageValidationVisitor()).Times(1);
  Network::ListenerFilterFactoryCb cb =
      factory->createListenerFilterFactoryFromProto(*proto_config, nullptr, context);

  Network::MockListenerFilterManager manager;
  Network::ListenerFilterPtr added_filter;
  EXPECT_CALL(manager, addAcceptFilter_(_, _))
      .WillOnce(Invoke([&added_filter](const Network::ListenerFilterMatcherSharedPtr&,
                                       Network::ListenerFilterPtr& filter) {
        added_filter = std::move(filter);
      }));
  cb(manager);

   
  EXPECT_NE(dynamic_cast<ProxyProtocol::Filter*>(added_filter.get()), nullptr);
}