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_NE(ret, std::nullopt); 19 EXPECT_EQ(ret->tftpServer, "1.1.1.1"); 20 EXPECT_EQ(ret->fwFile, "path"); 21 } 22 { 23 // Protocol, no schema on url 24 std::optional<TftpUrl> ret = parseTftpUrl("1.1.1.1/path", "TFTP", res); 25 ASSERT_NE(ret, std::nullopt); 26 EXPECT_EQ(ret->tftpServer, "1.1.1.1"); 27 EXPECT_EQ(ret->fwFile, "path"); 28 } 29 { 30 // Both protocl and schema on url 31 std::optional<TftpUrl> ret = parseTftpUrl("tftp://1.1.1.1/path", "TFTP", 32 res); 33 ASSERT_NE(ret, std::nullopt); 34 EXPECT_EQ(ret->tftpServer, "1.1.1.1"); 35 EXPECT_EQ(ret->fwFile, "path"); 36 } 37 } 38 39 TEST(UpdateService, ParseTFTPNegative) 40 { 41 crow::Response res; 42 // No protocol, no schema 43 ASSERT_EQ(parseTftpUrl("1.1.1.1/path", std::nullopt, res), std::nullopt); 44 // No host 45 ASSERT_EQ(parseTftpUrl("/path", "TFTP", res), std::nullopt); 46 47 // No host 48 ASSERT_EQ(parseTftpUrl("path", "TFTP", res), std::nullopt); 49 50 // No path 51 ASSERT_EQ(parseTftpUrl("tftp://1.1.1.1", "TFTP", res), std::nullopt); 52 ASSERT_EQ(parseTftpUrl("tftp://1.1.1.1/", "TFTP", res), std::nullopt); 53 } 54 } // namespace 55 } // namespace redfish 56