The data (HTTP headers) are generated by the `%mfs_httpheader` macro which writes them to a temporary file (`header.txt`) within the `WORK` library. The script then reads this file to validate its content. No persistent external data source is used.
1 Code Block
MACRO CALLS and DATA STEP Data
Explanation : This block initializes the header file location (`sasjs_stpsrv_header_loc`) to a temporary path in the `WORK` library. It uses `%mp_assertscope` to mark a reference point before calling `%mfs_httpheader` to write the 'Content-Type: application/csv' header. A `DATA _NULL_` is then used to read the first line of this file and store its content in the macro variable `test1`. Finally, two assertions with `%mp_assert` verify that the execution was error-free (`&syscc=0`) and that the written header is correct.
Copied!
%let orig_sasjs_stpsrv_header_loc=&sasjs_stpsrv_header_loc;
%let sasjs_stpsrv_header_loc=%sysfunc(pathname(work))/header.txt;
%mp_assertscope(SNAPSHOT)
%mfs_httpheader(Content-Type,application/csv)
%mp_assertscope(COMPARE,ignorelist=sasjs_stpsrv_header_loc)
data _null_;
infile "&sasjs_stpsrv_header_loc";
input;
if _n_=1 then call symputx('test1',_infile_);
run;
%mp_assert(
iftrue=(&syscc=0),
desc=Check code ran without errors,
outds=work.test_results
)
%mp_assert(
iftrue=("&test1"="Content-Type: application/csv"),
desc=Checking line was created,
outds=work.test_results
)
Explanation : This second test block repeats the process by calling `%mfs_httpheader` with 'Content-Type: application/text'. A `DATA _NULL_` reads the second line of the header file and its content is stored in `test2`. Two assertions are performed to validate the execution and the content of the updated header. The block concludes by resetting the `sasjs_stpsrv_header_loc` variable to its original value, cleaning the environment for future executions or other tests.
Copied!
%mfs_httpheader(Content-Type,application/text)
%let test2=0;
data _null_;
infile "&sasjs_stpsrv_header_loc";
input;
if _n_=2 then call symputx('test2',_infile_);
run;
%mp_assert(
iftrue=(&syscc=0),
desc=Check code ran without errors for test2,
outds=work.test_results
)
%mp_assert(
iftrue=("&test2"="Content-Type: application/text"),
desc=Checking line was created,
outds=work.test_results
)
/* reset header so the test will pass */
%let sasjs_stpsrv_header_loc=&orig_sasjs_stpsrv_header_loc;
This material is provided "as is" by We Are Cas. There are no warranties, expressed or implied, as to merchantability or fitness for a particular purpose regarding the materials or code contained herein. We Are Cas is not responsible for errors in this material as it now exists or will exist, nor does We Are Cas provide technical support for it.
Copyright Info : Copyright 2010-2023 HMS Analytical Software GmbH, http://www.analytical-software.de. This file is part of SASUnit, the unit testing framework for SAS(R) programs. For copyright information and terms of use under the GNU Lesser General Public License, see the included README.md file or https://github.com/HMS-Analytical-Software/SASUnit/wiki/readme/.
SAS and all other SAS Institute Inc. product or service names are registered trademarks or trademarks of SAS Institute Inc. in the USA and other countries. ® indicates USA registration. WeAreCAS is an independent community site and is not affiliated with SAS Institute Inc.
This site uses technical and analytical cookies to improve your experience.
Read more.