From 594d294e8f47ddb5db1a05a3328d7a8aef073bfa Mon Sep 17 00:00:00 2001 From: Yongjoo Ahn Date: Wed, 3 Apr 2024 13:00:03 +0900 Subject: [PATCH] [test] Add unit tests for plugin-parser - Add more tests covering more functions for plugin other than "INSTALL" function. Signed-off-by: Yongjoo Ahn --- plugin-parser/mlops-plugin-parser.cc | 5 +- .../plugin-parser/unittest_mlops_plugin_parser.cc | 117 +++++++++++++++++---- 2 files changed, 96 insertions(+), 26 deletions(-) diff --git a/plugin-parser/mlops-plugin-parser.cc b/plugin-parser/mlops-plugin-parser.cc index eaa7399..461d4ce 100644 --- a/plugin-parser/mlops-plugin-parser.cc +++ b/plugin-parser/mlops-plugin-parser.cc @@ -569,10 +569,9 @@ extern "C" int PKGMGR_MDPARSER_PLUGIN_UPGRADE (const char *pkgid, const char *appid, GList *metadata) { _I ("PKGMGR_MDPARSER_PLUGIN_UPGRADE called"); - PKGMGR_MDPARSER_PLUGIN_UNINSTALL (pkgid, appid, metadata); - PKGMGR_MDPARSER_PLUGIN_INSTALL (pkgid, appid, metadata); - return 0; + PKGMGR_MDPARSER_PLUGIN_UNINSTALL (pkgid, appid, metadata); + return PKGMGR_MDPARSER_PLUGIN_INSTALL (pkgid, appid, metadata); } /** diff --git a/tests/plugin-parser/unittest_mlops_plugin_parser.cc b/tests/plugin-parser/unittest_mlops_plugin_parser.cc index 7db85d6..7946042 100644 --- a/tests/plugin-parser/unittest_mlops_plugin_parser.cc +++ b/tests/plugin-parser/unittest_mlops_plugin_parser.cc @@ -178,7 +178,7 @@ GModule *PkgMgrInfoMockTestFixture::module = nullptr; /** * @brief Negative test case of pkgmgrinfo_pkginfo_get_pkginfo() failed. */ -TEST_F (PkgMgrInfoMockTestFixture, rpk_install_n1) +TEST_F (PkgMgrInfoMockTestFixture, rpk_install1_n) { std::string pkgid = "pkgid"; std::string appid = "appid"; @@ -192,7 +192,7 @@ TEST_F (PkgMgrInfoMockTestFixture, rpk_install_n1) /** * @brief Negative test case of pkgmgrinfo_pkginfo_get_type() failed. */ -TEST_F (PkgMgrInfoMockTestFixture, rpk_install_n2) +TEST_F (PkgMgrInfoMockTestFixture, rpk_install2_n) { std::string pkgid = "pkgid"; std::string appid = "appid"; @@ -212,7 +212,7 @@ TEST_F (PkgMgrInfoMockTestFixture, rpk_install_n2) /** * @brief Negative test case of pkgmgrinfo_pkginfo_get_root_path() failed. */ -TEST_F (PkgMgrInfoMockTestFixture, rpk_install_n3) +TEST_F (PkgMgrInfoMockTestFixture, rpk_install3_n) { std::string pkgid = "pkgid"; std::string appid = "appid"; @@ -237,7 +237,7 @@ TEST_F (PkgMgrInfoMockTestFixture, rpk_install_n3) /** * @brief Negative test case of pkgmgrinfo_pkginfo_get_res_type() failed. */ -TEST_F (PkgMgrInfoMockTestFixture, rpk_install_n4) +TEST_F (PkgMgrInfoMockTestFixture, rpk_install4_n) { std::string pkgid = "pkgid"; std::string appid = "appid"; @@ -265,7 +265,7 @@ TEST_F (PkgMgrInfoMockTestFixture, rpk_install_n4) /** * @brief Negative test case of pkgmgrinfo_pkginfo_get_res_version() failed. */ -TEST_F (PkgMgrInfoMockTestFixture, rpk_install_n5) +TEST_F (PkgMgrInfoMockTestFixture, rpk_install5_n) { std::string pkgid = "pkgid"; std::string appid = "appid"; @@ -296,7 +296,7 @@ TEST_F (PkgMgrInfoMockTestFixture, rpk_install_n5) /** * @brief Negative test case of invalid config file. */ -TEST_F (PkgMgrInfoMockTestFixture, rpk_install_n6) +TEST_F (PkgMgrInfoMockTestFixture, rpk_install6_n) { std::string pkgid = "pkgid"; std::string appid = "appid"; @@ -333,7 +333,7 @@ TEST_F (PkgMgrInfoMockTestFixture, rpk_install_n6) /** * @brief Negative test case of invalid config file. */ -TEST_F (PkgMgrInfoMockTestFixture, rpk_install_n7) +TEST_F (PkgMgrInfoMockTestFixture, rpk_install7_n) { std::string pkgid = "pkgid"; std::string appid = "appid"; @@ -368,9 +368,9 @@ TEST_F (PkgMgrInfoMockTestFixture, rpk_install_n7) } /** - * @brief Positive test case of sample rpk package install. + * @brief Positive test case of tpk package. */ -TEST_F (PkgMgrInfoMockTestFixture, rpk_install_p1) +TEST_F (PkgMgrInfoMockTestFixture, tpk_install_p1) { std::string pkgid = "pkgid"; std::string appid = "appid"; @@ -381,49 +381,120 @@ TEST_F (PkgMgrInfoMockTestFixture, rpk_install_p1) EXPECT_CALL(*pkgMgrInfoMockInstance, pkgmgrinfo_pkginfo_get_pkginfo (_, _)) .WillOnce (Return (PMINFO_R_OK)); + char pkg_type_tpk[] = "tpk"; + EXPECT_CALL(*pkgMgrInfoMockInstance, pkgmgrinfo_pkginfo_get_type (_, _)) + .WillOnce (DoAll (SetArgPointee<1> (pkg_type_tpk), + Return (PMINFO_R_OK))); + + EXPECT_EQ (exec_plugin_parser_func ("PKGMGR_MDPARSER_PLUGIN_INSTALL", pkgid, appid, NULL), 0); +} + +/** + * @brief Positive test case of sample rpk package install/upgrade/uninstall. + */ +TEST_F (PkgMgrInfoMockTestFixture, rpk_scenario_p1) +{ + std::string pkgid = "pkgid"; + std::string appid = "appid"; + + EXPECT_CALL (*pkgMgrInfoMockInstance, pkgmgrinfo_pkginfo_destroy_pkginfo (_)) + .WillRepeatedly (Return (PMINFO_R_OK)); + + EXPECT_CALL(*pkgMgrInfoMockInstance, pkgmgrinfo_pkginfo_get_pkginfo (_, _)) + .WillRepeatedly (Return (PMINFO_R_OK)); + char pkg_type_rpk[] = "rpk"; EXPECT_CALL(*pkgMgrInfoMockInstance, pkgmgrinfo_pkginfo_get_type (_, _)) - .WillOnce (DoAll (SetArgPointee<1> (pkg_type_rpk), + .WillRepeatedly (DoAll (SetArgPointee<1> (pkg_type_rpk), Return (PMINFO_R_OK))); char root_path[] = "../tests/plugin-parser/test_rpk_samples/working_rpk"; EXPECT_CALL(*pkgMgrInfoMockInstance, pkgmgrinfo_pkginfo_get_root_path (_, _)) - .WillOnce (DoAll (SetArgPointee<1> (root_path), + .WillRepeatedly (DoAll (SetArgPointee<1> (root_path), Return (PMINFO_R_OK))); char res_type[] = "sample-res-type"; EXPECT_CALL(*pkgMgrInfoMockInstance, pkgmgrinfo_pkginfo_get_res_type (_, _)) - .WillOnce (DoAll (SetArgPointee<1> (res_type), + .WillRepeatedly (DoAll (SetArgPointee<1> (res_type), Return (PMINFO_R_OK))); char res_version[] = "1.5.0"; EXPECT_CALL(*pkgMgrInfoMockInstance, pkgmgrinfo_pkginfo_get_res_version (_, _)) - .WillOnce (DoAll (SetArgPointee<1> (res_version), + .WillRepeatedly (DoAll (SetArgPointee<1> (res_version), Return (PMINFO_R_OK))); + // install rpk EXPECT_EQ (exec_plugin_parser_func ("PKGMGR_MDPARSER_PLUGIN_INSTALL", pkgid, appid, NULL), 0); + + // upgrade rpk + EXPECT_EQ (exec_plugin_parser_func ("PKGMGR_MDPARSER_PLUGIN_UPGRADE", pkgid, appid, NULL), 0); + + // uninstall the rpk + EXPECT_EQ (exec_plugin_parser_func ("PKGMGR_MDPARSER_PLUGIN_UNINSTALL", pkgid, appid, NULL), 0); } /** - * @brief Positive test case of tpk package. + * @brief Negative test case of RECOVERINSTALL. */ -TEST_F (PkgMgrInfoMockTestFixture, tpk_install_p1) +TEST_F (PkgMgrInfoMockTestFixture, RECOVERINSTALL_n) { std::string pkgid = "pkgid"; std::string appid = "appid"; - EXPECT_CALL (*pkgMgrInfoMockInstance, pkgmgrinfo_pkginfo_destroy_pkginfo (_)) - .WillRepeatedly (Return (PMINFO_R_OK)); + EXPECT_CALL(*pkgMgrInfoMockInstance, pkgmgrinfo_pkginfo_get_pkginfo (_, _)) + .WillOnce (Return (PMINFO_R_ERROR)); + + EXPECT_NE (exec_plugin_parser_func ("PKGMGR_MDPARSER_PLUGIN_RECOVERINSTALL", pkgid, appid, NULL), 0); +} + +/** + * @brief Negative test case of RECOVERUPGRADE. + */ +TEST_F (PkgMgrInfoMockTestFixture, RECOVERUPGRADE_n) +{ + std::string pkgid = "pkgid"; + std::string appid = "appid"; EXPECT_CALL(*pkgMgrInfoMockInstance, pkgmgrinfo_pkginfo_get_pkginfo (_, _)) - .WillOnce (Return (PMINFO_R_OK)); + .WillRepeatedly (Return (PMINFO_R_ERROR)); - char pkg_type_tpk[] = "tpk"; - EXPECT_CALL(*pkgMgrInfoMockInstance, pkgmgrinfo_pkginfo_get_type (_, _)) - .WillOnce (DoAll (SetArgPointee<1> (pkg_type_tpk), - Return (PMINFO_R_OK))); + EXPECT_NE (exec_plugin_parser_func ("PKGMGR_MDPARSER_PLUGIN_RECOVERUPGRADE", pkgid, appid, NULL), 0); +} - EXPECT_EQ (exec_plugin_parser_func ("PKGMGR_MDPARSER_PLUGIN_INSTALL", pkgid, appid, NULL), 0); +/** + * @brief Negative test case of RECOVERUNINSTALL. + */ +TEST_F (PkgMgrInfoMockTestFixture, RECOVERUNINSTALL_n) +{ + std::string pkgid = "pkgid"; + std::string appid = "appid"; + + EXPECT_CALL(*pkgMgrInfoMockInstance, pkgmgrinfo_pkginfo_get_pkginfo (_, _)) + .WillOnce (Return (PMINFO_R_ERROR)); + + EXPECT_NE (exec_plugin_parser_func ("PKGMGR_MDPARSER_PLUGIN_RECOVERUNINSTALL", pkgid, appid, NULL), 0); +} + +/** + * @brief Positive test case of CLEAN. + */ +TEST_F (PkgMgrInfoMockTestFixture, clean_p1) +{ + std::string pkgid = "pkgid"; + std::string appid = "appid"; + + EXPECT_EQ (exec_plugin_parser_func ("PKGMGR_MDPARSER_PLUGIN_CLEAN", pkgid, appid, NULL), 0); +} + +/** + * @brief Positive test case of UNDO. + */ +TEST_F (PkgMgrInfoMockTestFixture, undo_p1) +{ + std::string pkgid = "pkgid"; + std::string appid = "appid"; + + EXPECT_EQ (exec_plugin_parser_func ("PKGMGR_MDPARSER_PLUGIN_UNDO", pkgid, appid, NULL), 0); } /** -- 2.7.4