TEST(HealthCheckEventLoggerImplTest, All) {
  AccessLog::MockAccessLogManager log_manager;
  std::shared_ptr<AccessLog::MockAccessLogFile> file(new AccessLog::MockAccessLogFile());
  EXPECT_CALL(log_manager, createAccessLog(Filesystem::FilePathAndType{
                               Filesystem::DestinationType::File, "foo"}))
      .WillOnce(Return(file));

  std::shared_ptr<MockHostDescription> host(new NiceMock<MockHostDescription>());
  NiceMock<MockClusterInfo> cluster;
  ON_CALL(*host, cluster()).WillByDefault(ReturnRef(cluster));

  Event::SimulatedTimeSystem time_system;
  // This is rendered as "2009-02-13T23:31:31.234Z".a
  time_system.setSystemTime(std::chrono::milliseconds(1234567891234));

  HealthCheckEventLoggerImpl event_logger(log_manager, time_system, "foo");

  EXPECT_CALL(*file, write(absl::string_view{
                         "{\"health_checker_type\":\"HTTP\",\"host\":{\"socket_address\":{"
                         "\"protocol\":\"TCP\",\"address\":\"10.0.0.1\",\"resolver_name\":\"\","
                         "\"ipv4_compat\":false,\"port_value\":443}},\"cluster_name\":\"fake_"
                         "cluster\",\"eject_unhealthy_event\":{\"failure_type\":\"ACTIVE\"},"
                         "\"timestamp\":\"2009-02-13T23:31:31.234Z\"}\n"}));
  event_logger.logEjectUnhealthy(envoy::data::core::v3::HTTP, host, envoy::data::core::v3::ACTIVE);

  EXPECT_CALL(*file, write(absl::string_view{
                         "{\"health_checker_type\":\"HTTP\",\"host\":{\"socket_address\":{"
                         "\"protocol\":\"TCP\",\"address\":\"10.0.0.1\",\"resolver_name\":\"\","
                         "\"ipv4_compat\":false,\"port_value\":443}},\"cluster_name\":\"fake_"
                         "cluster\",\"add_healthy_event\":{\"first_check\":false},\"timestamp\":"
                         "\"2009-02-13T23:31:31.234Z\"}\n"}));
  event_logger.logAddHealthy(envoy::data::core::v3::HTTP, host, false);

  EXPECT_CALL(*file, write(absl::string_view{
                         "{\"health_checker_type\":\"HTTP\",\"host\":{\"socket_address\":{"
                         "\"protocol\":\"TCP\",\"address\":\"10.0.0.1\",\"resolver_name\":\"\","
                         "\"ipv4_compat\":false,\"port_value\":443}},\"cluster_name\":\"fake_"
                         "cluster\",\"health_check_failure_event\":{\"failure_type\":\"ACTIVE\","
                         "\"first_check\":false},"
                         "\"timestamp\":\"2009-02-13T23:31:31.234Z\"}\n"}));
  event_logger.logUnhealthy(envoy::data::core::v3::HTTP, host, envoy::data::core::v3::ACTIVE,
                            false);

  EXPECT_CALL(*file, write(absl::string_view{
                         "{\"health_checker_type\":\"HTTP\",\"host\":{\"socket_address\":{"
                         "\"protocol\":\"TCP\",\"address\":\"10.0.0.1\",\"resolver_name\":\"\","
                         "\"ipv4_compat\":false,\"port_value\":443}},\"cluster_name\":\"fake_"
                         "cluster\",\"degraded_healthy_host\":{},"
                         "\"timestamp\":\"2009-02-13T23:31:31.234Z\"}\n"}));
  event_logger.logDegraded(envoy::data::core::v3::HTTP, host);

  EXPECT_CALL(*file, write(absl::string_view{
                         "{\"health_checker_type\":\"HTTP\",\"host\":{\"socket_address\":{"
                         "\"protocol\":\"TCP\",\"address\":\"10.0.0.1\",\"resolver_name\":\"\","
                         "\"ipv4_compat\":false,\"port_value\":443}},\"cluster_name\":\"fake_"
                         "cluster\",\"no_longer_degraded_host\":{},"
                         "\"timestamp\":\"2009-02-13T23:31:31.234Z\"}\n"}));
  event_logger.logNoLongerDegraded(envoy::data::core::v3::HTTP, host);
}
TEST(HealthCheckEventLoggerImplTest, All) {
  AccessLog::MockAccessLogManager log_manager;
  std::shared_ptr<AccessLog::MockAccessLogFile> file(new AccessLog::MockAccessLogFile());
  EXPECT_CALL(log_manager, createAccessLog(Filesystem::FilePathAndType{
                               Filesystem::DestinationType::File, "foo"}))
      .WillOnce(Return(file));

  std::shared_ptr<MockHostDescription> host(new NiceMock<MockHostDescription>());
  NiceMock<MockClusterInfo> cluster;
  ON_CALL(*host, cluster()).WillByDefault(ReturnRef(cluster));

  Event::SimulatedTimeSystem time_system;
   
  time_system.setSystemTime(std::chrono::milliseconds(1234567891234));

  HealthCheckEventLoggerImpl event_logger(log_manager, time_system, "foo");

  EXPECT_CALL(*file, write(absl::string_view{
                         "{\"health_checker_type\":\"HTTP\",\"host\":{\"socket_address\":{"
                         "\"protocol\":\"TCP\",\"address\":\"10.0.0.1\",\"resolver_name\":\"\","
                         "\"ipv4_compat\":false,\"port_value\":443}},\"cluster_name\":\"fake_"
                         "cluster\",\"eject_unhealthy_event\":{\"failure_type\":\"ACTIVE\"},"
                         "\"timestamp\":\"2009-02-13T23:31:31.234Z\"}\n"}));
  event_logger.logEjectUnhealthy(envoy::data::core::v3::HTTP, host, envoy::data::core::v3::ACTIVE);

  EXPECT_CALL(*file, write(absl::string_view{
                         "{\"health_checker_type\":\"HTTP\",\"host\":{\"socket_address\":{"
                         "\"protocol\":\"TCP\",\"address\":\"10.0.0.1\",\"resolver_name\":\"\","
                         "\"ipv4_compat\":false,\"port_value\":443}},\"cluster_name\":\"fake_"
                         "cluster\",\"add_healthy_event\":{\"first_check\":false},\"timestamp\":"
                         "\"2009-02-13T23:31:31.234Z\"}\n"}));
  event_logger.logAddHealthy(envoy::data::core::v3::HTTP, host, false);

  EXPECT_CALL(*file, write(absl::string_view{
                         "{\"health_checker_type\":\"HTTP\",\"host\":{\"socket_address\":{"
                         "\"protocol\":\"TCP\",\"address\":\"10.0.0.1\",\"resolver_name\":\"\","
                         "\"ipv4_compat\":false,\"port_value\":443}},\"cluster_name\":\"fake_"
                         "cluster\",\"health_check_failure_event\":{\"failure_type\":\"ACTIVE\","
                         "\"first_check\":false},"
                         "\"timestamp\":\"2009-02-13T23:31:31.234Z\"}\n"}));
  event_logger.logUnhealthy(envoy::data::core::v3::HTTP, host, envoy::data::core::v3::ACTIVE,
                            false);

  EXPECT_CALL(*file, write(absl::string_view{
                         "{\"health_checker_type\":\"HTTP\",\"host\":{\"socket_address\":{"
                         "\"protocol\":\"TCP\",\"address\":\"10.0.0.1\",\"resolver_name\":\"\","
                         "\"ipv4_compat\":false,\"port_value\":443}},\"cluster_name\":\"fake_"
                         "cluster\",\"degraded_healthy_host\":{},"
                         "\"timestamp\":\"2009-02-13T23:31:31.234Z\"}\n"}));
  event_logger.logDegraded(envoy::data::core::v3::HTTP, host);

  EXPECT_CALL(*file, write(absl::string_view{
                         "{\"health_checker_type\":\"HTTP\",\"host\":{\"socket_address\":{"
                         "\"protocol\":\"TCP\",\"address\":\"10.0.0.1\",\"resolver_name\":\"\","
                         "\"ipv4_compat\":false,\"port_value\":443}},\"cluster_name\":\"fake_"
                         "cluster\",\"no_longer_degraded_host\":{},"
                         "\"timestamp\":\"2009-02-13T23:31:31.234Z\"}\n"}));
  event_logger.logNoLongerDegraded(envoy::data::core::v3::HTTP, host);
}