Repository: ossrs/srs
File: trunk/src/utest/srs_utest_config.cpp (C++)

Code before:
        EXPECT_STREQ("xxx2", conf.get_hls_ts_file("ossrs.net").c_str());
        EXPECT_EQ(10*SRS_UTIME_SECONDS, conf.get_hls_fragment("ossrs.net"));
        EXPECT_EQ(60*SRS_UTIME_SECONDS, conf.get_hls_window("ossrs.net"));
    }

    if (true) {
        MockSrsConfig conf;
        HELPER_ASSERT_SUCCESS(conf.parse("include ./conf/include_test/include_4.conf;"));

        vector<string> listens = conf.get_listens();
        EXPECT_EQ(1, (int)listens.size());
        EXPECT_STREQ("1935", listens.at(0).c_str());

        EXPECT_FALSE(conf.get_log_tank_file());

        EXPECT_TRUE(conf.get_http_stream_enabled());
        EXPECT_STREQ("xxx", conf.get_http_stream_listen().c_str());
        EXPECT_STREQ("xxx2", conf.get_http_stream_dir().c_str());

        EXPECT_TRUE(conf.get_hls_enabled("ossrs.net"));
        EXPECT_STREQ("xxx", conf.get_hls_path("ossrs.net").c_str());
        EXPECT_STREQ("xxx1", conf.get_hls_m3u8_file("ossrs.net").c_str());
        EXPECT_STREQ("xxx2", conf.get_hls_ts_file("ossrs.net").c_str());
        EXPECT_EQ(10*SRS_UTIME_SECONDS, conf.get_hls_fragment("ossrs.net"));
        EXPECT_EQ(60*SRS_UTIME_SECONDS, conf.get_hls_window("ossrs.net"));

        EXPECT_TRUE(conf.get_http_api_enabled());
        EXPECT_STREQ("xxx", conf.get_http_api_listen().c_str());
    }
}


Review comment (suggestion):
Do not write the configuration of the test under the 'conf' directory, you need to modify the mock to support 'include'. That means reading this mock value from a memory string. You can set it, for example:

```
MockSrsConfig conf;
`conf.mock_include("./conf/include_test/include.conf", "configuration content");`
```

When reading this file, it is still recommended to use mock to read it.

The code logic may need to support mocking and should not directly read from the file.

`TRANS_BY_GPT3`

Code after:
        EXPECT_TRUE(conf.get_heartbeat_enabled());
        EXPECT_EQ(10*SRS_UTIME_SECONDS, conf.get_heartbeat_interval());
        EXPECT_STREQ("xxx", conf.get_heartbeat_url().c_str());
        EXPECT_STREQ("xxx2", conf.get_heartbeat_device_id().c_str());
        EXPECT_TRUE(conf.get_heartbeat_summaries());
    }

    if (true) {
        MockSrsConfig conf;
        HELPER_ASSERT_SUCCESS(conf.parse(_MIN_OK_CONF "stats{network 0;disk xxx;}"));
        EXPECT_EQ(0, (int)conf.get_stats_network());
        EXPECT_TRUE(conf.get_stats_disk_device() != NULL);
    }
}

VOID TEST(ConfigMainTest, CheckIncludeConfig)
{
    srs_error_t err;

    if (true) {
        MockSrsConfig conf;

        conf.mock_include("./conf/include_test/include.conf", "listen 1935;include ./conf/include_test/include_1.conf;");
        conf.mock_include("./conf/include_test/include_1.conf", "max_connections 1000;daemon off;srs_log_tank console;http_server {enabled on;listen xxx;dir xxx2;}vhost ossrs.net {hls {enabled on;hls_path xxx;hls_m3u8_file xxx1;hls_ts_file xxx2;hls_fragment 10;hls_window 60;}}");

        HELPER_ASSERT_SUCCESS(conf.parse("include ./conf/include_test/include.conf;"));

        vector<string> listens = conf.get_listens();
        EXPECT_EQ(1, (int)listens.size());
        EXPECT_STREQ("1935", listens.at(0).c_str());

        EXPECT_FALSE(conf.get_log_tank_file());

        EXPECT_TRUE(conf.get_http_stream_enabled());
        EXPECT_STREQ("xxx", conf.get_http_stream_listen().c_str());
        EXPECT_STREQ("xxx2", conf.get_http_stream_dir().c_str());

        EXPECT_TRUE(conf.get_hls_enabled("ossrs.net"));
        EXPECT_STREQ("xxx", conf.get_hls_path("ossrs.net").c_str());
        EXPECT_STREQ("xxx1", conf.get_hls_m3u8_file("ossrs.net").c_str());
        EXPECT_STREQ("xxx2", conf.get_hls_ts_file("ossrs.net").c_str());
        EXPECT_EQ(10*SRS_UTIME_SECONDS, conf.get_hls_fragment("ossrs.net"));
        EXPECT_EQ(60*SRS_UTIME_SECONDS, conf.get_hls_window("ossrs.net"));
    }

    if (true) {
        MockSrsConfig conf;

        conf.mock_include("./conf/include_test/include_1.conf", "max_connections 1000;daemon off;srs_log_tank console;http_server {enabled on;listen xxx;dir xxx2;}vhost ossrs.net {hls {enabled on;hls_path xxx;hls_m3u8_file xxx1;hls_ts_file xxx2;hls_fragment 10;hls_window 60;}}");

        HELPER_ASSERT_SUCCESS(conf.parse(_MIN_OK_CONF "include ./conf/include_test/include_1.conf;"));