Add erm module test

This commit is contained in:
JeremyStar™ 2024-04-06 14:00:44 +02:00
parent ccec39d85a
commit 1c528da96f
Signed by: JeremyStarTM
GPG key ID: E366BAEF67E4704D

103
tests/unit/erm.gd Normal file
View file

@ -0,0 +1,103 @@
extends 'res://tests/unitbase.gd'
var url_base: String = "https://fs.staropensource.de/test/core/erm-"
var url_text: String = url_base + "text"
var url_binary: String = url_base + "binary"
var correct_text: String = "Hi! This file is used in tests verifying that CORE's built-in 'erm' module works.\n"
var correct_text_binary: PackedByteArray = []
var correct_binary: PackedByteArray = [31, 139, 8, 8, 41, 47, 17, 102, 0, 3, 101, 114, 109, 45, 98, 105, 110, 97, 114, 121, 0, 83, 14, 41, 74, 204, 43, 14, 202, 76, 207, 40, 41, 118, 44, 74, 245, 40, 205, 77, 204, 131, 240, 184, 0, 158, 102, 174, 206, 27, 0, 0, 0]
func test_awaited_request_text() -> void:
await load_framework()
# Get download data
var dldata: Dictionary = await core.erm.awaited_request(url_text, true)
# Skip test if request failed
if dldata["result"] != 0:
rskip("Godot returned '" + error_string(dldata["result"]) + "'")
return
if dldata["http_code"] != 200:
rskip("Server returned '" + str(dldata["http_code"]) + "'")
return
# Check content
if dldata["body_utf8"] != correct_text:
lerror("Got this INVALID UTF-8 body data: " + str(dldata["body_utf8"]).replace("\n", "\\n"))
rerror("Got invalid UTF-8 body data (check logs)")
return
rok()
func test_awaited_request_binary() -> void:
await load_framework()
# Get download data
var dldata: Dictionary = await core.erm.awaited_request(url_binary, false)
# Skip test if request failed
if dldata["result"] != 0:
rskip("Godot returned '" + error_string(dldata["result"]) + "'")
return
if dldata["http_code"] != 200:
rskip("Server returned '" + str(dldata["http_code"]) + "'")
return
# Check content
if dldata["body"] != correct_binary:
lerror("Got this INVALID binary body data: " + str(dldata["body"]))
rerror("Got invalid binary body data (check logs)")
return
rok()
func test_oneline_awaited_request_text() -> void:
await load_framework()
# Get download data
var dldata: Variant = await core.erm.oneline_awaited_request(url_text, true)
# Check failure
if dldata == null:
rskip("dldata is 'null', request probably failed")
return
# Check type
if typeof(dldata) != TYPE_STRING:
rerror("dldata is not of type String")
return
# Check content
if dldata != correct_text:
lerror("Got this INVALID UTF-8 body data: " + str(dldata).replace("\n", "\\n"))
rerror("Got invalid UTF-8 body data (check logs)")
return
rok()
func test_oneline_awaited_request_binary() -> void:
await load_framework()
# Get download data
var dldata: Variant = await core.erm.oneline_awaited_request(url_binary, false)
# Check failure
if dldata == null:
rskip("dldata is 'null', request probably failed")
return
# Check type
if typeof(dldata) != TYPE_PACKED_BYTE_ARRAY:
rerror("dldata is not of type PackedByteArray")
return
# Check content
if dldata != correct_binary:
lerror("Got this INVALID binary body data: " + str(dldata))
rerror("Got invalid binary body data (check logs)")
return
rok()
func test_batch_awaited_request() -> void: rskip("TODO")