Patrick Williams | 16f0efa | 2025-06-25 23:24:44 -0400 | [diff] [blame^] | 1 | #include "user_mgr.hpp" |
| 2 | |
| 3 | #include <gtest/gtest.h> |
| 4 | |
| 5 | TEST(ExecuteCmdTest, CommandReturnsEmptyOutput) |
| 6 | { |
| 7 | std::vector<std::string> output = phosphor::user::executeCmd("/bin/true"); |
| 8 | ASSERT_TRUE(output.empty()); |
| 9 | } |
| 10 | |
| 11 | TEST(ExecuteCmdTest, CommandWithArgs) |
| 12 | { |
| 13 | std::vector<std::string> output = phosphor::user::executeCmd( |
| 14 | "/bin/echo", "testing", "with", "multiple", "args"); |
| 15 | ASSERT_EQ(output.size(), 1); |
| 16 | EXPECT_EQ(output[0], "testing with multiple args"); |
| 17 | } |
| 18 | |
| 19 | TEST(ExecuteCmdTest, CommandReturnsOutput) |
| 20 | { |
| 21 | std::vector<std::string> output = |
| 22 | phosphor::user::executeCmd("/bin/echo", "-e", "hello\\nworld"); |
| 23 | ASSERT_EQ(output.size(), 2); |
| 24 | EXPECT_EQ(output[0], "hello"); |
| 25 | EXPECT_EQ(output[1], "world"); |
| 26 | } |
| 27 | |
| 28 | TEST(ExecuteCmdTest, NonExistentCommand) |
| 29 | { |
| 30 | EXPECT_THROW(phosphor::user::executeCmd("/path/to/nonexistent_command"), |
| 31 | boost::process::process_error); |
| 32 | } |
| 33 | |
| 34 | TEST(ExecuteCmdTest, CommandReturnsNonZeroExitCode) |
| 35 | { |
| 36 | EXPECT_THROW( |
| 37 | phosphor::user::executeCmd("/bin/false"), |
| 38 | sdbusplus::xyz::openbmc_project::Common::Error::InternalFailure); |
| 39 | } |