Skip to content

Commit 452b5d6

Browse files
committed
more tests
gufi_query -Q without -I test parallel_cpr directory to file clear trie user data
1 parent 51bab8c commit 452b5d6

File tree

7 files changed

+34
-25
lines changed

7 files changed

+34
-25
lines changed

src/gufi_query/validate_inputs.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -135,7 +135,7 @@ int validate_inputs(struct input *in) {
135135
/* -Q requires -I */
136136
if (sll_get_size(&in->external_attach)) {
137137
if (!in->sql.init.len) {
138-
fprintf(stderr, "External databases require template files attached with -I [%s]\n", in->sql.init.data);
138+
fprintf(stderr, "External databases require template files attached with -I\n");
139139
return -1;
140140
}
141141
}

src/parallel_cpr.c

Lines changed: 10 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -291,31 +291,16 @@ static int cpr_dir(QPTPool_t *ctx, const size_t id, void *data, void *args) {
291291
}
292292

293293
static int setup(const refstr_t *dst) {
294-
const mode_t mode = umask(0);
295-
const uid_t uid = geteuid();
296-
const uid_t gid = getegid();
297-
298-
umask(mode); /* reset umask */
299-
300-
/* should copy because mkpath modifies the string */
301-
char *path = malloc(dst->len + 1);
302-
SNFORMAT_S(path, dst->len + 1, 1,
303-
dst->data, dst->len);
304-
305-
int rc = mkpath(path, ~mode & 0777, uid, gid);
306-
const int err = errno;
294+
struct stat st;
295+
st.st_mode = umask(0);
296+
st.st_uid = geteuid();
297+
st.st_gid = getegid();
307298

308-
free(path);
299+
umask(st.st_mode); /* reset umask */
309300

310-
if (rc != 0) {
311-
if (err != EEXIST) {
312-
return err;
313-
}
301+
st.st_mode = ~st.st_mode & 0777;
314302

315-
rc = 0;
316-
}
317-
318-
return rc;
303+
return dupdir(dst->data, &st);
319304
}
320305

321306
static void sub_help(void) {
@@ -340,6 +325,9 @@ int main(int argc, char * argv[]) {
340325
}
341326

342327
if (setup(&in.nameto) != 0) {
328+
const int err = errno;
329+
fprintf(stderr, "Error: Cannot copy to \"%s\": %s (%d)\n",
330+
in.nameto.data, strerror(err), err);
343331
input_fini(&in);
344332
return EXIT_FAILURE;
345333
}

test/regression/gufi_query.expected

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -244,6 +244,10 @@ Error: Missing -I
244244
$ gufi_query -O outdb -K "create;" "prefix"
245245
Error: Missing -I
246246

247+
# Missing -I (external databases)
248+
$ gufi_query -Q "external" "user" "data" "base" "prefix"
249+
External databases require template files attached with -I
250+
247251
# Missing -J (aggregate, stdout)
248252
$ gufi_query -I "create" -S "insert;" -E "insert;" -K "create;" -G "query;" "prefix"
249253
Error: Missing -J

test/regression/gufi_query.sh.in

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -127,6 +127,9 @@ run_no_sort "${GUFI_QUERY} -o outfile -K \
127127
echo "# Missing -I (aggregating, outdb)"
128128
run_no_sort "${GUFI_QUERY} -O outdb -K \"create;\" \"${INDEXROOT}\""
129129

130+
echo "# Missing -I (external databases)"
131+
run_no_sort "${GUFI_QUERY} -Q \"external\" \"user\" \"data\" \"base\" \"${INDEXROOT}\""
132+
130133
echo "# Missing -J (aggregate, stdout)"
131134
run_no_sort "${GUFI_QUERY} -I \"create\" -S \"insert;\" -E \"insert;\" -K \"create;\" -G \"query;\" \"${INDEXROOT}\""
132135

test/regression/parallel_cpr.expected

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -122,3 +122,6 @@ Error: Cannot lstat "badtrace": No such file or directory (2)
122122
$ parallel_cpr /dev/null "copy"
123123
Not copying "/dev/null"
124124

125+
$ parallel_cpr "prefix" "prefix/old_file"
126+
Error: Cannot copy to "prefix/old_file": File exists (17)
127+

test/regression/parallel_cpr.sh.in

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -139,6 +139,9 @@ run_no_sort "${PARALLEL_CPR} \"${BADTRACE}\" \"${CPR_ROOT}\""
139139

140140
# non-directory/link/file source
141141
run_no_sort "${PARALLEL_CPR} /dev/null \"${CPR_ROOT}\""
142+
143+
# directory to file
144+
run_no_sort "${PARALLEL_CPR} \"${SRCDIR}\" \"${SRCDIR}/old_file\""
142145
set -e
143146
) | tee "${OUTPUT}"
144147

test/unit/googletest/trie.cpp

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -95,8 +95,11 @@ TEST(trie, insert_empty) {
9595
trie_t *root = trie_alloc();
9696
ASSERT_NE(root, nullptr);
9797

98-
trie_insert(root, buf, 0, nullptr, nullptr);
98+
trie_insert(root, buf, 0, nullptr, [](void *) {});
99+
EXPECT_EQ(trie_search(root, buf, 0, nullptr), 1);
99100

101+
// replace previous value, running user free fucntion
102+
trie_insert(root, buf, 0, nullptr, nullptr);
100103
EXPECT_EQ(trie_search(root, buf, 0, nullptr), 1);
101104

102105
trie_free(root);
@@ -140,13 +143,18 @@ TEST(trie, delete) {
140143
{
141144
/* insert long string and sub string */
142145
trie_insert(root, str, str_len, nullptr, nullptr);
143-
trie_insert(root, str, sub_len, nullptr, nullptr);
146+
trie_insert(root, str, sub_len, nullptr, [](void *) {});
144147
EXPECT_EQ(trie_search(root, str, str_len, nullptr), 1);
145148
EXPECT_EQ(trie_search(root, str, sub_len, nullptr), 1);
146149

147150
/* shorter string is deleted, but the longer string remains */
148151
EXPECT_EQ(trie_delete(root, str, sub_len), 0);
149152
EXPECT_NE(root, nullptr);
153+
154+
/* insert and remove sub string again without a free user function */
155+
trie_insert(root, str, sub_len, nullptr, nullptr));
156+
EXPECT_EQ(trie_search(root, str, sub_len, nullptr), 1);
157+
150158
EXPECT_EQ(trie_search(root, str, str_len, nullptr), 1);
151159
EXPECT_EQ(trie_search(root, str, sub_len, nullptr), 0);
152160
}

0 commit comments

Comments
 (0)