nt",
        result.reason());
}

TEST(ReplSetHeartbeatResponse, InitializeConfigWrongType) {
    ReplSetHeartbeatResponse hbResponse;
    BSONObj initializerObj =
        BSON("ok" << 1.0 << "v" << 2 <<  // needs a version to get this far in initialize()
             "config"
                  << 4);
    Status result = hbResponse.initialize(initializerObj, 0);
    ASSERT_EQUALS(ErrorCodes::TypeMismatch, result);
    ASSERT_EQUALS(
        "Expected \"config\" in response to replSetHeartbeat to "
        "have type Object, but found int",
        result.reason());
}

TEST(ReplSetHeartbeatResponse, InitializeBadConfig) {
    ReplSetHeartbeatResponse hbResponse;
    BSONObj initializerObj =
        BSON("ok" << 1.0 << "v" << 2 <<  // needs a version to get this far in initialize()
             "config"
                  << BSON("illegalFieldName" << 2));
    Status result = hbResponse.initialize(initializerObj, 0);
    ASSERT_EQUALS(ErrorCodes::BadValue, result);
    ASSERT_EQUALS("Unexpected field illegalFieldName in replica set configuration",
                  result.reason());
}

TEST(ReplSetHeartbeatResponse, InitializeBothElectionTimeTypesSameResult) {
    ReplSetHeartbeatResponse hbResponseDate;
    ReplSetHeartbeatResponse hbResponseTimestamp;
    BSONObjBuilder initializerDate;
    BSONObjBuilder initializerTimestamp;
    Date_t electionTime = Date_t::fromMillisSinceEpoch(974132);

    initializerDate.append("ok", 1.0);
    initializerDate.append("v", 1);
    initializerDate.appendDate("electionTime", electionTime);
    Status result = hbResponseDate.initialize(initializerDate.obj(), 0);
    ASSERT_EQUALS(Status::OK(), result);

    initializerTimestamp.append("ok", 1.0);
    initializerTimestamp.append("v", 1);
    initializerTimestamp.appendTimestamp("electionTime", electionTime.toULL());
    result = hbResponseTimestamp.initialize(initializerTimestamp.obj(), 0);
    ASSERT_EQUALS(Status::OK(), result);

    ASSERT_EQUALS(hbResponseTimestamp.getElectionTime(), hbResponseTimestamp.getElectionTime());
}

