<commit_before>/*
 * Copyright (c) 2014 Juniper Networks, Inc. All rights reserved.
 */

#include <fstream>
#include <iostream>

#include <boost/asio/ip/host_name.hpp>

#include "base/contrail_ports.h"
#include "base/test/task_test_util.h"
#include "base/util.h"
#include "base/logging.h"
#include "base/test/task_test_util.h"
#include "control-node/options.h"
#include "io/event_manager.h"
#include "net/address_util.h"

using namespace std;
using namespace boost::asio::ip;

static uint16_t default_bgp_port = ContrailPorts::ControlBgp();
static uint16_t default_http_server_port = ContrailPorts::HttpPortControl();
static uint16_t default_xmpp_port = ContrailPorts::ControlXmpp();
static uint16_t default_discovery_port = ContrailPorts::DiscoveryServerPort();

class OptionsTest : public ::testing::Test {
protected:
    OptionsTest() { }

    virtual void SetUp() {
        boost::system::error_code error;
        hostname_ = host_name(error);
        host_ip_ = GetHostIp(evm_.io_service(), hostname_);
        default_collector_server_list_.push_back("127.0.0.1:8086");
    }

    virtual void TearDown() {
        remove("./options_test_config_file.conf");
    }

    EventManager evm_;
    std::string hostname_;
    std::string host_ip_;
    std::vector<std::string> default_collector_server_list_;
    Options options_;
};

TEST_F(OptionsTest, NoArguments) {
    int argc = 1;
    char *argv[argc];
    char argv_0[] = "options_test";
    argv[0] = argv_0;

    options_.Parse(evm_, argc, argv);

    EXPECT_EQ(options_.bgp_config_file(), "bgp_config.xml");
    EXPECT_EQ(options_.bgp_port(), default_bgp_port);
    TASK_UTIL_EXPECT_VECTOR_EQ(default_collector_server_list_,
                     options_.collector_server_list());
    EXPECT_EQ(options_.config_file(), "/etc/contrail/contrail-control.conf");
    EXPECT_EQ(options_.discovery_server(), "127.0.0.1");
    EXPECT_EQ(options_.discovery_port(), default_discovery_port);
    EXPECT_EQ(options_.hostname(), hostname_);
    EXPECT_EQ(options_.host_ip(), host_ip_);
    EXPECT_EQ(options_.http_server_port(), default_http_server_port);
    EXPECT_EQ(options_.log_category(), "");
    EXPECT_EQ(options_.log_disable(), false);
    EXPECT_EQ(options_.log_file(), "<stdout>");
    EXPECT_EQ(options_.log_files_count(), 10);
    EXPECT_EQ(options_.log_file_size(), 10*1024*1024);
    EXPECT_EQ(options_.log_level(), "SYS_NOTICE");
    EXPECT_EQ(options_.log_local(), false);
    EXPECT_EQ(options_.ifmap_server_url(), "");
    EXPECT_EQ(options_.ifmap_password(), "<PASSWORD>");
    EXPECT_EQ(options_.ifmap_user(), "control-node");
    EXPECT_EQ(options_.ifmap_certs_store(), "");
    EXPECT_EQ(options_.ifmap_stale_entries_cleanup_timeout(), 300);
    EXPECT_EQ(options_.ifmap_end_of_rib_timeout(), 10);
    EXPECT_EQ(options_.ifmap_peer_response_wait_time(), 60);
    EXPECT_EQ(options_.xmpp_port(), default_xmpp_port);
    EXPECT_EQ(options_.test_mode(), false);
    EXPECT_EQ(options_.sandesh_send_rate_limit(), 0);
    EXPECT_EQ(options_.gr_helper_bgp_enable(), false);
    EXPECT_EQ(options_.gr_helper_xmpp_enable(), false);
}

