- Add GdUnit4 v6.2.1 framework in addons/gdUnit4/ - Create test directory structure (tests/unit/, tests/integration/, tests/mocks/) - Add unit tests for MusicPlayer.gd (8 tests) - Add unit tests for MainWindow.gd (15+ tests) - Add unit tests for Settings.gd (5 tests) - Add unit tests for Playlist.gd (11 tests) - Add integration tests for full flow (10+ tests) - Add MockHTTPRequest for HTTP request mocking - Add TestHelpers with utility functions - Add Gitea Actions CI workflow (.gitea/workflows/test.yml) - Add .runsettings for GdUnit4 CLI configuration - Add run_tests.sh for convenient test execution - Add TESTING.md with comprehensive documentation - Add TESTING_PLAN.md with implementation details - Update .gitignore for test artifacts - Enable GdUnit4 plugin in project.godot Features: - Test button functionality (play, pause, search, sync, etc.) - Mock REST API requests to server - Test complete application flows - Run tests in CI (headless mode) - Run tests in GUI for visual feedback - JUnit XML and HTML test reports Generated by OpenCode AI assistant.
38 lines
1.2 KiB
GDScript
38 lines
1.2 KiB
GDScript
class_name MockHTTPRequest
|
|
extends HTTPRequest
|
|
|
|
signal mock_request_completed(result: int, response_code: int, headers: PackedStringArray, body: PackedByteArray)
|
|
|
|
var mock_responses: Dictionary = {}
|
|
var request_count: int = 0
|
|
|
|
func _ready() -> void:
|
|
request_completed.connect(_on_request_completed)
|
|
|
|
func _on_request_completed(result: int, response_code: int, headers: PackedStringArray, body: PackedByteArray) -> void:
|
|
pass
|
|
|
|
func add_mock_response(url: String, response_code: int = 200, body: PackedByteArray = PackedByteArray(), headers: PackedStringArray = PackedStringArray()) -> void:
|
|
mock_responses[url] = {
|
|
"code": response_code,
|
|
"body": body,
|
|
"headers": headers
|
|
}
|
|
|
|
func request(url: String, headers: PackedStringArray = [], method: int = HTTPClient.METHOD_GET, body: PackedByteArray = PackedByteArray()) -> int:
|
|
request_count += 1
|
|
if mock_responses.has(url):
|
|
var response = mock_responses[url]
|
|
emit_signal("request_completed", OK, response.code, response.headers, response.body)
|
|
return OK
|
|
else:
|
|
emit_signal("request_completed", FAILED, 404, [], PackedByteArray())
|
|
return FAILED
|
|
|
|
func get_request_count() -> int:
|
|
return request_count
|
|
|
|
func reset() -> void:
|
|
request_count = 0
|
|
mock_responses.clear()
|