test: More CLI tests, and make -u optional for publish, too.
Some checks failed
Build Tilde Friends / Build-All (push) Failing after 5m11s
Some checks failed
Build Tilde Friends / Build-All (push) Failing after 5m11s
This commit is contained in:
parent
4de53b9926
commit
86ef74e20d
16
src/main.c
16
src/main.c
@ -461,7 +461,7 @@ static int _tf_command_publish(const char* file, int argc, char* argv[])
|
||||
}
|
||||
}
|
||||
|
||||
if (show_usage || !user || !identity || !content)
|
||||
if (show_usage || !identity || !content)
|
||||
{
|
||||
tf_printf("\n%s publish [options]\n\n", file);
|
||||
tf_printf("options:\n");
|
||||
@ -480,6 +480,14 @@ static int _tf_command_publish(const char* file, int argc, char* argv[])
|
||||
tf_ssb_t* ssb = tf_ssb_create(NULL, NULL, db_path, NULL);
|
||||
tf_ssb_set_quiet(ssb, true);
|
||||
uint8_t private_key[512] = { 0 };
|
||||
|
||||
bool free_user = false;
|
||||
if (!user)
|
||||
{
|
||||
user = tf_ssb_db_get_user_for_identity(ssb, identity);
|
||||
free_user = true;
|
||||
}
|
||||
|
||||
if (tf_ssb_db_identity_get_private_key(ssb, user, identity, private_key, sizeof(private_key)))
|
||||
{
|
||||
JSContext* context = tf_ssb_get_context(ssb);
|
||||
@ -509,6 +517,12 @@ static int _tf_command_publish(const char* file, int argc, char* argv[])
|
||||
{
|
||||
tf_printf("Did not find private key for identity %s belonging to %s.\n", identity, user);
|
||||
}
|
||||
|
||||
if (free_user)
|
||||
{
|
||||
tf_free((void*)user);
|
||||
}
|
||||
|
||||
tf_ssb_destroy(ssb);
|
||||
tf_free((void*)default_db_path);
|
||||
return result;
|
||||
|
@ -1478,7 +1478,7 @@ void tf_ssb_test_triggers(const tf_test_options_t* options)
|
||||
uv_loop_close(&loop);
|
||||
}
|
||||
|
||||
static void _subprocess_check_call(const char* command)
|
||||
static void _subprocess_check_call(const char* command, int expected)
|
||||
{
|
||||
int result = system(command);
|
||||
if (!WIFEXITED(result))
|
||||
@ -1486,9 +1486,9 @@ static void _subprocess_check_call(const char* command)
|
||||
tf_printf("Command did not report exit: %s.\n", command);
|
||||
abort();
|
||||
}
|
||||
if (WEXITSTATUS(result) != 0)
|
||||
if (WEXITSTATUS(result) != expected)
|
||||
{
|
||||
tf_printf("Command returned %d: %s.\n", WEXITSTATUS(result), command);
|
||||
tf_printf("Command returned %d (expected %d): %s.\n", WEXITSTATUS(result), expected, command);
|
||||
abort();
|
||||
}
|
||||
}
|
||||
@ -1558,13 +1558,53 @@ void tf_ssb_test_cli(const tf_test_options_t* options)
|
||||
|
||||
char command[1024];
|
||||
snprintf(command, sizeof(command), "%s get_identity -d out/test_db0.sqlite", options->exe_path);
|
||||
_subprocess_check_call(command);
|
||||
_subprocess_check_call(command, 0);
|
||||
char* id = _trim(_subprocess_check_output(command));
|
||||
tf_printf("id = [%s]\n", id);
|
||||
|
||||
snprintf(command, sizeof(command), "%s private -i %s -r %s -d out/test_db0.sqlite -t '{\"type\": \"post\", \"text\": \"hello world\"}'", options->exe_path, id, id);
|
||||
_subprocess_check_call(command);
|
||||
snprintf(command, sizeof(command), "%s publish -i %s -d out/test_db0.sqlite -c '{\"type\": \"about\", \"about\": \"%s\", \"name\": \"test_user\"}'", options->exe_path, id, id);
|
||||
_subprocess_check_call(command, 0);
|
||||
|
||||
snprintf(command, sizeof(command), "%s private -i %s -r %s -d out/test_db0.sqlite -t '{\"type\": \"post\", \"text\": \"hello world\"}'", options->exe_path, id, id);
|
||||
_subprocess_check_call(command, 0);
|
||||
|
||||
snprintf(command, sizeof(command), "%s verify -i %s -d out/test_db0.sqlite", options->exe_path, id);
|
||||
_subprocess_check_call(command, 0);
|
||||
|
||||
snprintf(command, sizeof(command), "%s store_blob -f GNUmakefile -d out/test_db0.sqlite", options->exe_path);
|
||||
char* blob = _trim(_subprocess_check_output(command));
|
||||
|
||||
snprintf(command, sizeof(command), "%s has_blob -b '%s' -d out/test_db0.sqlite", options->exe_path, blob);
|
||||
_subprocess_check_call(command, 0);
|
||||
|
||||
snprintf(command, sizeof(command), "%s has_blob -b '&nonexistentid.sha256' -d out/test_db0.sqlite", options->exe_path);
|
||||
_subprocess_check_call(command, EXIT_FAILURE);
|
||||
|
||||
snprintf(command, sizeof(command), "%s get_sequence -i %s -d out/test_db0.sqlite", options->exe_path, id);
|
||||
char* sequence = _trim(_subprocess_check_output(command));
|
||||
if (strcmp(sequence, "2") != 0)
|
||||
{
|
||||
tf_printf("sequence = %s (expected 1)\n", sequence);
|
||||
abort();
|
||||
}
|
||||
tf_free(sequence);
|
||||
|
||||
snprintf(command, sizeof(command), "%s get_profile -i %s -d out/test_db0.sqlite", options->exe_path, id);
|
||||
char* profile = _trim(_subprocess_check_output(command));
|
||||
const char* k_expected_profile = "{\"name\":\"test_user\"}";
|
||||
if (strcmp(profile, k_expected_profile) != 0)
|
||||
{
|
||||
tf_printf("profile = %s (expected \"%s\")\n", profile, k_expected_profile);
|
||||
abort();
|
||||
}
|
||||
tf_free(profile);
|
||||
|
||||
snprintf(command, sizeof(command), "%s get_contacts -i %s -d out/test_db0.sqlite", options->exe_path, id);
|
||||
char* contacts = _trim(_subprocess_check_output(command));
|
||||
tf_printf("contacts = %s\n", contacts);
|
||||
tf_free(contacts);
|
||||
|
||||
tf_free(blob);
|
||||
tf_free(id);
|
||||
}
|
||||
#endif
|
||||
|
Loading…
x
Reference in New Issue
Block a user