blob: 1fa75ae8fa0454f4afd03fc86c027b363dca6d53 [file] [log] [blame]
#include "bmc/gmi_reader.h"
#include <cstdio>
#include <string>
#include "gmi/machine_identity.pb.h"
#include "proto_reader.h"
#include "gmock/gmock.h"
#include "gtest/gtest.h"
#include "absl/status/status.h"
#include "bmc/test_util.h"
namespace {
using ::testing::status::StatusIs;
using security_prodid::GoogleMachineIdentityProto;
// TODO (b/352080861)create a static file for testing, rather than creating a
// new file during test. Creating a file during the test, allows us to ignore
// the file path that must be correct for static files
TEST(gmi_read_test, read_fqdn) {
GoogleMachineIdentityProto id;
std::string test_fqdn = "jrxi100";
std::string file_name = std::tmpnam(nullptr);
id.set_fqdn(test_fqdn);
EXPECT_TRUE(proto_reader::WriteProto(file_name, id).ok());
EXPECT_EQ(gmi_reader::ReadGmiHostName(file_name).value(), test_fqdn);
}
TEST(gmi_empty_string_test, read_fqdn) {
GoogleMachineIdentityProto id;
std::string test_fqdn = "";
std::string file_name = std::tmpnam(nullptr);
id.set_fqdn(test_fqdn);
EXPECT_TRUE(proto_reader::WriteProto(file_name, id).ok());
EXPECT_EQ(gmi_reader::ReadGmiHostName(file_name).value(), test_fqdn);
}
TEST(gmi_file_not_found_test, read_fqdn) {
std::string file_name = std::tmpnam(nullptr);
absl::Status status = gmi_reader::ReadGmiHostName(file_name).status();
EXPECT_THAT(gmi_reader::ReadGmiHostName(file_name).status(),
StatusIs(absl::StatusCode::kInvalidArgument));
}
} // namespace