Skip to content

Commit cb500b9

Browse files
Use writable test assets dir; simplify setup
Override SUNSHINE_ASSETS_DIR in tests to ${CMAKE_CURRENT_BINARY_DIR}/test_assets so tests use a writable assets directory. Update test_confighttp setup to create a temporary web directory, use std::filesystem::create_directories for WEB_DIR, and write test_page.html directly (removing the previous try/catch and existence checks). These changes simplify test setup and ensure test files are created in writable temp locations.
1 parent f51923d commit cb500b9

File tree

2 files changed

+13
-19
lines changed

2 files changed

+13
-19
lines changed

tests/CMakeLists.txt

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -79,6 +79,11 @@ list(APPEND TEST_DEFINITIONS SUNSHINE_TESTS)
7979
list(APPEND TEST_DEFINITIONS SUNSHINE_SOURCE_DIR="${CMAKE_SOURCE_DIR}")
8080
list(APPEND TEST_DEFINITIONS SUNSHINE_TEST_BIN_DIR="${CMAKE_CURRENT_BINARY_DIR}")
8181

82+
# Override SUNSHINE_ASSETS_DIR to use a writable temp directory for tests
83+
# Remove the existing definition from SUNSHINE_DEFINITIONS to avoid redefinition error
84+
list(FILTER SUNSHINE_DEFINITIONS EXCLUDE REGEX "^SUNSHINE_ASSETS_DIR=")
85+
list(APPEND TEST_DEFINITIONS SUNSHINE_ASSETS_DIR="${CMAKE_CURRENT_BINARY_DIR}/test_assets")
86+
8287
if(NOT WIN32)
8388
find_package(Udev 255) # we need 255+ for udevadm verify
8489
message(STATUS "UDEV_FOUND: ${UDEV_FOUND}")

tests/unit/test_confighttp.cpp

Lines changed: 8 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -120,29 +120,18 @@ class ConfigHttpTest: public ::testing::Test {
120120
// Set test locale
121121
config::sunshine.locale = "en";
122122

123-
// Create test web directory
123+
// Create test web directory in temp
124124
test_web_dir = std::filesystem::temp_directory_path() / "sunshine_test_confighttp";
125125
std::filesystem::create_directories(test_web_dir / "web");
126126

127-
// Create test HTML file in the actual WEB_DIR for getPage to read
128-
// Note: WEB_DIR might not exist yet, so create it
129-
try {
130-
std::filesystem::path web_dir_path(WEB_DIR);
131-
if (!std::filesystem::exists(web_dir_path)) {
132-
std::filesystem::create_directories(web_dir_path);
133-
}
134-
web_dir_test_file = web_dir_path / "test_page.html";
127+
// Create test HTML file in WEB_DIR, creating parent directories with proper permissions
128+
std::filesystem::path web_dir_path(WEB_DIR);
129+
std::filesystem::create_directories(web_dir_path);
130+
web_dir_test_file = web_dir_path / "test_page.html";
135131

136-
std::ofstream test_html(web_dir_test_file);
137-
if (test_html.is_open()) {
138-
test_html << "<html><head><title>Test Page</title></head><body><h1>Test Page Content</h1></body></html>";
139-
test_html.close();
140-
}
141-
} catch (const std::exception &e) {
142-
// If we can't create the file, getPage tests will be skipped
143-
// Log but don't fail setup
144-
std::cerr << "Warning: Could not create test file in WEB_DIR: " << e.what() << std::endl;
145-
}
132+
std::ofstream test_html(web_dir_test_file);
133+
test_html << "<html><head><title>Test Page</title></head><body><h1>Test Page Content</h1></body></html>";
134+
test_html.close();
146135

147136
// Write certificates to temp files (Simple-Web-Server expects file paths)
148137
cert_file = test_web_dir / "test_cert.pem";

0 commit comments

Comments
 (0)