Skip to content

Commit

Permalink
modules/kvs: Add corner case unit test
Browse files Browse the repository at this point in the history
Add unit test when user passes in an invalid commit to commit_process().
  • Loading branch information
chu11 committed Feb 22, 2018
1 parent bb5d1e2 commit be0f53a
Showing 1 changed file with 37 additions and 0 deletions.
37 changes: 37 additions & 0 deletions src/modules/kvs/test/commit.c
Original file line number Diff line number Diff line change
Expand Up @@ -745,6 +745,42 @@ void commit_basic_commit_process_test_multiple_fences_merge (void)
cache_destroy (cache);
}

void commit_basic_commit_process_test_invalid_commit (void)
{
struct cache *cache;
commit_mgr_t *cm;
commit_t *cbad, *c;
blobref_t rootref;

cache = create_cache_with_empty_rootdir (rootref);

ok ((cm = commit_mgr_create (cache,
KVS_PRIMARY_NAMESPACE,
"sha1",
NULL,
&test_global)) != NULL,
"commit_mgr_create works");

create_ready_commit (cm, "fence1", "key1", "1", 0, 0);
create_ready_commit (cm, "fence2", "key2", "2", 0, 0);

ok ((cbad = commit_mgr_get_ready_commit (cm)) != NULL,
"commit_mgr_get_ready_commit returns ready commit");

ok (commit_mgr_merge_ready_commits (cm) == 0,
"commit_mgr_merge_ready_commits success");

ok ((c = commit_mgr_get_ready_commit (cm)) != NULL,
"commit_mgr_get_ready_commit returns ready commit");

ok (commit_process (cbad, 1, rootref) == COMMIT_PROCESS_ERROR
&& commit_get_errnum (cbad) == EINVAL,
"commit_process fails on bad commit");

commit_mgr_destroy (cm);
cache_destroy (cache);
}

void commit_basic_root_not_dir (void)
{
struct cache *cache;
Expand Down Expand Up @@ -2304,6 +2340,7 @@ int main (int argc, char *argv[])
commit_basic_commit_process_test ();
commit_basic_commit_process_test_multiple_fences ();
commit_basic_commit_process_test_multiple_fences_merge ();
commit_basic_commit_process_test_invalid_commit ();
commit_basic_root_not_dir ();
commit_basic_iter_not_ready_tests ();
commit_process_root_missing ();
Expand Down

0 comments on commit be0f53a

Please sign in to comment.