commit 2fdf78e7753a1b717267e84370b9079b8ecf9e1a Author: Jeff Garzik <jeff@xxxxxxxxxx> Date: Sun Mar 7 17:17:18 2010 -0500 [test] add test for storage/retrieval of x-amz-meta-* HTTP headers Also, - move now-common code into a new internal libtest.a library. - update hdr-content-type.c copyright header to 2010 Signed-off-by: Jeff Garzik <jgarzik@xxxxxxxxxx> diff --git a/test/.gitignore b/test/.gitignore index 26ba541..1cc58b4 100644 --- a/test/.gitignore +++ b/test/.gitignore @@ -1,9 +1,13 @@ .libs + +libtest.a + basic-bucket basic-object it-works large-object wait-for-listen hdr-content-type +hdr-meta diff --git a/test/Makefile.am b/test/Makefile.am index 62b279e..3d751bc 100644 --- a/test/Makefile.am +++ b/test/Makefile.am @@ -25,19 +25,24 @@ TESTS = \ basic-object \ large-object \ hdr-content-type \ + hdr-meta \ stop-daemon \ clean-db check_PROGRAMS = basic-bucket basic-object it-works large-object \ - hdr-content-type wait-for-listen + hdr-content-type hdr-meta wait-for-listen + +noinst_LIBRARIES = libtest.a TESTLDADD = ../lib/libhttpstor.la \ ../lib/libhttputil.a \ + libtest.a \ @LIBCURL@ @GLIB_LIBS@ @CRYPTO_LIBS@ @XML_LIBS@ basic_bucket_LDADD = $(TESTLDADD) basic_object_LDADD = $(TESTLDADD) large_object_LDADD = $(TESTLDADD) hdr_content_type_LDADD = $(TESTLDADD) +hdr_meta_LDADD = $(TESTLDADD) it_works_LDADD = $(TESTLDADD) wait_for_listen_LDADD = ../lib/libhttputil.a diff --git a/test/hdr-content-type.c b/test/hdr-content-type.c index 0fc3641..f798638 100644 --- a/test/hdr-content-type.c +++ b/test/hdr-content-type.c @@ -1,6 +1,6 @@ /* - * Copyright 2008-2009 Red Hat, Inc. + * Copyright 2008-2010 Red Hat, Inc. * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by @@ -16,12 +16,6 @@ * the Free Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA. * */ -/* - * A large object test verifies the workings of bizarrely complicated and - * subtle mechanics of the sliding windows and flow control when tabled - * pipes the data between its client and the back-end chunkservers. - * As such, we have to defend against hungs as well as corruption. - */ #define _GNU_SOURCE #include "tabled-config.h" @@ -44,41 +38,6 @@ static char *user_hdrs[] = { NULL }; -static bool find_our_hdr(const void *data, size_t data_len) -{ - const void *p = data; - size_t len = data_len; - - while (len > 0) { - void *eol; - size_t llen, real_len; - const char *s; - - eol = memchr(p, '\n', len); - if (!eol) - llen = len; - else - llen = eol - p + 1; - - real_len = llen; - s = p; - while (real_len > 0) { - if (!isspace(s[real_len - 1])) - break; - - real_len--; - } - - if (!strncasecmp(user_hdrs[0], p, real_len)) - return true; - - p += llen; - len -= llen; - } - - return false; -} - static void runtest(struct httpstor_client *httpstor) { bool rcb; @@ -93,7 +52,7 @@ static void runtest(struct httpstor_client *httpstor) OK(data); OK(data_len > 0); - rcb = find_our_hdr(data, data_len); + rcb = find_our_hdr(user_hdrs[0], data, data_len); OK(rcb); free(data); diff --git a/test/hdr-meta.c b/test/hdr-meta.c new file mode 100644 index 0000000..424006c --- /dev/null +++ b/test/hdr-meta.c @@ -0,0 +1,96 @@ + +/* + * Copyright 2008-2010 Red Hat, Inc. + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; see the file COPYING. If not, write to + * the Free Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA. + * + */ + +#define _GNU_SOURCE +#include "tabled-config.h" + +#include <stdbool.h> +#include <string.h> +#include <stdlib.h> +#include <ctype.h> +#include <locale.h> +#include <httpstor.h> +#include <httputil.h> +#include "test.h" + +static char bucket[] = "test-hdr-meta"; +static char key[] = "Key of HDR meta test"; +static char value[] = "Value of HDR meta test"; + +static char *user_hdrs[] = { + "x-amz-meta-test1: foo bar", + "x-amz-meta-test2: foo bar baz zonk zip", + NULL +}; + +static void runtest(struct httpstor_client *httpstor) +{ + bool rcb; + void *data = NULL; + size_t data_len = 0; + int idx; + + rcb = httpstor_put_inline(httpstor, bucket, key, + value, strlen(value) + 1, user_hdrs); + OK(rcb); + + data = httpstor_get_inline(httpstor, bucket, key, true, &data_len); + OK(data); + OK(data_len > 0); + + idx = 0; + while (user_hdrs[idx]) { + rcb = find_our_hdr(user_hdrs[idx], data, data_len); + OK(rcb); + + idx++; + } + + free(data); +} + +int main(int argc, char *argv[]) +{ + struct httpstor_client *httpstor; + char accbuf[80]; + int rc; + bool rcb; + + setlocale(LC_ALL, "C"); + + rc = tb_readport(TEST_FILE_TB, accbuf, sizeof(accbuf)); + OK(rc > 0); + + httpstor = httpstor_new(accbuf, TEST_HOST, TEST_USER, TEST_USER_KEY); + OK(httpstor); + + /* add bucket - since tests are independent, we do not rely on others */ + rcb = httpstor_add_bucket(httpstor, bucket); + OK(rcb); + + runtest(httpstor); + + rcb = httpstor_del(httpstor, bucket, key); + OK(rcb); + + rcb = httpstor_del_bucket(httpstor, bucket); + OK(rcb); + + return 0; +} diff --git a/test/libtest.c b/test/libtest.c new file mode 100644 index 0000000..ef07778 --- /dev/null +++ b/test/libtest.c @@ -0,0 +1,62 @@ + +/* + * Copyright 2010 Red Hat, Inc. + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; see the file COPYING. If not, write to + * the Free Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA. + * + */ + +#include <string.h> +#include <stdbool.h> +#include <ctype.h> + +bool find_our_hdr(const char *hdr, const void *data, size_t data_len) +{ + const void *p = data; + size_t len = data_len; + + while (len > 0) { + void *eol; + size_t llen, real_len; + const char *s; + + eol = memchr(p, '\n', len); + if (!eol) + llen = len; + else + llen = eol - p + 1; + + real_len = llen; + s = p; + while (real_len > 0) { + if (!isspace(s[real_len - 1])) + break; + + real_len--; + } + + /* stop scan at first blank line (end of headers) */ + if (real_len == 0) + break; + + if (!strncasecmp(hdr, p, real_len)) + return true; + + p += llen; + len -= llen; + } + + return false; +} + diff --git a/test/test.h b/test/test.h index e627a0c..50b7e36 100644 --- a/test/test.h +++ b/test/test.h @@ -38,4 +38,6 @@ } \ } while (0) +extern bool find_our_hdr(const char *hdr, const void *data, size_t data_len); + #endif /* __TABLED_TEST_H__ */ -- To unsubscribe from this list: send the line "unsubscribe hail-devel" in the body of a message to majordomo@xxxxxxxxxxxxxxx More majordomo info at http://vger.kernel.org/majordomo-info.html