in core/unittest/config/PipelineConfigUnittest.cpp [1321:1562]
void PipelineConfigUnittest::HandleInvalidInputs() const {
unique_ptr<Json::Value> configJson;
string configStr, errorMsg;
unique_ptr<CollectionConfig> config;
// no inputs
configStr = R"(
{
"flushers": [
{
"Type": "flusher_sls"
}
]
}
)";
configJson.reset(new Json::Value());
APSARA_TEST_TRUE(ParseJsonTable(configStr, *configJson, errorMsg));
config.reset(new CollectionConfig(configName, std::move(configJson)));
APSARA_TEST_FALSE(config->Parse());
// inputs is not of type array
configStr = R"(
{
"inputs": {},
"flushers": [
{
"Type": "flusher_sls"
}
]
}
)";
configJson.reset(new Json::Value());
APSARA_TEST_TRUE(ParseJsonTable(configStr, *configJson, errorMsg));
config.reset(new CollectionConfig(configName, std::move(configJson)));
APSARA_TEST_FALSE(config->Parse());
// inputs is empty
configStr = R"(
{
"inputs": [],
"flushers": [
{
"Type": "flusher_sls"
}
]
}
)";
configJson.reset(new Json::Value());
APSARA_TEST_TRUE(ParseJsonTable(configStr, *configJson, errorMsg));
config.reset(new CollectionConfig(configName, std::move(configJson)));
APSARA_TEST_FALSE(config->Parse());
// inputs element is not of type object
configStr = R"(
{
"inputs": [
[]
],
"flushers": [
{
"Type": "flusher_sls"
}
]
}
)";
configJson.reset(new Json::Value());
APSARA_TEST_TRUE(ParseJsonTable(configStr, *configJson, errorMsg));
config.reset(new CollectionConfig(configName, std::move(configJson)));
APSARA_TEST_FALSE(config->Parse());
// no Type
configStr = R"(
{
"inputs": [
{
"type": "input_file"
}
],
"flushers": [
{
"Type": "flusher_sls"
}
]
}
)";
configJson.reset(new Json::Value());
APSARA_TEST_TRUE(ParseJsonTable(configStr, *configJson, errorMsg));
config.reset(new CollectionConfig(configName, std::move(configJson)));
APSARA_TEST_FALSE(config->Parse());
// Type is not of type string
configStr = R"(
{
"inputs": [
{
"Type": true
}
],
"flushers": [
{
"Type": "flusher_sls"
}
]
}
)";
configJson.reset(new Json::Value());
APSARA_TEST_TRUE(ParseJsonTable(configStr, *configJson, errorMsg));
config.reset(new CollectionConfig(configName, std::move(configJson)));
APSARA_TEST_FALSE(config->Parse());
// unsupported input
configStr = R"(
{
"inputs": [
{
"Type": "input_unknown"
}
],
"flushers": [
{
"Type": "flusher_sls"
}
]
}
)";
configJson.reset(new Json::Value());
APSARA_TEST_TRUE(ParseJsonTable(configStr, *configJson, errorMsg));
config.reset(new CollectionConfig(configName, std::move(configJson)));
APSARA_TEST_TRUE(config->Parse());
configStr = R"(
{
"inputs": [
{
"Type": "input_file"
},
{
"Type": "input_unknown"
}
],
"flushers": [
{
"Type": "flusher_sls"
}
]
}
)";
configJson.reset(new Json::Value());
APSARA_TEST_TRUE(ParseJsonTable(configStr, *configJson, errorMsg));
config.reset(new CollectionConfig(configName, std::move(configJson)));
APSARA_TEST_FALSE(config->Parse());
configStr = R"(
{
"inputs": [
{
"Type": "service_docker_stdout"
},
{
"Type": "input_unknown"
}
],
"flushers": [
{
"Type": "flusher_sls"
}
]
}
)";
configJson.reset(new Json::Value());
APSARA_TEST_TRUE(ParseJsonTable(configStr, *configJson, errorMsg));
config.reset(new CollectionConfig(configName, std::move(configJson)));
APSARA_TEST_TRUE(config->Parse());
// more than 1 native input
configStr = R"(
{
"inputs": [
{
"Type": "input_file"
},
{
"Type": "input_file"
}
],
"flushers": [
{
"Type": "flusher_sls"
}
]
}
)";
configJson.reset(new Json::Value());
APSARA_TEST_TRUE(ParseJsonTable(configStr, *configJson, errorMsg));
config.reset(new CollectionConfig(configName, std::move(configJson)));
APSARA_TEST_FALSE(config->Parse());
// native and extended inputs coexist
configStr = R"(
{
"inputs": [
{
"Type": "input_file"
},
{
"Type": "service_docker_stdout"
}
],
"flushers": [
{
"Type": "flusher_sls"
}
]
}
)";
configJson.reset(new Json::Value());
APSARA_TEST_TRUE(ParseJsonTable(configStr, *configJson, errorMsg));
config.reset(new CollectionConfig(configName, std::move(configJson)));
APSARA_TEST_FALSE(config->Parse());
configStr = R"(
{
"inputs": [
{
"Type": "service_docker_stdoutinput_file"
},
{
"Type": "input_file"
}
],
"flushers": [
{
"Type": "flusher_sls"
}
]
}
)";
configJson.reset(new Json::Value());
APSARA_TEST_TRUE(ParseJsonTable(configStr, *configJson, errorMsg));
config.reset(new CollectionConfig(configName, std::move(configJson)));
APSARA_TEST_FALSE(config->Parse());
}