Skip to content

Commit

Permalink
libhostlist: add unit tests for hostlist_find_hostname()
Browse files Browse the repository at this point in the history
Problem: There are no tests of hostlist_find_hostname().

Add them using the existing hostlist_find() inputs.
  • Loading branch information
grondo committed Sep 10, 2024
1 parent 566ec4e commit 6fc817c
Showing 1 changed file with 30 additions and 0 deletions.
30 changes: 30 additions & 0 deletions src/common/libhostlist/test/hostlist.c
Original file line number Diff line number Diff line change
Expand Up @@ -343,6 +343,35 @@ void test_find ()
}
}

void test_find_hostname ()
{
struct find_test *t = find_tests;

ok (hostlist_find_hostname (NULL, NULL) == -1 && errno == EINVAL,
"hostlist_find_hostname (NULL, NULL) returns EINVAL");

while (t && t->input) {
int rc;
struct hostlist_hostname *hn;
struct hostlist *hl = hostlist_decode (t->input);
if (!hl)
BAIL_OUT ("hostlist_decode (%s) failed!", t->input);
if (!(hn = hostlist_hostname_create (t->arg)))
BAIL_OUT ("hostlist_hostname_create (%s) failed!", t->arg);
rc = hostlist_find_hostname (hl, hn);
ok (rc == t->rc,
"hostlist_find_hostname ('%s', '%s') returned %d",
t->input, t->arg, rc);
if (t->rc >= 0)
is (hostlist_current (hl), t->arg,
"hostlist_find leaves cursor pointing to found host");
hostlist_hostname_destroy (hn);
hostlist_destroy (hl);
t++;
}
}


struct delete_test {
char *input;
char *delete;
Expand Down Expand Up @@ -616,6 +645,7 @@ int main (int argc, char *argv[])
test_append ();
test_nth ();
test_find ();
test_find_hostname ();
test_delete ();
test_sortuniq ();
test_iteration ();
Expand Down

0 comments on commit 6fc817c

Please sign in to comment.