tests: add test for configuration key/value formatting

Closes: #412 [via git-merge-pr]
This commit is contained in:
Duncan Overbruck 2021-06-26 15:26:52 +02:00
parent 248ca4b152
commit 72395cdf80
No known key found for this signature in database
GPG Key ID: 335C1D17EC3D6E35
2 changed files with 54 additions and 0 deletions

View File

@ -276,6 +276,57 @@ ATF_TC_BODY(config_masking, tc)
ATF_REQUIRE_STREQ(repo, "1");
}
ATF_TC(config_trim_values);
ATF_TC_HEAD(config_trim_values, tc)
{
atf_tc_set_md_var(tc, "descr", "Test trimming of values");
}
ATF_TC_BODY(config_trim_values, tc)
{
struct xbps_handle xh;
const char *tcsdir, *repo;
char *buf, *buf2, pwd[PATH_MAX];
int ret;
/* get test source dir */
tcsdir = atf_tc_get_config_var(tc, "srcdir");
memset(&xh, 0, sizeof(xh));
buf = getcwd(pwd, sizeof(pwd));
xbps_strlcpy(xh.rootdir, tcsdir, sizeof(xh.rootdir));
xbps_strlcpy(xh.metadir, tcsdir, sizeof(xh.metadir));
ret = snprintf(xh.confdir, sizeof(xh.confdir), "%s/xbps.d", pwd);
ATF_REQUIRE_EQ((ret >= 0), 1);
ATF_REQUIRE_EQ(((size_t)ret < sizeof(xh.confdir)), 1);
ret = snprintf(xh.sysconfdir, sizeof(xh.sysconfdir), "%s/sys-xbps.d", pwd);
ATF_REQUIRE_EQ((ret >= 0), 1);
ATF_REQUIRE_EQ(((size_t)ret < sizeof(xh.sysconfdir)), 1);
ATF_REQUIRE_EQ(xbps_mkpath(xh.confdir, 0755), 0);
ATF_REQUIRE_EQ(xbps_mkpath(xh.sysconfdir, 0755), 0);
buf = xbps_xasprintf("%s/trim.cf", tcsdir);
buf2 = xbps_xasprintf("%s/xbps.d/1.conf", pwd);
ATF_REQUIRE_EQ(symlink(buf, buf2), 0);
free(buf);
free(buf2);
xh.flags = XBPS_FLAG_DEBUG;
ATF_REQUIRE_EQ(xbps_init(&xh), 0);
/* should contain one repository */
ATF_REQUIRE_EQ(xbps_array_count(xh.repositories), 2);
/* should contain repository=1 */
ATF_REQUIRE_EQ(xbps_array_get_cstring_nocopy(xh.repositories, 0, &repo), true);
ATF_REQUIRE_STREQ(repo, "1");
/* should contain repository=2 */
ATF_REQUIRE_EQ(xbps_array_get_cstring_nocopy(xh.repositories, 1, &repo), true);
ATF_REQUIRE_STREQ(repo, "2");
}
ATF_TP_ADD_TCS(tp)
{
ATF_TP_ADD_TC(tp, config_include_test);
@ -283,6 +334,7 @@ ATF_TP_ADD_TCS(tp)
ATF_TP_ADD_TC(tp, config_include_absolute);
ATF_TP_ADD_TC(tp, config_include_absolute_glob);
ATF_TP_ADD_TC(tp, config_masking);
ATF_TP_ADD_TC(tp, config_trim_values);
return atf_no_error();
}

View File

@ -0,0 +1,2 @@
repository= 1
repository =2