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

Function test_reftable_stack__add_one

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

Source from the content-addressed store, hash-verified

150}
151
152void test_reftable_stack__add_one(void)
153{
154 char *dir = get_tmp_dir(__LINE__);
155 struct reftable_buf scratch = REFTABLE_BUF_INIT;
156 int mask = umask(002);
157 struct reftable_write_options opts = {
158 .default_permissions = 0660,
159 };
160 struct reftable_stack *st = NULL;
161 struct reftable_ref_record ref = {
162 .refname = (char *) "HEAD",
163 .update_index = 1,
164 .value_type = REFTABLE_REF_SYMREF,
165 .value.symref = (char *) "master",
166 };
167 struct reftable_ref_record dest = { 0 };
168 struct stat stat_result = { 0 };
169 int err;
170
171 err = reftable_new_stack(&st, dir, &opts);
172 cl_assert(!err);
173
174 err = reftable_stack_add(st, write_test_ref, &ref, 0);
175 cl_assert(!err);
176
177 err = reftable_stack_read_ref(st, ref.refname, &dest);
178 cl_assert(!err);
179 cl_assert(reftable_ref_record_equal(&ref, &dest,
180 REFTABLE_HASH_SIZE_SHA1));
181 cl_assert(st->tables_len > 0);
182
183#ifndef GIT_WINDOWS_NATIVE
184 cl_assert_equal_i(reftable_buf_addstr(&scratch, dir), 0);
185 cl_assert_equal_i(reftable_buf_addstr(&scratch,
186 "/tables.list"), 0);
187 cl_assert_equal_i(stat(scratch.buf, &stat_result), 0);
188 cl_assert_equal_i((stat_result.st_mode & 0777),
189 opts.default_permissions);
190
191 reftable_buf_reset(&scratch);
192 cl_assert_equal_i(reftable_buf_addstr(&scratch, dir), 0);
193 cl_assert_equal_i(reftable_buf_addstr(&scratch, "/"), 0);
194 /* do not try at home; not an external API for reftable. */
195 cl_assert(!reftable_buf_addstr(&scratch, st->tables[0]->name));
196 err = stat(scratch.buf, &stat_result);
197 cl_assert(!err);
198 cl_assert_equal_i((stat_result.st_mode & 0777),
199 opts.default_permissions);
200#else
201 (void) stat_result;
202#endif
203
204 reftable_ref_record_release(&dest);
205 reftable_stack_destroy(st);
206 reftable_buf_release(&scratch);
207 clear_dir(dir);
208 umask(mask);
209}

Callers

nothing calls this directly

Calls 12

get_tmp_dirFunction · 0.85
reftable_new_stackFunction · 0.85
reftable_stack_addFunction · 0.85
reftable_stack_read_refFunction · 0.85
reftable_buf_addstrFunction · 0.85
reftable_buf_resetFunction · 0.85
reftable_stack_destroyFunction · 0.85
reftable_buf_releaseFunction · 0.85
clear_dirFunction · 0.85
statClass · 0.70

Tested by

no test coverage detected