diff options
| author | Lorenz Kästle <12514511+RincewindsHat@users.noreply.github.com> | 2025-03-30 22:38:12 +0200 |
|---|---|---|
| committer | Lorenz Kästle <12514511+RincewindsHat@users.noreply.github.com> | 2025-03-30 22:38:12 +0200 |
| commit | 76971dea753d52d3e177aa84605d9b239a3a793e (patch) | |
| tree | 1922bdcdc18e32e5cf43d7e0f0acbb93efeaeb16 /plugins/tests | |
| parent | 908aed4e6f9072e601a189d4ceff3152bdecc49d (diff) | |
| download | monitoring-plugins-76971dea753d52d3e177aa84605d9b239a3a793e.tar.gz | |
Address check_disk changes in tests
Diffstat (limited to 'plugins/tests')
| -rw-r--r-- | plugins/tests/test_check_disk.c | 67 |
1 files changed, 35 insertions, 32 deletions
diff --git a/plugins/tests/test_check_disk.c b/plugins/tests/test_check_disk.c index 963a9413..35c57bce 100644 --- a/plugins/tests/test_check_disk.c +++ b/plugins/tests/test_check_disk.c | |||
| @@ -24,7 +24,7 @@ | |||
| 24 | void np_test_mount_entry_regex(struct mount_entry *dummy_mount_list, char *regstr, int cflags, int expect, char *desc); | 24 | void np_test_mount_entry_regex(struct mount_entry *dummy_mount_list, char *regstr, int cflags, int expect, char *desc); |
| 25 | 25 | ||
| 26 | int main(int argc, char **argv) { | 26 | int main(int argc, char **argv) { |
| 27 | plan_tests(33); | 27 | plan_tests(35); |
| 28 | 28 | ||
| 29 | struct name_list *exclude_filesystem = NULL; | 29 | struct name_list *exclude_filesystem = NULL; |
| 30 | ok(np_find_name(exclude_filesystem, "/var/log") == false, "/var/log not in list"); | 30 | ok(np_find_name(exclude_filesystem, "/var/log") == false, "/var/log not in list"); |
| @@ -81,15 +81,16 @@ int main(int argc, char **argv) { | |||
| 81 | np_test_mount_entry_regex(dummy_mount_list, strdup("(/home)|(/var)"), cflags, 2, strdup("grouped regex pathname match:")); | 81 | np_test_mount_entry_regex(dummy_mount_list, strdup("(/home)|(/var)"), cflags, 2, strdup("grouped regex pathname match:")); |
| 82 | np_test_mount_entry_regex(dummy_mount_list, strdup("(/homE)|(/Var)"), cflags | REG_ICASE, 2, strdup("grouped regi pathname match:")); | 82 | np_test_mount_entry_regex(dummy_mount_list, strdup("(/homE)|(/Var)"), cflags | REG_ICASE, 2, strdup("grouped regi pathname match:")); |
| 83 | 83 | ||
| 84 | struct parameter_list *paths = NULL; | 84 | filesystem_list test_paths = filesystem_list_init(); |
| 85 | np_add_parameter(&paths, "/home/groups"); | 85 | mp_int_fs_list_append(&test_paths, "/home/groups"); |
| 86 | np_add_parameter(&paths, "/var"); | 86 | mp_int_fs_list_append(&test_paths, "/var"); |
| 87 | np_add_parameter(&paths, "/tmp"); | 87 | mp_int_fs_list_append(&test_paths, "/tmp"); |
| 88 | np_add_parameter(&paths, "/home/tonvoon"); | 88 | mp_int_fs_list_append(&test_paths, "/home/tonvoon"); |
| 89 | np_add_parameter(&paths, "/dev/c2t0d0s0"); | 89 | mp_int_fs_list_append(&test_paths, "/dev/c2t0d0s0"); |
| 90 | ok(test_paths.length == 5, "List counter works correctly with appends"); | ||
| 90 | 91 | ||
| 91 | np_set_best_match(paths, dummy_mount_list, false); | 92 | mp_int_fs_list_set_best_match(test_paths, dummy_mount_list, false); |
| 92 | for (struct parameter_list *p = paths; p; p = p->name_next) { | 93 | for (parameter_list_elem *p = test_paths.first; p; p = mp_int_fs_list_get_next(p)) { |
| 93 | struct mount_entry *temp_me; | 94 | struct mount_entry *temp_me; |
| 94 | temp_me = p->best_match; | 95 | temp_me = p->best_match; |
| 95 | if (!strcmp(p->name, "/home/groups")) { | 96 | if (!strcmp(p->name, "/home/groups")) { |
| @@ -105,15 +106,19 @@ int main(int argc, char **argv) { | |||
| 105 | } | 106 | } |
| 106 | } | 107 | } |
| 107 | 108 | ||
| 108 | paths = NULL; /* Bad boy - should free, but this is a test suite */ | 109 | for (parameter_list_elem *p = test_paths.first; p; p = mp_int_fs_list_get_next(p)) { |
| 109 | np_add_parameter(&paths, "/home/groups"); | 110 | mp_int_fs_list_del(&test_paths, p); |
| 110 | np_add_parameter(&paths, "/var"); | 111 | } |
| 111 | np_add_parameter(&paths, "/tmp"); | 112 | ok(test_paths.length == 0, "List delete sets counter properly"); |
| 112 | np_add_parameter(&paths, "/home/tonvoon"); | 113 | |
| 113 | np_add_parameter(&paths, "/home"); | 114 | mp_int_fs_list_append(&test_paths, "/home/groups"); |
| 115 | mp_int_fs_list_append(&test_paths, "/var"); | ||
| 116 | mp_int_fs_list_append(&test_paths, "/tmp"); | ||
| 117 | mp_int_fs_list_append(&test_paths, "/home/tonvoon"); | ||
| 118 | mp_int_fs_list_append(&test_paths, "/home"); | ||
| 114 | 119 | ||
| 115 | np_set_best_match(paths, dummy_mount_list, true); | 120 | mp_int_fs_list_set_best_match(test_paths, dummy_mount_list, true); |
| 116 | for (struct parameter_list *p = paths; p; p = p->name_next) { | 121 | for (parameter_list_elem *p = test_paths.first; p; p = mp_int_fs_list_get_next(p)) { |
| 117 | if (!strcmp(p->name, "/home/groups")) { | 122 | if (!strcmp(p->name, "/home/groups")) { |
| 118 | ok(!p->best_match, "/home/groups correctly not found"); | 123 | ok(!p->best_match, "/home/groups correctly not found"); |
| 119 | } else if (!strcmp(p->name, "/var")) { | 124 | } else if (!strcmp(p->name, "/var")) { |
| @@ -129,8 +134,8 @@ int main(int argc, char **argv) { | |||
| 129 | 134 | ||
| 130 | bool found = false; | 135 | bool found = false; |
| 131 | /* test deleting first element in paths */ | 136 | /* test deleting first element in paths */ |
| 132 | paths = np_del_parameter(paths, NULL); | 137 | mp_int_fs_list_del(&test_paths, NULL); |
| 133 | for (struct parameter_list *p = paths; p; p = p->name_next) { | 138 | for (parameter_list_elem *p = test_paths.first; p; p = mp_int_fs_list_get_next(p)) { |
| 134 | if (!strcmp(p->name, "/home/groups")) { | 139 | if (!strcmp(p->name, "/home/groups")) { |
| 135 | found = true; | 140 | found = true; |
| 136 | } | 141 | } |
| @@ -138,23 +143,21 @@ int main(int argc, char **argv) { | |||
| 138 | ok(!found, "first element successfully deleted"); | 143 | ok(!found, "first element successfully deleted"); |
| 139 | found = false; | 144 | found = false; |
| 140 | 145 | ||
| 141 | struct parameter_list *prev = NULL; | 146 | parameter_list_elem *prev = NULL; |
| 142 | struct parameter_list *p = paths; | 147 | parameter_list_elem *p = NULL; |
| 143 | while (p) { | 148 | for (parameter_list_elem *path = test_paths.first; path; path = mp_int_fs_list_get_next(path)) { |
| 144 | if (!strcmp(p->name, "/tmp")) { | 149 | if (!strcmp(path->name, "/tmp")) { |
| 145 | p = np_del_parameter(p, prev); | 150 | mp_int_fs_list_del(&test_paths, path); |
| 146 | } else { | ||
| 147 | prev = p; | ||
| 148 | p = p->name_next; | ||
| 149 | } | 151 | } |
| 152 | p = path; | ||
| 150 | } | 153 | } |
| 151 | 154 | ||
| 152 | struct parameter_list *last = NULL; | 155 | parameter_list_elem *last = NULL; |
| 153 | for (struct parameter_list *path = paths; path; path = path->name_next) { | 156 | for (parameter_list_elem *path = test_paths.first; path; path = mp_int_fs_list_get_next(path)) { |
| 154 | if (!strcmp(path->name, "/tmp")) { | 157 | if (!strcmp(path->name, "/tmp")) { |
| 155 | found = true; | 158 | found = true; |
| 156 | } | 159 | } |
| 157 | if (path->name_next) { | 160 | if (path->next) { |
| 158 | prev = path; | 161 | prev = path; |
| 159 | } else { | 162 | } else { |
| 160 | last = path; | 163 | last = path; |
| @@ -163,8 +166,8 @@ int main(int argc, char **argv) { | |||
| 163 | ok(!found, "/tmp element successfully deleted"); | 166 | ok(!found, "/tmp element successfully deleted"); |
| 164 | 167 | ||
| 165 | int count = 0; | 168 | int count = 0; |
| 166 | p = np_del_parameter(last, prev); | 169 | mp_int_fs_list_del(&test_paths, p); |
| 167 | for (p = paths; p; p = p->name_next) { | 170 | for (p = test_paths.first; p; p = p->next) { |
| 168 | if (!strcmp(p->name, "/home")) { | 171 | if (!strcmp(p->name, "/home")) { |
| 169 | found = true; | 172 | found = true; |
| 170 | } | 173 | } |
