Repository: envoyproxy/envoy
File: test/common/common/version_test.cc (C++)

Code before:
  static const std::string& sslVersion() { return VersionInfo::sslVersion(); }
  static bool sslFipsCompliant() { return VersionInfo::sslFipsCompliant(); }
  static envoy::config::core::v3::BuildVersion makeBuildVersion(const char* version) {
    return VersionInfo::makeBuildVersion(version);
  }
};

TEST(VersionTest, BuildVersion) {
  auto build_version = VersionInfo::buildVersion();
  std::string version_string =
      absl::StrCat(build_version.version().major_number(), ".",
                   build_version.version().minor_number(), ".", build_version.version().patch());

  const auto& fields = build_version.metadata().fields();
  if (fields.find(BuildVersionMetadataKeys::get().BuildLabel) != fields.end()) {
    absl::StrAppend(&version_string, "-",
                    fields.at(BuildVersionMetadataKeys::get().BuildLabel).string_value());
  }
  EXPECT_EQ(BUILD_VERSION_NUMBER, version_string);
  EXPECT_EQ(VersionInfo::revision(),
            fields.at(BuildVersionMetadataKeys::get().RevisionSHA).string_value());
  EXPECT_EQ(VersionInfo::revisionStatus(),
            fields.at(BuildVersionMetadataKeys::get().RevisionStatus).string_value());
  EXPECT_EQ(VersionInfoTestPeer::buildType(),
            fields.at(BuildVersionMetadataKeys::get().BuildType).string_value());
#ifdef ENVOY_SSL_FIPS
  EXPECT_TRUE(VersionInfoTestPeer::sslFipsCompliant());
#else
  EXPECT_FALSE(VersionInfoTestPeer::sslFipsCompliant());
#endif
  EXPECT_EQ(VersionInfoTestPeer::sslVersion(),
            fields.at(BuildVersionMetadataKeys::get().SslVersion).string_value());
}

TEST(VersionTest, MakeBuildVersionWithLabel) {
  auto build_version = VersionInfoTestPeer::makeBuildVersion("1.2.3-foo-bar");
  EXPECT_EQ(1, build_version.version().major_number());
  EXPECT_EQ(2, build_version.version().minor_number());
  EXPECT_EQ(3, build_version.version().patch());
  const auto& fields = build_version.metadata().fields();
  EXPECT_GE(fields.size(), 1);
#ifdef ENVOY_SSL_FIPS
  EXPECT_TRUE(VersionInfoTestPeer::sslFipsCompliant());
#else
  EXPECT_FALSE(VersionInfoTestPeer::sslFipsCompliant());
#endif
  EXPECT_EQ("foo-bar", fields.at(BuildVersionMetadataKeys::get().BuildLabel).string_value());
}

TEST(VersionTest, MakeBuildVersionWithoutLabel) {
  auto build_version = VersionInfoTestPeer::makeBuildVersion("1.2.3");

Review comment (suggestion):
I think this test was kept deliberately to ensure macro is consistent with FIPS_mode(). You should remove when you remove the macro.

Code after:
  static const std::string& buildType() { return VersionInfo::buildType(); }
  static const std::string& sslVersion() { return VersionInfo::sslVersion(); }
  static bool sslFipsCompliant() { return VersionInfo::sslFipsCompliant(); }
  static envoy::config::core::v3::BuildVersion makeBuildVersion(const char* version) {
    return VersionInfo::makeBuildVersion(version);
  }
};

TEST(VersionTest, BuildVersion) {
  auto build_version = VersionInfo::buildVersion();
  std::string version_string =
      absl::StrCat(build_version.version().major_number(), ".",
                   build_version.version().minor_number(), ".", build_version.version().patch());

  const auto& fields = build_version.metadata().fields();
  if (fields.find(BuildVersionMetadataKeys::get().BuildLabel) != fields.end()) {
    absl::StrAppend(&version_string, "-",
                    fields.at(BuildVersionMetadataKeys::get().BuildLabel).string_value());
  }
  EXPECT_EQ(BUILD_VERSION_NUMBER, version_string);
  EXPECT_EQ(VersionInfo::revision(),
            fields.at(BuildVersionMetadataKeys::get().RevisionSHA).string_value());
  EXPECT_EQ(VersionInfo::revisionStatus(),
            fields.at(BuildVersionMetadataKeys::get().RevisionStatus).string_value());
  EXPECT_EQ(VersionInfoTestPeer::buildType(),
            fields.at(BuildVersionMetadataKeys::get().BuildType).string_value());
  if (FIPS_mode() == 1) {
    EXPECT_TRUE(VersionInfoTestPeer::sslFipsCompliant());
  } else {
    EXPECT_FALSE(VersionInfoTestPeer::sslFipsCompliant());
  }
  EXPECT_EQ(VersionInfoTestPeer::sslVersion(),
            fields.at(BuildVersionMetadataKeys::get().SslVersion).string_value());
}

TEST(VersionTest, MakeBuildVersionWithLabel) {
  auto build_version = VersionInfoTestPeer::makeBuildVersion("1.2.3-foo-bar");
  EXPECT_EQ(1, build_version.version().major_number());
  EXPECT_EQ(2, build_version.version().minor_number());
  EXPECT_EQ(3, build_version.version().patch());
  const auto& fields = build_version.metadata().fields();
  EXPECT_GE(fields.size(), 1);
  if (FIPS_mode() == 1) {
    EXPECT_TRUE(VersionInfoTestPeer::sslFipsCompliant());
  } else {
    EXPECT_FALSE(VersionInfoTestPeer::sslFipsCompliant());
  }
  EXPECT_EQ("foo-bar", fields.at(BuildVersionMetadataKeys::get().BuildLabel).string_value());
}

TEST(VersionTest, MakeBuildVersionWithoutLabel) {