Skip to content

Commit

Permalink
test: add libkvs/getroot unit test
Browse files Browse the repository at this point in the history
  • Loading branch information
garlick committed Aug 21, 2018
1 parent 9fc2760 commit c24c616
Show file tree
Hide file tree
Showing 2 changed files with 87 additions and 0 deletions.
5 changes: 5 additions & 0 deletions src/common/libkvs/Makefile.am
Expand Up @@ -42,6 +42,7 @@ TESTS = \
test_kvs_dir.t \
test_kvs_commit.t \
test_kvs_watch.t \
test_kvs_getroot.t \
test_treeobj.t

check_PROGRAMS = \
Expand Down Expand Up @@ -89,6 +90,10 @@ test_kvs_watch_t_SOURCES = test/kvs_watch.c
test_kvs_watch_t_CPPFLAGS = $(test_cppflags)
test_kvs_watch_t_LDADD = $(test_ldadd) $(LIBDL)

test_kvs_getroot_t_SOURCES = test/kvs_getroot.c
test_kvs_getroot_t_CPPFLAGS = $(test_cppflags)
test_kvs_getroot_t_LDADD = $(test_ldadd) $(LIBDL)

test_treeobj_t_SOURCES = test/treeobj.c
test_treeobj_t_CPPFLAGS = $(test_cppflags)
test_treeobj_t_LDADD = $(test_ldadd) $(LIBDL)
82 changes: 82 additions & 0 deletions src/common/libkvs/test/kvs_getroot.c
@@ -0,0 +1,82 @@
#if HAVE_CONFIG_H
#include "config.h"
#endif

#include <string.h>
#include <errno.h>
#include <flux/core.h>

#include "src/common/libflux/flux.h"
#include "kvs_getroot.h"
#include "src/common/libtap/tap.h"

void errors (void)
{
flux_t *h = (flux_t *)(uintptr_t)42; // fake but non-NULL
flux_future_t *f;
const char *s;
int i;
uint32_t u32;

/* check simple error cases */
if (!(f = flux_future_create (NULL, NULL)))
BAIL_OUT ("flux_future_create failed");

errno = 0;
ok (flux_kvs_getroot (NULL, "foo", 0) == NULL && errno == EINVAL,
"flux_kvs_getroot h=NULL fails with EINVAL");
errno = 0;
ok (flux_kvs_getroot (h, "foo", 0xff) == NULL && errno == EINVAL,
"flux_kvs_getroot flags=(inval) fails with EINVAL");
errno = 0;
ok (flux_kvs_getroot_get_blobref (NULL, &s) < 0 && errno == EINVAL,
"flux_kvs_getroot_get_blobref f=NULL fails with EINVAL");
errno = 0;
ok (flux_kvs_getroot_get_blobref (f, NULL) < 0 && errno == EINVAL,
"flux_kvs_getroot_get_blobref blobref=NULL fails with EINVAL");
errno = 0;
ok (flux_kvs_getroot_get_sequence (NULL, &i) < 0 && errno == EINVAL,
"flux_kvs_getroot_get_sequence f=NULL fails with EINVAL");
errno = 0;
ok (flux_kvs_getroot_get_sequence (f, NULL) < 0 && errno == EINVAL,
"flux_kvs_getroot_get_sequence sequence=NULL fails with EINVAL");
errno = 0;
ok (flux_kvs_getroot_get_owner (NULL, &u32) < 0 && errno == EINVAL,
"flux_kvs_getroot_get_owner f=NULL fails with EINVAL");
errno = 0;
ok (flux_kvs_getroot_get_owner (f, NULL) < 0 && errno == EINVAL,
"flux_kvs_getroot_get_owner owner=NULL fails with EINVAL");
errno = 0;
ok (flux_kvs_getroot_get_treeobj (NULL, &s) < 0 && errno == EINVAL,
"flux_kvs_getroot_get_treeobj f=NULL fails with EINVAL");
errno = 0;
ok (flux_kvs_getroot_get_treeobj (f, NULL) < 0 && errno == EINVAL,
"flux_kvs_getroot_get_treeobj treeobj=NULL fails with EINVAL");
errno = 0;
ok (flux_kvs_getroot_get_treeobj (f, &s) < 0 && errno == EINVAL,
"flux_kvs_getroot_get_treeobj f=(non-getroot) fails with EINVAL");
errno = 0;
ok (flux_kvs_getroot_cancel (NULL) < 0 && errno == EINVAL,
"flux_kvs_getroot_cancel f=NULL fails with EINVAL");
errno = 0;
ok (flux_kvs_getroot_cancel (f) < 0 && errno == EINVAL,
"flux_kvs_getroot_cancel f=(non-getroot) fails with EINVAL");

flux_future_destroy (f);
}

int main (int argc, char *argv[])
{

plan (NO_PLAN);

errors ();

done_testing();
return (0);
}

/*
* vi:tabstop=4 shiftwidth=4 expandtab
*/

0 comments on commit c24c616

Please sign in to comment.