MCPcopy Create free account
hub / github.com/git/git / test_reftable_stack__add

Function test_reftable_stack__add

t/unit-tests/u-reftable-stack.c:486–583  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

484}
485
486void test_reftable_stack__add(void)
487{
488 struct reftable_write_options opts = {
489 .exact_log_message = 1,
490 .default_permissions = 0660,
491 .disable_auto_compact = 1,
492 };
493 struct reftable_stack *st = NULL;
494 char *dir = get_tmp_dir(__LINE__);
495 struct reftable_ref_record refs[2] = { 0 };
496 struct reftable_log_record logs[2] = { 0 };
497 struct reftable_buf path = REFTABLE_BUF_INIT;
498 struct stat stat_result;
499 size_t i, N = ARRAY_SIZE(refs);
500 int err = 0;
501
502 err = reftable_new_stack(&st, dir, &opts);
503 cl_assert(!err);
504
505 for (i = 0; i < N; i++) {
506 char buf[256];
507 snprintf(buf, sizeof(buf), "branch%02"PRIuMAX, (uintmax_t)i);
508 refs[i].refname = xstrdup(buf);
509 refs[i].update_index = i + 1;
510 refs[i].value_type = REFTABLE_REF_VAL1;
511 cl_reftable_set_hash(refs[i].value.val1, i,
512 REFTABLE_HASH_SHA1);
513
514 logs[i].refname = xstrdup(buf);
515 logs[i].update_index = N + i + 1;
516 logs[i].value_type = REFTABLE_LOG_UPDATE;
517 logs[i].value.update.email = xstrdup("identity@invalid");
518 cl_reftable_set_hash(logs[i].value.update.new_hash, i,
519 REFTABLE_HASH_SHA1);
520 }
521
522 for (i = 0; i < N; i++)
523 cl_assert_equal_i(reftable_stack_add(st, write_test_ref,
524 &refs[i], 0), 0);
525
526 for (i = 0; i < N; i++) {
527 struct write_log_arg arg = {
528 .log = &logs[i],
529 .update_index = reftable_stack_next_update_index(st),
530 };
531 cl_assert_equal_i(reftable_stack_add(st, write_test_log,
532 &arg, 0), 0);
533 }
534
535 cl_assert_equal_i(reftable_stack_compact_all(st, NULL), 0);
536
537 for (i = 0; i < N; i++) {
538 struct reftable_ref_record dest = { 0 };
539
540 cl_assert_equal_i(reftable_stack_read_ref(st,
541 refs[i].refname, &dest), 0);
542 cl_assert(reftable_ref_record_equal(&dest, refs + i,
543 REFTABLE_HASH_SIZE_SHA1) != 0);

Callers

nothing calls this directly

Calls 15

get_tmp_dirFunction · 0.85
reftable_new_stackFunction · 0.85
xstrdupFunction · 0.85
cl_reftable_set_hashFunction · 0.85
reftable_stack_addFunction · 0.85
reftable_stack_read_refFunction · 0.85
reftable_stack_read_logFunction · 0.85

Tested by

no test coverage detected