1 2 #include "update_service.hpp" 3 4 #include <gtest/gtest.h> 5 6 namespace redfish 7 { 8 namespace 9 { 10 11 TEST(UpdateService, ParseTFTPPostitive) 12 { 13 crow::Response res; 14 { 15 // No protocol, schema on url 16 std::optional<TftpUrl> ret = parseTftpUrl("tftp://1.1.1.1/path", 17 std::nullopt, res); 18 ASSERT_TRUE(ret); 19 if (!ret) 20 { 21 return; 22 } 23 EXPECT_EQ(ret->tftpServer, "1.1.1.1"); 24 EXPECT_EQ(ret->fwFile, "path"); 25 } 26 { 27 // Protocol, no schema on url 28 std::optional<TftpUrl> ret = parseTftpUrl("1.1.1.1/path", "TFTP", res); 29 ASSERT_TRUE(ret); 30 if (!ret) 31 { 32 return; 33 } 34 EXPECT_EQ(ret->tftpServer, "1.1.1.1"); 35 EXPECT_EQ(ret->fwFile, "path"); 36 } 37 { 38 // Both protocl and schema on url 39 std::optional<TftpUrl> ret = parseTftpUrl("tftp://1.1.1.1/path", "TFTP", 40 res); 41 ASSERT_TRUE(ret); 42 if (!ret) 43 { 44 return; 45 } 46 EXPECT_EQ(ret->tftpServer, "1.1.1.1"); 47 EXPECT_EQ(ret->fwFile, "path"); 48 } 49 } 50 51 TEST(UpdateService, ParseTFTPNegative) 52 { 53 crow::Response res; 54 // No protocol, no schema 55 ASSERT_EQ(parseTftpUrl("1.1.1.1/path", std::nullopt, res), std::nullopt); 56 // No host 57 ASSERT_EQ(parseTftpUrl("/path", "TFTP", res), std::nullopt); 58 59 // No host 60 ASSERT_EQ(parseTftpUrl("path", "TFTP", res), std::nullopt); 61 62 // No path 63 ASSERT_EQ(parseTftpUrl("tftp://1.1.1.1", "TFTP", res), std::nullopt); 64 ASSERT_EQ(parseTftpUrl("tftp://1.1.1.1/", "TFTP", res), std::nullopt); 65 } 66 } // namespace 67 } // namespace redfish 68