1
0
mirror of https://github.com/moparisthebest/curl synced 2024-11-12 04:25:08 -05:00

test 970: verify --write-out '%{json}'

Makes curl_easy_getinfo() of "variable" numerical content instead return
the number set in the env variable `CURL_TIME`.

Makes curl_version() of "variable" textual content. This guarantees a
stable version string which can be tested against. Environment variable
`CURL_VERSION` defines the content.

Assisted-by: Mathias Gumz
This commit is contained in:
Daniel Stenberg 2020-02-09 00:04:05 +01:00
parent 04c03416e6
commit 7631f2b752
No known key found for this signature in database
GPG Key ID: 5CC908FDB71E12C2
3 changed files with 136 additions and 3 deletions

View File

@ -5,7 +5,7 @@
* | (__| |_| | _ <| |___ * | (__| |_| | _ <| |___
* \___|\___/|_| \_\_____| * \___|\___/|_| \_\_____|
* *
* Copyright (C) 1998 - 2019, Daniel Stenberg, <daniel@haxx.se>, et al. * Copyright (C) 1998 - 2020, Daniel Stenberg, <daniel@haxx.se>, et al.
* *
* This software is licensed as described in the file COPYING, which * This software is licensed as described in the file COPYING, which
* you should have received as part of this distribution. The terms * you should have received as part of this distribution. The terms
@ -147,6 +147,20 @@ static CURLcode getinfo_long(struct Curl_easy *data, CURLINFO info,
long *to_long; long *to_long;
} lptr; } lptr;
#ifdef DEBUGBUILD
char *timestr = getenv("CURL_TIME");
if(timestr) {
unsigned long val = strtol(timestr, NULL, 10);
switch(info) {
case CURLINFO_LOCAL_PORT:
*param_longp = (long)val;
return CURLE_OK;
default:
break;
}
}
#endif
switch(info) { switch(info) {
case CURLINFO_RESPONSE_CODE: case CURLINFO_RESPONSE_CODE:
*param_longp = data->info.httpcode; *param_longp = data->info.httpcode;
@ -258,6 +272,27 @@ static CURLcode getinfo_long(struct Curl_easy *data, CURLINFO info,
static CURLcode getinfo_offt(struct Curl_easy *data, CURLINFO info, static CURLcode getinfo_offt(struct Curl_easy *data, CURLINFO info,
curl_off_t *param_offt) curl_off_t *param_offt)
{ {
#ifdef DEBUGBUILD
char *timestr = getenv("CURL_TIME");
if(timestr) {
unsigned long val = strtol(timestr, NULL, 10);
switch(info) {
case CURLINFO_TOTAL_TIME_T:
case CURLINFO_NAMELOOKUP_TIME_T:
case CURLINFO_CONNECT_TIME_T:
case CURLINFO_APPCONNECT_TIME_T:
case CURLINFO_PRETRANSFER_TIME_T:
case CURLINFO_STARTTRANSFER_TIME_T:
case CURLINFO_REDIRECT_TIME_T:
case CURLINFO_SPEED_DOWNLOAD_T:
case CURLINFO_SPEED_UPLOAD_T:
*param_offt = (curl_off_t)val;
return CURLE_OK;
default:
break;
}
}
#endif
switch(info) { switch(info) {
case CURLINFO_FILETIME_T: case CURLINFO_FILETIME_T:
*param_offt = (curl_off_t)data->info.filetime; *param_offt = (curl_off_t)data->info.filetime;
@ -282,7 +317,7 @@ static CURLcode getinfo_offt(struct Curl_easy *data, CURLINFO info,
*param_offt = (data->progress.flags & PGRS_UL_SIZE_KNOWN)? *param_offt = (data->progress.flags & PGRS_UL_SIZE_KNOWN)?
data->progress.size_ul:-1; data->progress.size_ul:-1;
break; break;
case CURLINFO_TOTAL_TIME_T: case CURLINFO_TOTAL_TIME_T:
*param_offt = data->progress.timespent; *param_offt = data->progress.timespent;
break; break;
case CURLINFO_NAMELOOKUP_TIME_T: case CURLINFO_NAMELOOKUP_TIME_T:
@ -316,6 +351,27 @@ static CURLcode getinfo_offt(struct Curl_easy *data, CURLINFO info,
static CURLcode getinfo_double(struct Curl_easy *data, CURLINFO info, static CURLcode getinfo_double(struct Curl_easy *data, CURLINFO info,
double *param_doublep) double *param_doublep)
{ {
#ifdef DEBUGBUILD
char *timestr = getenv("CURL_TIME");
if(timestr) {
unsigned long val = strtol(timestr, NULL, 10);
switch(info) {
case CURLINFO_TOTAL_TIME:
case CURLINFO_NAMELOOKUP_TIME:
case CURLINFO_CONNECT_TIME:
case CURLINFO_APPCONNECT_TIME:
case CURLINFO_PRETRANSFER_TIME:
case CURLINFO_STARTTRANSFER_TIME:
case CURLINFO_REDIRECT_TIME:
case CURLINFO_SPEED_DOWNLOAD:
case CURLINFO_SPEED_UPLOAD:
*param_doublep = (double)val;
return CURLE_OK;
default:
break;
}
}
#endif
switch(info) { switch(info) {
case CURLINFO_TOTAL_TIME: case CURLINFO_TOTAL_TIME:
*param_doublep = DOUBLE_SECS(data->progress.timespent); *param_doublep = DOUBLE_SECS(data->progress.timespent);

View File

@ -110,7 +110,7 @@ test927 test928 test929 test930 test931 test932 test933 test934 test935 \
test936 test937 test938 test939 test940 test941 test942 test943 test944 \ test936 test937 test938 test939 test940 test941 test942 test943 test944 \
test945 test946 test947 test948 test949 test950 test951 test952 test953 \ test945 test946 test947 test948 test949 test950 test951 test952 test953 \
test954 test955 test956 test957 test958 test959 test960 test961 test962 \ test954 test955 test956 test957 test958 test959 test960 test961 test962 \
test963 test964 test965 test966 test967 test968 test969 \ test963 test964 test965 test966 test967 test968 test969 test970 \
\ \
test1000 test1001 test1002 test1003 test1004 test1005 test1006 test1007 \ test1000 test1001 test1002 test1003 test1004 test1005 test1006 test1007 \
test1008 test1009 test1010 test1011 test1012 test1013 test1014 test1015 \ test1008 test1009 test1010 test1011 test1012 test1013 test1014 test1015 \

77
tests/data/test970 Normal file
View File

@ -0,0 +1,77 @@
<testcase>
<info>
<keywords>
HTTP
HTTP GET
</keywords>
</info>
#
# Server-side
<reply>
<data nocheck="yes">
HTTP/1.1 200 OK
Date: Thu, 09 Nov 2010 14:49:00 GMT
Server: test-server/fake
Last-Modified: Tue, 13 Jun 2000 12:10:00 GMT
ETag: "21025-dc7-39462498"
Accept-Ranges: bytes
Content-Length: 6
Connection: close
Content-Type: text/html
Funny-head: yesyes
-foo-
</data>
</reply>
#
# Client-side
<client>
<server>
http
</server>
<features>
debug
</features>
<setenv>
CURL_TIME=13
CURL_VERSION=curl-unit-test-fake-version
</setenv>
<name>
HTTP GET with JSON output
</name>
<command>
http://%HOSTIP:%HTTPPORT/970 --write-out '%{json}'
</command>
</client>
#
# Verify data after the test has been "shot"
<verify>
<strip>
^User-Agent:.*
</strip>
<protocol>
GET /970 HTTP/1.1
Host: %HOSTIP:%HTTPPORT
Accept: */*
</protocol>
<stdout nonewline="yes">
HTTP/1.1 200 OK
Date: Thu, 09 Nov 2010 14:49:00 GMT
Server: test-server/fake
Last-Modified: Tue, 13 Jun 2000 12:10:00 GMT
ETag: "21025-dc7-39462498"
Accept-Ranges: bytes
Content-Length: 6
Connection: close
Content-Type: text/html
Funny-head: yesyes
-foo-
{"url_effective":"http://127.0.0.1:8990/970","http_code":200,"response_code":200,"http_connect":0,"time_total":0.000013,"time_namelookup":0.000013,"time_connect":0.000013,"time_appconnect":0.000013,"time_pretransfer":0.000013,"time_starttransfer":0.000013,"size_header":250,"size_request":85,"size_download":6,"size_upload":0,"speed_download":0.000013,"speed_upload":0.000013,"content_type":"text/html","num_connects":1,"time_redirect":0.000013,"num_redirects":0,"ssl_verify_result":0,"proxy_ssl_verify_result":0,"filename_effective":null,"remote_ip":"127.0.0.1","remote_port":8990,"local_ip":"127.0.0.1","local_port":13,"http_version":"1.1","scheme":"HTTP","curl_version":"curl-unit-test-fake-version"}
</stdout>
</verify>
</testcase>