aboutsummaryrefslogtreecommitdiff
path: root/tests/test_download.c
diff options
context:
space:
mode:
authorJoseph Hunkeler <jhunkeler@gmail.com>2024-10-30 10:48:51 -0400
committerJoseph Hunkeler <jhunkeler@gmail.com>2024-10-30 10:48:51 -0400
commit252f9425fc9a5fc8a7e152772b7af67ff7869652 (patch)
treeaccdb5aeba48c719a1605fbe70a684ba834fdad6 /tests/test_download.c
parent5898e7d5bef98c2c7515fe23c4160ad3dbbaf6ad (diff)
downloadstasis-252f9425fc9a5fc8a7e152772b7af67ff7869652.tar.gz
Fixes download test
* NGINX updated and changed the default error page source code * Look for "404" in the page contents
Diffstat (limited to 'tests/test_download.c')
-rw-r--r--tests/test_download.c21
1 files changed, 17 insertions, 4 deletions
diff --git a/tests/test_download.c b/tests/test_download.c
index ad8724e..714e614 100644
--- a/tests/test_download.c
+++ b/tests/test_download.c
@@ -2,15 +2,20 @@
#include "download.h"
void test_download() {
+ enum MATCH_STYLE {
+ match_begins=0,
+ match_contains,
+ };
struct testcase {
const char *url;
long http_code;
+ enum MATCH_STYLE style;
const char *data;
const char *errmsg;
};
struct testcase tc[] = {
- {.url = "https://ssb.stsci.edu/jhunk/stasis_test/test_download.txt", .http_code = 200L, .data = "It works!\n", .errmsg = NULL},
- {.url = "https://ssb.stsci.edu/jhunk/stasis_test/test_download.broken", .http_code = 404L, .data = "<html", .errmsg = NULL},
+ {.url = "https://ssb.stsci.edu/jhunk/stasis_test/test_download.txt", .http_code = 200L, .data = "It works!\n", .style = match_begins, .errmsg = NULL},
+ {.url = "https://ssb.stsci.edu/jhunk/stasis_test/test_download.broken", .http_code = 404L, .data = "404", .style = match_contains, .errmsg = NULL},
{.url = "https://example.tld", .http_code = -1L, .data = NULL, .errmsg = "Couldn't resolve host name"},
};
@@ -28,10 +33,18 @@ void test_download() {
}
STASIS_ASSERT(http_code == tc[i].http_code, "expecting non-error HTTP code");
- char **data = file_readlines(filename, 0, 100, NULL);
+ //char **data = file_readlines(filename, 0, 100, NULL);
+ char *data = stasis_testing_read_ascii(filename);
if (http_code >= 0) {
STASIS_ASSERT(data != NULL, "data should not be null");
- STASIS_ASSERT(strncmp(data[0], tc[i].data, strlen(tc[i].data)) == 0, "data file does not match the expected contents");
+ printf("FILE: %s\nLOCAL: '%s'\nREMOTE: '%s'\n", tc[i].url, data, tc[i].data);
+ if (tc[i].style == match_begins) {
+ STASIS_ASSERT(strncmp(data, tc[i].data, strlen(tc[i].data)) == 0, "data file does not begin with the expected contents");
+ } else if (tc[i].style == match_contains) {
+ STASIS_ASSERT(strstr(data, tc[i].data) != NULL, "data file does not contain the expected contents");
+ } else {
+ STASIS_ASSERT(false, "Unrecognized matching mode");
+ }
} else {
STASIS_ASSERT(http_code == -1, "http_code should be -1 on fatal curl error");
STASIS_ASSERT(data == NULL, "data should be NULL on fatal curl error");