test: Cover more ways to request apps and files.
All checks were successful
Build Tilde Friends / Build-All (push) Successful in 15m15s

This commit is contained in:
Cory McWilliams 2024-11-02 15:43:03 -04:00
parent fd4ac7c9b9
commit 30e027092b
6 changed files with 43 additions and 2 deletions

4
apps/test.json Normal file
View File

@ -0,0 +1,4 @@
{
"type": "tildefriends-app",
"emoji": "📦"
}

1
apps/test/app.js Normal file
View File

@ -0,0 +1 @@
app.setDocument('<p style="color: #fff">Maybe one day this app will run tests, but for now there is nothing to see here.</p>');

1
apps/test/hello.txt Normal file
View File

@ -0,0 +1 @@
Hello, world!

View File

@ -1077,7 +1077,8 @@ static void _httpd_endpoint_view_work(tf_ssb_t* ssb, void* user_data)
}
else
{
tf_ssb_db_blob_get(ssb, blob_id, (uint8_t**)&view->data, &view->size);
bool result = tf_ssb_db_blob_get(ssb, blob_id, (uint8_t**)&view->data, &view->size);
tf_printf("ssb=%p result=%d blob_id=[%s] data=%p size=%zd\n", ssb, result, blob_id, view->data, view->size);
}
}
}

View File

@ -638,6 +638,10 @@ bool tf_ssb_db_blob_get(tf_ssb_t* ssb, const char* id, uint8_t** out_blob, size_
}
result = true;
}
else
{
tf_printf("OOPS %s\n", sqlite3_errmsg(db));
}
sqlite3_finalize(statement);
}
tf_ssb_release_db_reader(ssb, db);

View File

@ -4,6 +4,8 @@
#include "http.h"
#include "log.h"
#include "mem.h"
#include "ssb.h"
#include "ssb.db.h"
#include "ssb.tests.h"
#include "util.js.h"
@ -828,6 +830,10 @@ static void _http_check_body_contains(const char* url, const char* expected)
tf_printf("%s => found: \"%s\"\n", url, expected);
}
}
if (!found)
{
tf_printf("Didn't find \"%s\" in %s.\n", expected, url);
}
assert(found);
assert(file);
int status = pclose(file);
@ -844,23 +850,35 @@ static void _test_httpd(const tf_test_options_t* options)
char command[256];
snprintf(command, sizeof(command), "%s run -b 0 --db-path=out/test_db0.sqlite" TEST_ARGS, options->exe_path);
uv_stdio_container_t stdio[] =
{
[STDIN_FILENO] = { .flags = UV_IGNORE },
[STDOUT_FILENO] = { .flags = UV_INHERIT_FD },
[STDERR_FILENO] = { .flags = UV_INHERIT_FD },
};
uv_process_t process = { 0 };
uv_spawn(&loop, &process,
&(uv_process_options_t)
{
.file = options->exe_path,
.args = (char*[]) { (char*)options->exe_path, "run", "-b0", "--db-path=out/test_db0.sqlite", "--http-port=8080", "--https-port=0", NULL },
.stdio_count = sizeof(stdio) / sizeof(*stdio),
.stdio = stdio,
});
for (int i = 0; i < 100; i++)
{
if (_http_get_status_code("http://localhost:8080/mem") == 200)
if (_http_get_status_code("http://localhost:8080/debug") == 200)
{
break;
}
uv_sleep(1000);
}
tf_ssb_t* ssb = tf_ssb_create(&loop, NULL, "file:out/test_db0.sqlite", NULL);
const char* app_id = tf_ssb_db_get_property(ssb, "core", "path:test");
tf_ssb_destroy(ssb);
_http_check_status_code("http://localhost:8080/404", 404);
_http_check_status_code("http://localhost:8080/", 303);
_http_check_status_code("http://localhost:8080/~core/apps/", 200);
@ -868,6 +886,18 @@ static void _test_httpd(const tf_test_options_t* options)
_http_check_status_code("http://localhost:8080/~core/apps/view", 200);
_http_check_body_contains("http://localhost:8080/~core/apps/", "<title>Tilde Friends</title>");
_http_check_body_contains("http://localhost:8080/~core/apps/view", "\"type\":\"tildefriends-app\"");
_http_check_body_contains("http://localhost:8080/~core/test/hello.txt", "Hello, world!");
_http_check_status_code("http://localhost:8080/~core/test/nonexistent.txt", 404);
_http_check_body_contains("http://localhost:8080/&MV9b23bQeMQ7isAGTkoBZGErH853yGk0W/yUx1iU7dM=.sha256/view", "Hello, world!");
char url[1024];
snprintf(url, sizeof(url), "http://localhost:8080/%s/", app_id);
_http_check_body_contains(url, "<title>Tilde Friends</title>");
snprintf(url, sizeof(url), "http://localhost:8080/%s/view", app_id);
_http_check_body_contains(url, "\"type\":\"tildefriends-app\"");
snprintf(url, sizeof(url), "http://localhost:8080/%s/hello.txt", app_id);
_http_check_body_contains(url, "Hello, world!");
tf_free((void*)app_id);
uv_process_kill(&process, SIGTERM);
uv_close((uv_handle_t*)&process, NULL);