diff options
author | Joseph Hunkeler <jhunkeler@users.noreply.github.com> | 2024-10-30 12:21:20 -0400 |
---|---|---|
committer | GitHub <noreply@github.com> | 2024-10-30 12:21:20 -0400 |
commit | f25f05d8ac309b343f8e34e882d92cb8bc78eca3 (patch) | |
tree | 740bbf4fa413357d1e839bd308ab545d1271de96 /tests/test_download.c | |
parent | ec55ea8fc503ad3fb53635d7e9e6d58a63c6684a (diff) | |
parent | 3da6e513cc64990aa865613bd0bb9ba5d6624570 (diff) | |
download | stasis-f25f05d8ac309b343f8e34e882d92cb8bc78eca3.tar.gz |
Merge pull request #65 from jhunkeler/more-rt
More RT
Diffstat (limited to 'tests/test_download.c')
-rw-r--r-- | tests/test_download.c | 21 |
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"); |