diff options
Diffstat (limited to 'src/test/test-os-util.c')
-rw-r--r-- | src/test/test-os-util.c | 73 |
1 files changed, 38 insertions, 35 deletions
diff --git a/src/test/test-os-util.c b/src/test/test-os-util.c index 84e55e1..55475a5 100644 --- a/src/test/test-os-util.c +++ b/src/test/test-os-util.c @@ -14,47 +14,49 @@ #include "tmpfile-util.h" TEST(path_is_os_tree) { - assert_se(path_is_os_tree("/") > 0); - assert_se(path_is_os_tree("/etc") == 0); + ASSERT_GT(path_is_os_tree("/"), 0); + ASSERT_EQ(path_is_os_tree("/etc"), 0); assert_se(path_is_os_tree("/idontexist") == -ENOENT); } TEST(parse_os_release) { - /* Let's assume that we're running in a valid system, so os-release is available */ _cleanup_free_ char *id = NULL, *id2 = NULL, *name = NULL, *foobar = NULL; - assert_se(parse_os_release(NULL, "ID", &id) == 0); - log_info("ID: %s", id); - assert_se(setenv("SYSTEMD_OS_RELEASE", "/dev/null", 1) == 0); - assert_se(parse_os_release(NULL, "ID", &id2) == 0); + if (access("/etc/os-release", F_OK) >= 0 || access("/usr/lib/os-release", F_OK) >= 0) { + ASSERT_EQ(parse_os_release(NULL, "ID", &id), 0); + log_info("ID: %s", id); + } + + ASSERT_EQ(setenv("SYSTEMD_OS_RELEASE", "/dev/null", 1), 0); + ASSERT_EQ(parse_os_release(NULL, "ID", &id2), 0); log_info("ID: %s", strnull(id2)); _cleanup_(unlink_tempfilep) char tmpfile[] = "/tmp/test-os-util.XXXXXX"; - assert_se(write_tmpfile(tmpfile, + ASSERT_EQ(write_tmpfile(tmpfile, "ID=the-id \n" - "NAME=the-name") == 0); + "NAME=the-name"), 0); - assert_se(setenv("SYSTEMD_OS_RELEASE", tmpfile, 1) == 0); - assert_se(parse_os_release(NULL, "ID", &id, "NAME", &name) == 0); + ASSERT_EQ(setenv("SYSTEMD_OS_RELEASE", tmpfile, 1), 0); + ASSERT_EQ(parse_os_release(NULL, "ID", &id, "NAME", &name), 0); log_info("ID: %s NAME: %s", id, name); - assert_se(streq(id, "the-id")); - assert_se(streq(name, "the-name")); + ASSERT_STREQ(id, "the-id"); + ASSERT_STREQ(name, "the-name"); _cleanup_(unlink_tempfilep) char tmpfile2[] = "/tmp/test-os-util.XXXXXX"; - assert_se(write_tmpfile(tmpfile2, + ASSERT_EQ(write_tmpfile(tmpfile2, "ID=\"ignored\" \n" "ID=\"the-id\" \n" - "NAME='the-name'") == 0); + "NAME='the-name'"), 0); - assert_se(setenv("SYSTEMD_OS_RELEASE", tmpfile2, 1) == 0); - assert_se(parse_os_release(NULL, "ID", &id, "NAME", &name) == 0); + ASSERT_EQ(setenv("SYSTEMD_OS_RELEASE", tmpfile2, 1), 0); + ASSERT_EQ(parse_os_release(NULL, "ID", &id, "NAME", &name), 0); log_info("ID: %s NAME: %s", id, name); - assert_se(streq(id, "the-id")); - assert_se(streq(name, "the-name")); + ASSERT_STREQ(id, "the-id"); + ASSERT_STREQ(name, "the-name"); - assert_se(parse_os_release(NULL, "FOOBAR", &foobar) == 0); + ASSERT_EQ(parse_os_release(NULL, "FOOBAR", &foobar), 0); log_info("FOOBAR: %s", strnull(foobar)); - assert_se(foobar == NULL); + ASSERT_NULL(foobar); assert_se(unsetenv("SYSTEMD_OS_RELEASE") == 0); } @@ -70,6 +72,7 @@ TEST(parse_extension_release) { assert_se(a = path_join(tempdir, "/usr/lib/extension-release.d/extension-release.test")); assert_se(mkdir_parents(a, 0777) >= 0); + ASSERT_GE(mkdir_parents(a, 0777), 0); r = write_string_file(a, "ID=the-id \n VERSION_ID=the-version-id", WRITE_STRING_FILE_CREATE); if (r < 0) @@ -77,8 +80,8 @@ TEST(parse_extension_release) { assert_se(parse_extension_release(tempdir, IMAGE_SYSEXT, "test", false, "ID", &id, "VERSION_ID", &version_id) == 0); log_info("ID: %s VERSION_ID: %s", id, version_id); - assert_se(streq(id, "the-id")); - assert_se(streq(version_id, "the-version-id")); + ASSERT_STREQ(id, "the-id"); + ASSERT_STREQ(version_id, "the-version-id"); assert_se(b = path_join(tempdir, "/etc/extension-release.d/extension-release.tester")); assert_se(mkdir_parents(b, 0777) >= 0); @@ -87,42 +90,42 @@ TEST(parse_extension_release) { if (r < 0) log_error_errno(r, "Failed to write file: %m"); - assert_se(parse_extension_release(tempdir, IMAGE_CONFEXT, "tester", false, "ID", &id, "VERSION_ID", &version_id) == 0); + ASSERT_EQ(parse_extension_release(tempdir, IMAGE_CONFEXT, "tester", false, "ID", &id, "VERSION_ID", &version_id), 0); log_info("ID: %s VERSION_ID: %s", id, version_id); - assert_se(streq(id, "the-id")); - assert_se(streq(version_id, "the-version-id")); + ASSERT_STREQ(id, "the-id"); + ASSERT_STREQ(version_id, "the-version-id"); assert_se(parse_extension_release(tempdir, IMAGE_CONFEXT, "tester", false, "FOOBAR", &foobar) == 0); log_info("FOOBAR: %s", strnull(foobar)); - assert_se(foobar == NULL); + ASSERT_NULL(foobar); assert_se(parse_extension_release(tempdir, IMAGE_SYSEXT, "test", false, "FOOBAR", &foobar) == 0); log_info("FOOBAR: %s", strnull(foobar)); - assert_se(foobar == NULL); + ASSERT_NULL(foobar); } TEST(load_os_release_pairs) { _cleanup_(unlink_tempfilep) char tmpfile[] = "/tmp/test-os-util.XXXXXX"; - assert_se(write_tmpfile(tmpfile, + ASSERT_EQ(write_tmpfile(tmpfile, "ID=\"ignored\" \n" "ID=\"the-id\" \n" - "NAME='the-name'") == 0); + "NAME='the-name'"), 0); - assert_se(setenv("SYSTEMD_OS_RELEASE", tmpfile, 1) == 0); + ASSERT_EQ(setenv("SYSTEMD_OS_RELEASE", tmpfile, 1), 0); _cleanup_strv_free_ char **pairs = NULL; - assert_se(load_os_release_pairs(NULL, &pairs) == 0); + ASSERT_EQ(load_os_release_pairs(NULL, &pairs), 0); assert_se(strv_equal(pairs, STRV_MAKE("ID", "the-id", "NAME", "the-name"))); - assert_se(unsetenv("SYSTEMD_OS_RELEASE") == 0); + ASSERT_EQ(unsetenv("SYSTEMD_OS_RELEASE"), 0); } TEST(os_release_support_ended) { int r; - assert_se(os_release_support_ended("1999-01-01", false, NULL) == true); - assert_se(os_release_support_ended("2037-12-31", false, NULL) == false); + ASSERT_TRUE(os_release_support_ended("1999-01-01", false, NULL)); + ASSERT_FALSE(os_release_support_ended("2037-12-31", false, NULL)); assert_se(os_release_support_ended("-1-1-1", true, NULL) == -EINVAL); r = os_release_support_ended(NULL, false, NULL); |