forked from cory/tildefriends
test: Cover more ways to request apps and files.
This commit is contained in:
parent
fd4ac7c9b9
commit
30e027092b
4
apps/test.json
Normal file
4
apps/test.json
Normal file
@ -0,0 +1,4 @@
|
|||||||
|
{
|
||||||
|
"type": "tildefriends-app",
|
||||||
|
"emoji": "📦"
|
||||||
|
}
|
1
apps/test/app.js
Normal file
1
apps/test/app.js
Normal 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
1
apps/test/hello.txt
Normal file
@ -0,0 +1 @@
|
|||||||
|
Hello, world!
|
@ -1077,7 +1077,8 @@ static void _httpd_endpoint_view_work(tf_ssb_t* ssb, void* user_data)
|
|||||||
}
|
}
|
||||||
else
|
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);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -638,6 +638,10 @@ bool tf_ssb_db_blob_get(tf_ssb_t* ssb, const char* id, uint8_t** out_blob, size_
|
|||||||
}
|
}
|
||||||
result = true;
|
result = true;
|
||||||
}
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
tf_printf("OOPS %s\n", sqlite3_errmsg(db));
|
||||||
|
}
|
||||||
sqlite3_finalize(statement);
|
sqlite3_finalize(statement);
|
||||||
}
|
}
|
||||||
tf_ssb_release_db_reader(ssb, db);
|
tf_ssb_release_db_reader(ssb, db);
|
||||||
|
32
src/tests.c
32
src/tests.c
@ -4,6 +4,8 @@
|
|||||||
#include "http.h"
|
#include "http.h"
|
||||||
#include "log.h"
|
#include "log.h"
|
||||||
#include "mem.h"
|
#include "mem.h"
|
||||||
|
#include "ssb.h"
|
||||||
|
#include "ssb.db.h"
|
||||||
#include "ssb.tests.h"
|
#include "ssb.tests.h"
|
||||||
#include "util.js.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);
|
tf_printf("%s => found: \"%s\"\n", url, expected);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
if (!found)
|
||||||
|
{
|
||||||
|
tf_printf("Didn't find \"%s\" in %s.\n", expected, url);
|
||||||
|
}
|
||||||
assert(found);
|
assert(found);
|
||||||
assert(file);
|
assert(file);
|
||||||
int status = pclose(file);
|
int status = pclose(file);
|
||||||
@ -844,23 +850,35 @@ static void _test_httpd(const tf_test_options_t* options)
|
|||||||
char command[256];
|
char command[256];
|
||||||
snprintf(command, sizeof(command), "%s run -b 0 --db-path=out/test_db0.sqlite" TEST_ARGS, options->exe_path);
|
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_process_t process = { 0 };
|
||||||
uv_spawn(&loop, &process,
|
uv_spawn(&loop, &process,
|
||||||
&(uv_process_options_t)
|
&(uv_process_options_t)
|
||||||
{
|
{
|
||||||
.file = options->exe_path,
|
.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 },
|
.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++)
|
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;
|
break;
|
||||||
}
|
}
|
||||||
uv_sleep(1000);
|
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/404", 404);
|
||||||
_http_check_status_code("http://localhost:8080/", 303);
|
_http_check_status_code("http://localhost:8080/", 303);
|
||||||
_http_check_status_code("http://localhost:8080/~core/apps/", 200);
|
_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_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/", "<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/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_process_kill(&process, SIGTERM);
|
||||||
uv_close((uv_handle_t*)&process, NULL);
|
uv_close((uv_handle_t*)&process, NULL);
|
||||||
|
Loading…
Reference in New Issue
Block a user