Adds a test for defaults and fixes bug relating to it

This commit is contained in:
Jonathan Hodgson 2021-12-28 01:34:50 +00:00
parent e42705280c
commit 8bed39700e
2 changed files with 34 additions and 12 deletions

View file

@ -6,7 +6,7 @@
/*
* Ensures that path_exists returns true on current working dir (should to exist)
*/
MunitResult path_that_exists(const MunitParameter params[],
MunitResult pathThatExists(const MunitParameter params[],
void* user_data_or_fixture){
char cwd[500] = {'\0'};
getcwd(cwd,500);
@ -14,7 +14,7 @@ MunitResult path_that_exists(const MunitParameter params[],
return MUNIT_OK;
}
MunitResult path_that_doesnt_exist(const MunitParameter params[],
MunitResult pathThatDoesntExist(const MunitParameter params[],
void* user_data_or_fixture){
char cwd[500] = {'\0'};
getcwd(cwd,500);
@ -23,14 +23,14 @@ MunitResult path_that_doesnt_exist(const MunitParameter params[],
return MUNIT_OK;
}
MunitResult tilde_resolves_correctly(const MunitParameter params[],
MunitResult tildeResolvesCorrectly(const MunitParameter params[],
void* user_data_or_fixture){
munit_assert_string_equal( getenv("HOME"), resolveTilde("~") );
return MUNIT_OK;
}
MunitResult check_config_dir_with_xdg(const MunitParameter params[],
MunitResult checkConfigDirWithXdg(const MunitParameter params[],
void* user_data_or_fixture){
char directory[] = "/testing/xdg/directory";
setenv( "XDG_CONFIG_HOME",directory, 1 );
@ -38,7 +38,7 @@ MunitResult check_config_dir_with_xdg(const MunitParameter params[],
return MUNIT_OK;
}
MunitResult check_config_dir_without_xdg(const MunitParameter params[],
MunitResult checkConfigDirWithoutXdg(const MunitParameter params[],
void* user_data_or_fixture){
unsetenv( "XDG_CONFIG_HOME" );
char dir[500] = {'\0'};
@ -48,11 +48,25 @@ MunitResult check_config_dir_without_xdg(const MunitParameter params[],
return MUNIT_OK;
}
MunitResult checkDefaults(const MunitParameter params[],
void* user_data_or_fixture){
char directory[] = "/testing/xdg/directory";
char file[] = "/testing/xdg/directory/proxy.conf";
setenv( "XDG_CONFIG_HOME",directory, 1 );
Config *conf = configDefaults();
munit_assert_string_equal(conf->database, "proxy.sqlite");
munit_assert_int(conf->port, ==, 8080);
munit_assert_string_equal(conf->localConfig, "proxy.conf");
munit_assert_string_equal(conf->userConfig, file);
return MUNIT_OK;
}
MunitTest tests[] = {
{
"/path_exists/yes", /* name */
path_that_exists, /* test */
pathThatExists, /* test */
NULL, /* setup */
NULL, /* tear_down */
MUNIT_TEST_OPTION_NONE, /* options */
@ -60,7 +74,7 @@ MunitTest tests[] = {
},
{
"/path_exists/no", /* name */
path_that_doesnt_exist, /* test */
pathThatDoesntExist, /* test */
NULL, /* setup */
NULL, /* tear_down */
MUNIT_TEST_OPTION_NONE, /* options */
@ -68,7 +82,7 @@ MunitTest tests[] = {
},
{
"/TildeResolves", /* name */
tilde_resolves_correctly, /* test */
tildeResolvesCorrectly, /* test */
NULL, /* setup */
NULL, /* tear_down */
MUNIT_TEST_OPTION_NONE, /* options */
@ -76,7 +90,7 @@ MunitTest tests[] = {
},
{
"/ConfigDir/WithXDG", /* name */
check_config_dir_with_xdg, /* test */
checkConfigDirWithoutXdg, /* test */
NULL, /* setup */
NULL, /* tear_down */
MUNIT_TEST_OPTION_NONE, /* options */
@ -84,7 +98,15 @@ MunitTest tests[] = {
},
{
"/ConfigDir/WithoutXDG", /* name */
check_config_dir_without_xdg, /* test */
checkConfigDirWithoutXdg, /* test */
NULL, /* setup */
NULL, /* tear_down */
MUNIT_TEST_OPTION_NONE, /* options */
NULL /* parameters */
},
{
"/ConfigDir/Defaults", /* name */
checkDefaults, /* test */
NULL, /* setup */
NULL, /* tear_down */
MUNIT_TEST_OPTION_NONE, /* options */