TEST_F(OptionsTest, DefaultConfFile) {
    int argc = 2;
    char *argv[argc];
    char argv_0[] = "options_test";
    char argv_1[] = "--conf_file=controller/src/control-node/contrail-control.conf";
    argv[0] = argv_0;
    argv[1] = argv_1;

    options_.Parse(evm_, argc, argv);<commit_msg>Fix control-node unit test by asserting for the correct default value for options_.sandesh_send_rate_limit(), which is not 0 but g_sandesh_constants.DEFAULT_SANDESH_SEND_RATELIMIT<commit_after>/*
 * Copyright (c) 2014 Juniper Networks, Inc. All rights reserved.
 */

#include <fstream>
#include <iostream>

#include <boost/asio/ip/host_name.hpp>

#include "base/contrail_ports.h"
#include "base/test/task_test_util.h"
#include "base/util.h"
#include "base/logging.h"
#include "base/test/task_test_util.h"
#include "control-node/options.h"
#include "io/event_manager.h"
#include "net/address_util.h"

using namespace std;
using namespace boost::asio::ip;

static uint16_t default_bgp_port = ContrailPorts::ControlBgp();
static uint16_t default_http_server_port = ContrailPorts::HttpPortControl();
static uint16_t default_xmpp_port = ContrailPorts::ControlXmpp();
static uint16_t default_discovery_port = ContrailPorts::DiscoveryServerPort();

class OptionsTest : public ::testing::Test {
protected:
    OptionsTest() { }

    virtual void SetUp() {
        boost::system::error_code error;
        hostname_ = host_name(error);
        host_ip_ = GetHostIp(evm_.io_service(), hostname_);
        default_collector_server_list_.push_back("127.0.0.1:8086");
    }

    virtual void TearDown() {
        remove("./options_test_config_file.conf");
    }

    EventManager evm_;
    std::string hostname_;
    std::string host_ip_;
    std::vector<std::string> default_collector_server_list_;
    Options options_;
};

TEST_F(OptionsTest, NoArguments) {
    int argc = 1;
    char *argv[argc];
    char argv_0[] = "options_test";
    argv[0] = argv_0;

    options_.Parse(evm_, argc, argv);

    EXPECT_EQ(options_.bgp_config_file(), "bgp_config.xml");
    EXPECT_EQ(options_.bgp_port(), default_bgp_port);
    TASK_UTIL_EXPECT_VECTOR_EQ(default_collector_server_list_,
                     options_.collector_server_list());
    EXPECT_EQ(options_.config_file(), "/etc/contrail/contrail-control.conf");
    EXPECT_EQ(options_.discovery_server(), "127.0.0.1");
    EXPECT_EQ(options_.discovery_port(), default_discovery_port);
    EXPECT_EQ(options_.hostname(), hostname_);
    EXPECT_EQ(options_.host_ip(), host_ip_);
    EXPECT_EQ(options_.http_server_port(), default_http_server_port);
    EXPECT_EQ(options_.log_category(), "");
    EXPECT_EQ(options_.log_disable(), false);
    EXPECT_EQ(options_.log_file(), "<stdout>");
    EXPECT_EQ(options_.log_files_count(), 10);
    EXPECT_EQ(options_.log_file_size(), 10*1024*1024);
    EXPECT_EQ(options_.log_level(), "SYS_NOTICE");
    EXPECT_EQ(options_.log_local(), false);
    EXPECT_EQ(options_.ifmap_server_url(), "");
    EXPECT_EQ(options_.ifmap_password(), "<PASSWORD>");
    EXPECT_EQ(options_.ifmap_user(), "control-node");
    EXPECT_EQ(options_.ifmap_certs_store(), "");
    EXPECT_EQ(options_.ifmap_stale_entries_cleanup_timeout(), 300);
    EXPECT_EQ(options_.ifmap_end_of_rib_timeout(), 10);
    EXPECT_EQ(options_.ifmap_peer_response_wait_time(), 60);
    EXPECT_EQ(options_.xmpp_port(), default_xmpp_port);
    EXPECT_EQ(options_.test_mode(), false);
    EXPECT_EQ(options_.sandesh_send_rate_limit(),
              g_sandesh_constants.DEFAULT_SANDESH_SEND_RATELIMIT);
    EXPECT_EQ(options_.gr_helper_bgp_enable(), false);
    EXPECT_EQ(options_.gr_helper_xmpp_enable(), false);
}

TEST_F(OptionsTest, DefaultConfFile) {
    int argc = 2;
    char *argv[argc];
    char argv_0[] = "options_test";
    char argv_1[] = "--conf_file=controller/src/control-node/contrail-control.conf";
    argv[0] = argv_0;
    argv[1] = argv_1;

    options_.Parse(evm_, argc, argv);
{'fraction_non_alphanumeric': 0.1360980475986889, 'fraction_numerical': 0.016816303263502922, 'mean_word_length': 5.034393809114359, 'pattern_counts': {'":': 0, '<': 15, '<?xml version=': 0, '>': 15, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 2}, 'pii_count': 4, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '5985536', 'n_tokens_mistral': 2487, 'n_tokens_neox': 2448, 'n_words': 363}