The previous tests never compiled: they used GUT's assert functions, Godot 3 APIs and reassigned autoload functions, so no test ran. - 90 tests: unit tests for the playlist, songs, player scoring, time formatting, search and the server client, plus integration tests that run MainWindow and SyncWindow against a fake server - Keybind tests check that Alt+<number> and Ctrl+Alt+<number> keep following the player rows while players are added and removed - run_tests.sh finds Godot and runs the suite headless (~10 seconds) - CI runs the tests before the build job in gitea-build.yaml; the separate test.yml used a GitHub action that does not exist - GdUnit4 is committed instead of ignored, since the project enables it, and .gitea/ is no longer ignored - Exported builds leave out tests/ and addons/gdUnit4/
57 lines
1.9 KiB
GDScript
57 lines
1.9 KiB
GDScript
class_name FakeHttpTransport
|
|
extends HttpTransport
|
|
## Stands in for the MusicServer in tests.
|
|
##
|
|
## Register canned responses per path with [method respond_json] or
|
|
## [method respond_bytes], then install it with [method install]. Requests to paths
|
|
## without a response get a 404. Responses are delivered immediately.
|
|
|
|
## Paths requested so far, relative to [code]Settings.default_path[/code].
|
|
var requested_paths: Array[String] = []
|
|
## HTTP method of each request, in the same order as [member requested_paths].
|
|
var requested_methods: Array[int] = []
|
|
|
|
var _responses: Dictionary = {}
|
|
var _previous_transport: HttpTransport
|
|
|
|
|
|
func _init() -> void:
|
|
super(null)
|
|
|
|
|
|
## Replaces the MusicServerClient transport with this fake.
|
|
func install() -> FakeHttpTransport:
|
|
_previous_transport = MusicServerClient.transport
|
|
MusicServerClient.transport = self
|
|
return self
|
|
|
|
|
|
## Restores the transport that was active before [method install].
|
|
func uninstall() -> void:
|
|
MusicServerClient.transport = _previous_transport
|
|
|
|
|
|
## Answers requests to [param path] with [param data] encoded as JSON.
|
|
func respond_json(path: String, data: Variant, response_code: int = 200) -> void:
|
|
respond_bytes(path, JSON.stringify(data).to_utf8_buffer(), response_code)
|
|
|
|
|
|
## Answers requests to [param path] with [param body] as-is.
|
|
func respond_bytes(path: String, body: PackedByteArray, response_code: int = 200) -> void:
|
|
_responses[path] = {"code": response_code, "body": body}
|
|
|
|
|
|
## Returns how many times [param path] has been requested.
|
|
func count(path: String) -> int:
|
|
return requested_paths.count(path)
|
|
|
|
|
|
func request(url: String, method: int, on_complete: Callable) -> void:
|
|
var path: String = url.trim_prefix(Settings.default_path)
|
|
requested_paths.append(path)
|
|
requested_methods.append(method)
|
|
if _responses.has(path):
|
|
on_complete.call(_responses[path].code, _responses[path].body)
|
|
else:
|
|
on_complete.call(404, PackedByteArray())
|