-
Notifications
You must be signed in to change notification settings - Fork 34
Fixes #571 - Notify Users about out of date pack #590
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Conversation
kristiankunc
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'd honestly love to see at least partial test coverage on this.
|
I'll write some in a bit |
|
The copilot comments about the files also look sensible, we can just throw an error instantly (which can be surpressed as I assume we don't want to enforce it 100%) + the rest are some nitpicks |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Pull request overview
Copilot reviewed 6 out of 6 changed files in this pull request and generated 7 comments.
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
| #include "filestatus/FileStatusModule.h" | ||
| #include "bootstrap/PersistenceContainer.h" | ||
| #include "curl/CurlInterface.h" | ||
| #include "curl/CurlRequest.h" | ||
| #include "curl/CurlResponse.h" | ||
|
|
||
| #include <gmock/gmock.h> | ||
| #include <gtest/gtest.h> | ||
| #include <fstream> | ||
| #include <filesystem> | ||
|
|
||
| using ::testing::NiceMock; | ||
| using ::testing::Return; | ||
| using ::testing::Test; | ||
|
|
||
| namespace UKControllerPluginTest { | ||
| namespace FileStatus { | ||
|
|
||
| // Mock Curl interface | ||
| class MockCurlInterface : public UKControllerPlugin::Curl::CurlInterface | ||
| { | ||
| public: | ||
| MOCK_METHOD( | ||
| UKControllerPlugin::Curl::CurlResponse, | ||
| MakeCurlRequest, | ||
| (const UKControllerPlugin::Curl::CurlRequest& request), | ||
| (override)); | ||
| }; | ||
|
|
||
| class FileStatusModuleTest : public Test | ||
| { | ||
| protected: | ||
| virtual void SetUp() | ||
| { | ||
| // Create temp directory for test files | ||
| testDir = std::filesystem::temp_directory_path() / "filestatus_test"; | ||
| std::filesystem::create_directories(testDir); | ||
| } | ||
|
|
||
| virtual void TearDown() | ||
| { | ||
| // Clean up temp files | ||
| if (std::filesystem::exists(testDir)) { | ||
| std::filesystem::remove_all(testDir); | ||
| } | ||
| if (std::filesystem::exists("./UK")) { | ||
| std::filesystem::remove_all("./UK"); | ||
| } | ||
| } | ||
|
|
||
| std::filesystem::path testDir; | ||
| }; | ||
|
|
||
| // Test FetchPackVersion with successful response | ||
| TEST_F(FileStatusModuleTest, FetchPackVersionReturnsVersionOnSuccess) | ||
| { | ||
| NiceMock<MockCurlInterface> mockCurl; | ||
| UKControllerPlugin::Curl::CurlResponse response("abc123def456", false, 200); | ||
|
|
||
| EXPECT_CALL(mockCurl, MakeCurlRequest).WillOnce(Return(response)); | ||
|
|
||
| std::string result = UKControllerPlugin::FileStatus::FetchPackVersion(mockCurl); | ||
| EXPECT_EQ(result, "abc123def456"); | ||
| } | ||
|
|
||
| // Test FetchPackVersion with whitespace trimming | ||
| TEST_F(FileStatusModuleTest, FetchPackVersionTrimsWhitespace) | ||
| { | ||
| NiceMock<MockCurlInterface> mockCurl; | ||
| UKControllerPlugin::Curl::CurlResponse response(" abc123def456 \n\t", false, 200); | ||
|
|
||
| EXPECT_CALL(mockCurl, MakeCurlRequest).WillOnce(Return(response)); | ||
|
|
||
| std::string result = UKControllerPlugin::FileStatus::FetchPackVersion(mockCurl); | ||
| EXPECT_EQ(result, "abc123def456"); | ||
| } | ||
|
|
||
| // Test FetchPackVersion with non-200 status code | ||
| TEST_F(FileStatusModuleTest, FetchPackVersionReturnsEmptyOnBadStatusCode) | ||
| { | ||
| NiceMock<MockCurlInterface> mockCurl; | ||
| UKControllerPlugin::Curl::CurlResponse response("Not Found", false, 404); | ||
|
|
||
| EXPECT_CALL(mockCurl, MakeCurlRequest).WillOnce(Return(response)); | ||
|
|
||
| std::string result = UKControllerPlugin::FileStatus::FetchPackVersion(mockCurl); | ||
| EXPECT_EQ(result, ""); | ||
| } | ||
|
|
||
| // Test FetchPackVersion with exception | ||
| TEST_F(FileStatusModuleTest, FetchPackVersionReturnsEmptyOnException) | ||
| { | ||
| NiceMock<MockCurlInterface> mockCurl; | ||
|
|
||
| EXPECT_CALL(mockCurl, MakeCurlRequest).WillOnce(::testing::Throw(std::runtime_error("Network error"))); | ||
|
|
||
| std::string result = UKControllerPlugin::FileStatus::FetchPackVersion(mockCurl); | ||
| EXPECT_EQ(result, ""); | ||
| } | ||
|
|
||
| } // namespace FileStatus | ||
| } // namespace UKControllerPluginTest No newline at end of file |
Copilot
AI
Nov 30, 2025
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Missing test coverage for CheckSectorFileProviderFile function. This function contains complex logic for parsing the sector file provider configuration and URL extraction that should be tested, especially the edge case where the line is exactly "URL:" without any actual URL content.
| #include "filestatus/FileStatusModule.h" | ||
| #include "bootstrap/PersistenceContainer.h" | ||
| #include "curl/CurlInterface.h" | ||
| #include "curl/CurlRequest.h" | ||
| #include "curl/CurlResponse.h" | ||
|
|
||
| #include <gmock/gmock.h> | ||
| #include <gtest/gtest.h> | ||
| #include <fstream> | ||
| #include <filesystem> | ||
|
|
||
| using ::testing::NiceMock; | ||
| using ::testing::Return; | ||
| using ::testing::Test; | ||
|
|
||
| namespace UKControllerPluginTest { | ||
| namespace FileStatus { | ||
|
|
||
| // Mock Curl interface | ||
| class MockCurlInterface : public UKControllerPlugin::Curl::CurlInterface | ||
| { | ||
| public: | ||
| MOCK_METHOD( | ||
| UKControllerPlugin::Curl::CurlResponse, | ||
| MakeCurlRequest, | ||
| (const UKControllerPlugin::Curl::CurlRequest& request), | ||
| (override)); | ||
| }; | ||
|
|
||
| class FileStatusModuleTest : public Test | ||
| { | ||
| protected: | ||
| virtual void SetUp() | ||
| { | ||
| // Create temp directory for test files | ||
| testDir = std::filesystem::temp_directory_path() / "filestatus_test"; | ||
| std::filesystem::create_directories(testDir); | ||
| } | ||
|
|
||
| virtual void TearDown() | ||
| { | ||
| // Clean up temp files | ||
| if (std::filesystem::exists(testDir)) { | ||
| std::filesystem::remove_all(testDir); | ||
| } | ||
| if (std::filesystem::exists("./UK")) { | ||
| std::filesystem::remove_all("./UK"); | ||
| } | ||
| } | ||
|
|
||
| std::filesystem::path testDir; | ||
| }; | ||
|
|
||
| // Test FetchPackVersion with successful response | ||
| TEST_F(FileStatusModuleTest, FetchPackVersionReturnsVersionOnSuccess) | ||
| { | ||
| NiceMock<MockCurlInterface> mockCurl; | ||
| UKControllerPlugin::Curl::CurlResponse response("abc123def456", false, 200); | ||
|
|
||
| EXPECT_CALL(mockCurl, MakeCurlRequest).WillOnce(Return(response)); | ||
|
|
||
| std::string result = UKControllerPlugin::FileStatus::FetchPackVersion(mockCurl); | ||
| EXPECT_EQ(result, "abc123def456"); | ||
| } | ||
|
|
||
| // Test FetchPackVersion with whitespace trimming | ||
| TEST_F(FileStatusModuleTest, FetchPackVersionTrimsWhitespace) | ||
| { | ||
| NiceMock<MockCurlInterface> mockCurl; | ||
| UKControllerPlugin::Curl::CurlResponse response(" abc123def456 \n\t", false, 200); | ||
|
|
||
| EXPECT_CALL(mockCurl, MakeCurlRequest).WillOnce(Return(response)); | ||
|
|
||
| std::string result = UKControllerPlugin::FileStatus::FetchPackVersion(mockCurl); | ||
| EXPECT_EQ(result, "abc123def456"); | ||
| } | ||
|
|
||
| // Test FetchPackVersion with non-200 status code | ||
| TEST_F(FileStatusModuleTest, FetchPackVersionReturnsEmptyOnBadStatusCode) | ||
| { | ||
| NiceMock<MockCurlInterface> mockCurl; | ||
| UKControllerPlugin::Curl::CurlResponse response("Not Found", false, 404); | ||
|
|
||
| EXPECT_CALL(mockCurl, MakeCurlRequest).WillOnce(Return(response)); | ||
|
|
||
| std::string result = UKControllerPlugin::FileStatus::FetchPackVersion(mockCurl); | ||
| EXPECT_EQ(result, ""); | ||
| } | ||
|
|
||
| // Test FetchPackVersion with exception | ||
| TEST_F(FileStatusModuleTest, FetchPackVersionReturnsEmptyOnException) | ||
| { | ||
| NiceMock<MockCurlInterface> mockCurl; | ||
|
|
||
| EXPECT_CALL(mockCurl, MakeCurlRequest).WillOnce(::testing::Throw(std::runtime_error("Network error"))); | ||
|
|
||
| std::string result = UKControllerPlugin::FileStatus::FetchPackVersion(mockCurl); | ||
| EXPECT_EQ(result, ""); | ||
| } | ||
|
|
||
| } // namespace FileStatus | ||
| } // namespace UKControllerPluginTest No newline at end of file |
Copilot
AI
Nov 30, 2025
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Missing test coverage for CheckPackVersion function. The test file only covers FetchPackVersion, but CheckPackVersion contains critical logic including file reading, version comparison, and message box display that should be tested.
| } | ||
|
|
||
| } catch (const std::exception& e) { | ||
| LogError("Exception when checking UK Controller Pack version"); |
Copilot
AI
Nov 30, 2025
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The error message lacks detail about what exception occurred. It should include the exception message using e.what() to aid in debugging, similar to the error handling in FetchPackVersion on line 42.
| LogError("Exception when checking UK Controller Pack version"); | |
| LogError("Exception when checking UK Controller Pack version: " + std::string(e.what())); |
| LogError("Could not find URL in sector file provider"); | ||
| } | ||
|
|
||
| if (extractedUrl != SECTOR_FILE_DOWNLOADER_LINK) { |
Copilot
AI
Nov 30, 2025
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The comparison should trim whitespace from extractedUrl before comparing it to SECTOR_FILE_DOWNLOADER_LINK. The current implementation will fail if the URL in the file has leading/trailing whitespace, even though it may be functionally correct.
Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
Fixes #571