Skip to content

Commit

Permalink
Ensure we exhausted the snapshot
Browse files Browse the repository at this point in the history
  • Loading branch information
supervacuus committed Mar 7, 2024
1 parent 6b83e8e commit b031e9d
Showing 1 changed file with 17 additions and 8 deletions.
25 changes: 17 additions & 8 deletions tests/unit/test_os_release.c
Original file line number Diff line number Diff line change
Expand Up @@ -103,18 +103,22 @@ const struct distro test_dists[] = {
{ .name = "sled", .version = "12.3" },
};

const int num_test_dists = sizeof(test_dists) / sizeof(struct distro);

int
value_strcmp_by_key(sentry_value_t value, const char *key, const char *str)
{
return strcmp(
sentry_value_as_string(sentry_value_get_by_key(value, key)), str);
}

int
assert_equals_snap(sentry_value_t os_dist)
{
for (size_t i = 0; i < sizeof(test_dists) / sizeof(struct distro); i++) {
for (size_t i = 0; i < num_test_dists; i++) {
const struct distro *expected = &test_dists[i];
if (strcmp(sentry_value_as_string(
sentry_value_get_by_key(os_dist, "name")),
expected->name)
== 0
&& strcmp(sentry_value_as_string(
sentry_value_get_by_key(os_dist, "version")),
expected->version)
if (value_strcmp_by_key(os_dist, "name", expected->name) == 0
&& value_strcmp_by_key(os_dist, "version", expected->version)
== 0) {
return 1;
}
Expand Down Expand Up @@ -145,6 +149,7 @@ SENTRY_TEST(os_releases_snapshot)

struct dirent *entry;

int successful_snap_asserts = 0;
while ((entry = readdir(test_data_dir)) != NULL) {
if (entry->d_type != DT_REG
|| strcmp("CODE_OF_CONDUCT.md", entry->d_name) == 0
Expand All @@ -165,10 +170,14 @@ SENTRY_TEST(os_releases_snapshot)
sentry_value_get_by_key(os_dist, "name")),
sentry_value_as_string(
sentry_value_get_by_key(os_dist, "version")));
} else {
successful_snap_asserts++;
}
sentry_value_decref(os_dist);
}

TEST_CHECK_INT_EQUAL(successful_snap_asserts, num_test_dists);

closedir(test_data_dir);
sentry__path_free(test_data_path);
#endif // !defined(SENTRY_PLATFORM_LINUX) && defined(SENTRY_PLATFORM_ANDROID)
Expand Down

0 comments on commit b031e9d

Please sign in to comment.