mirror of
https://github.com/sasjs/core.git
synced 2026-01-06 17:10:05 +00:00
chore: added tests for mv_jobflow
This commit is contained in:
60
tests/base/mf_getvarlist.test.sas
Normal file
60
tests/base/mf_getvarlist.test.sas
Normal file
@@ -0,0 +1,60 @@
|
||||
/**
|
||||
@file
|
||||
@brief Testing mf_getvarlist macro
|
||||
|
||||
<h4> SAS Macros </h4>
|
||||
@li mf_getvarlist.sas
|
||||
|
||||
**/
|
||||
|
||||
|
||||
%let test1=%mf_getvarlist(sashelp.class);
|
||||
%let test2=%mf_getvarlist(sashelp.class,dlm=X);
|
||||
%let test3=%mf_getvarlist(sashelp.class,dlm=%str(,),quote=double);
|
||||
%let test4=%mf_getvarlist(sashelp.class,typefilter=N);
|
||||
%let test5=%mf_getvarlist(sashelp.class,typefilter=C);
|
||||
|
||||
data work.test_results;
|
||||
length test_description $256 test_result $4 test_comments base result $256;
|
||||
test_description="Basic test";
|
||||
base=symget('test1');
|
||||
result='Name Sex Age Height Weight';
|
||||
if base=result then test_result='PASS';
|
||||
else test_result='FAIL';
|
||||
test_comments="Comparing "!!trim(base)!!' vs '!!trim(result);
|
||||
output;
|
||||
|
||||
test_description="DLM test";
|
||||
base=symget('test2');
|
||||
result='NameXSexXAgeXHeightXWeight';
|
||||
if base=result then test_result='PASS';
|
||||
else test_result='FAIL';
|
||||
test_comments="Comparing "!!trim(base)!!' vs '!!trim(result);
|
||||
output;
|
||||
|
||||
test_description="DLM + quote test";
|
||||
base=symget('test3');
|
||||
result='"Name","Sex","Age","Height","Weight"';
|
||||
if base=result then test_result='PASS';
|
||||
else test_result='FAIL';
|
||||
test_comments="Comparing "!!trim(base)!!' vs '!!trim(result);
|
||||
output;
|
||||
|
||||
test_description="Numeric Filter";
|
||||
base=symget('test4');
|
||||
result='Age Height Weight';
|
||||
if base=result then test_result='PASS';
|
||||
else test_result='FAIL';
|
||||
test_comments="Comparing "!!trim(base)!!' vs '!!trim(result);
|
||||
output;
|
||||
|
||||
test_description="Char Filter";
|
||||
base=symget('test5');
|
||||
result='Name Sex';
|
||||
if base=result then test_result='PASS';
|
||||
else test_result='FAIL';
|
||||
test_comments="Comparing "!!trim(base)!!' vs '!!trim(result);
|
||||
output;
|
||||
|
||||
drop base result;
|
||||
run;
|
||||
36
tests/base/mp_abort.test.nofix.sas
Normal file
36
tests/base/mp_abort.test.nofix.sas
Normal file
@@ -0,0 +1,36 @@
|
||||
/**
|
||||
@file
|
||||
@brief Testing mp_abort macro
|
||||
@details This is an unfixed problem with mp_abort when using the
|
||||
'unclosed macro' technique. This is only relevant for 9.4m3 environments,
|
||||
which can suffer from hung multibridge sessions from %abort and endsas.
|
||||
|
||||
The issue is that when called within a macro, within a %include, AND that
|
||||
macro contains subsequent logic, the service does not end cleanly - rather,
|
||||
we see:
|
||||
|
||||
ERROR: %EVAL function has no expression to evaluate, or %IF statement has no condition.
|
||||
ERROR: The macro TEST will stop executing.
|
||||
|
||||
We are not able to test this without a 9.4m3 environment, it is marked as
|
||||
nofix.
|
||||
|
||||
<h4> SAS Macros </h4>
|
||||
@li mp_abort.sas
|
||||
@li mp_assert.sas
|
||||
|
||||
**/
|
||||
|
||||
%macro test();
|
||||
|
||||
filename blah temp;
|
||||
data _null_;
|
||||
file blah;
|
||||
put '%mp_abort();';
|
||||
run;
|
||||
%inc blah;
|
||||
|
||||
%if 1=1 %then %put Houston - we have a problem here;
|
||||
%mend test;
|
||||
|
||||
%test()
|
||||
32
tests/base/mp_assertcolvals.test.sas
Normal file
32
tests/base/mp_assertcolvals.test.sas
Normal file
@@ -0,0 +1,32 @@
|
||||
/**
|
||||
@file
|
||||
@brief Testing mp_assertcolvals macro
|
||||
|
||||
<h4> SAS Macros </h4>
|
||||
@li mp_assertcolvals.sas
|
||||
|
||||
**/
|
||||
|
||||
|
||||
data work.checkds;
|
||||
do checkval='Jane','James','Jill';
|
||||
output;
|
||||
end;
|
||||
run;
|
||||
%mp_assertcolvals(sashelp.class.name,
|
||||
checkvals=work.checkds.checkval,
|
||||
desc=At least one value has a match,
|
||||
test=ANYVAL
|
||||
)
|
||||
|
||||
data work.check;
|
||||
do val='M','F';
|
||||
output;
|
||||
end;
|
||||
run;
|
||||
%mp_assertcolvals(sashelp.class.sex,
|
||||
checkvals=work.check.val,
|
||||
desc=All values have a match,
|
||||
test=ALLVALS
|
||||
)
|
||||
|
||||
28
tests/base/mp_ds2fmtds.test.sas
Normal file
28
tests/base/mp_ds2fmtds.test.sas
Normal file
@@ -0,0 +1,28 @@
|
||||
/**
|
||||
@file
|
||||
@brief Testing mp_ds2fmtds.sas macro
|
||||
|
||||
<h4> SAS Macros </h4>
|
||||
@li mp_ds2fmtds.sas
|
||||
@li mp_assert.sas
|
||||
|
||||
**/
|
||||
|
||||
proc sql;
|
||||
create table test as select * from dictionary.tables where libname='SASHELP';
|
||||
|
||||
filename inc temp;
|
||||
data _null_;
|
||||
set work.test;
|
||||
file inc;
|
||||
line=cats('%mp_ds2fmtds(sashelp.',memname,',',memname,')');
|
||||
put line;
|
||||
run;
|
||||
|
||||
%inc inc;
|
||||
|
||||
%mp_assert(
|
||||
iftrue=(&syscc=0),
|
||||
desc=Checking tables were created successfully,
|
||||
outds=work.test_results
|
||||
)
|
||||
148
tests/base/mp_filtercheck.test.sas
Normal file
148
tests/base/mp_filtercheck.test.sas
Normal file
@@ -0,0 +1,148 @@
|
||||
/**
|
||||
@file
|
||||
@brief Testing mp_filtercheck macro
|
||||
|
||||
<h4> SAS Macros </h4>
|
||||
@li mp_filtercheck.sas
|
||||
@li mp_assertdsobs.sas
|
||||
@li mp_assert.sas
|
||||
|
||||
**/
|
||||
|
||||
|
||||
/* valid filter */
|
||||
data work.inds;
|
||||
infile datalines4 dsd;
|
||||
input GROUP_LOGIC:$3. SUBGROUP_LOGIC:$3. SUBGROUP_ID:8. VARIABLE_NM:$32.
|
||||
OPERATOR_NM:$10. RAW_VALUE:$4000.;
|
||||
datalines4;
|
||||
AND,AND,1,AGE,=,12
|
||||
AND,AND,1,SEX,<=,"'M'"
|
||||
AND,OR,2,Name,NOT IN,"('Jane','Alfred')"
|
||||
AND,OR,2,Weight,>=,77.7
|
||||
AND,OR,2,Weight,NE,77.7
|
||||
;;;;
|
||||
run;
|
||||
|
||||
%mp_filtercheck(work.inds,
|
||||
targetds=sashelp.class,
|
||||
outds=work.badrecords,
|
||||
abort=NO
|
||||
)
|
||||
%let syscc=0;
|
||||
%mp_assertdsobs(work.badrecords,
|
||||
desc=Valid filter query,
|
||||
test=EMPTY,
|
||||
outds=work.test_results
|
||||
)
|
||||
|
||||
/* invalid column */
|
||||
data work.inds;
|
||||
infile datalines4 dsd;
|
||||
input GROUP_LOGIC:$3. SUBGROUP_LOGIC:$3. SUBGROUP_ID:8. VARIABLE_NM:$32.
|
||||
OPERATOR_NM:$10. RAW_VALUE:$4000.;
|
||||
datalines4;
|
||||
AND,AND,1,invalid,=,12
|
||||
AND,AND,1,SEX,<=,"'M'"
|
||||
AND,OR,2,Name,NOT IN,"('Jane','Alfred')"
|
||||
AND,OR,2,Weight,>=,7
|
||||
;;;;
|
||||
run;
|
||||
%mp_filtercheck(work.inds,
|
||||
targetds=sashelp.class,
|
||||
outds=work.badrecords,
|
||||
abort=NO
|
||||
)
|
||||
%let syscc=0;
|
||||
%mp_assertdsobs(work.badrecords,
|
||||
desc=Invalid column name,
|
||||
test=HASOBS,
|
||||
outds=work.test_results
|
||||
)
|
||||
|
||||
/* invalid raw value */
|
||||
data work.inds;
|
||||
infile datalines4 dsd;
|
||||
input GROUP_LOGIC:$3. SUBGROUP_LOGIC:$3. SUBGROUP_ID:8. VARIABLE_NM:$32.
|
||||
OPERATOR_NM:$10. RAW_VALUE:$4000.;
|
||||
datalines4;
|
||||
AND,OR,2,Name,NOT IN,"(''''Jane','Alfred')"
|
||||
;;;;
|
||||
run;
|
||||
|
||||
%mp_filtercheck(work.inds,
|
||||
targetds=sashelp.class,
|
||||
outds=work.badrecords,
|
||||
abort=NO
|
||||
)
|
||||
%let syscc=0;
|
||||
%mp_assertdsobs(work.badrecords,
|
||||
desc=Invalid raw value,
|
||||
test=HASOBS,
|
||||
outds=work.test_results
|
||||
)
|
||||
|
||||
/* Code injection - column name */
|
||||
data work.inds;
|
||||
infile datalines4 dsd;
|
||||
input GROUP_LOGIC:$3. SUBGROUP_LOGIC:$3. SUBGROUP_ID:8. VARIABLE_NM:$32.
|
||||
OPERATOR_NM:$10. RAW_VALUE:$4000.;
|
||||
datalines4;
|
||||
AND,AND,1,%abort,=,12
|
||||
AND,OR,2,Weight,>=,7
|
||||
;;;;
|
||||
run;
|
||||
|
||||
%mp_filtercheck(work.inds,
|
||||
targetds=sashelp.class,
|
||||
outds=work.badrecords,
|
||||
abort=NO
|
||||
)
|
||||
%let syscc=0;
|
||||
%mp_assertdsobs(work.badrecords,
|
||||
desc=Code injection - column name,
|
||||
test=HASOBS,
|
||||
outds=work.test_results
|
||||
)
|
||||
|
||||
/* Code injection - raw values*/
|
||||
data work.inds;
|
||||
infile datalines4 dsd;
|
||||
input GROUP_LOGIC:$3. SUBGROUP_LOGIC:$3. SUBGROUP_ID:8. VARIABLE_NM:$32.
|
||||
OPERATOR_NM:$10. RAW_VALUE:$4000.;
|
||||
datalines4;
|
||||
AND,AND,1,age,=,;;%abort
|
||||
;;;;
|
||||
run;
|
||||
%mp_filtercheck(work.inds,
|
||||
targetds=sashelp.class,
|
||||
outds=work.badrecords,
|
||||
abort=NO
|
||||
)
|
||||
%let syscc=0;
|
||||
%mp_assertdsobs(work.badrecords,
|
||||
desc=Code injection - raw value abort,
|
||||
test=HASOBS,
|
||||
outds=work.test_results
|
||||
)
|
||||
|
||||
/* Supply variables with incorrect types */
|
||||
data work.inds;
|
||||
infile datalines4 dsd;
|
||||
input GROUP_LOGIC:$3. SUBGROUP_LOGIC:$3. SUBGROUP_ID:8. VARIABLE_NM:$32.
|
||||
OPERATOR_NM:$10. RAW_VALUE:8;
|
||||
datalines4;
|
||||
AND,AND,1,age,=,0
|
||||
;;;;
|
||||
run;
|
||||
%let syscc=0;
|
||||
%mp_filtercheck(work.inds,
|
||||
targetds=sashelp.class,
|
||||
outds=work.badrecords,
|
||||
abort=NO
|
||||
)
|
||||
%mp_assert(iftrue=(&syscc=42),
|
||||
desc=Throw error if RAW_VALUE is incorrect,
|
||||
outds=work.test_results
|
||||
)
|
||||
%let syscc=0;
|
||||
122
tests/base/mp_filtergenerate.test.sas
Normal file
122
tests/base/mp_filtergenerate.test.sas
Normal file
@@ -0,0 +1,122 @@
|
||||
/**
|
||||
@file
|
||||
@brief Testing mp_filtergenerate macro
|
||||
|
||||
<h4> SAS Macros </h4>
|
||||
@li mp_filtergenerate.sas
|
||||
@li mp_filtercheck.sas
|
||||
@li mp_assertdsobs.sas
|
||||
|
||||
**/
|
||||
|
||||
options source2;
|
||||
|
||||
/* valid filter */
|
||||
data work.inds;
|
||||
infile datalines4 dsd;
|
||||
input GROUP_LOGIC:$3. SUBGROUP_LOGIC:$3. SUBGROUP_ID:8. VARIABLE_NM:$32.
|
||||
OPERATOR_NM:$10. RAW_VALUE:$4000.;
|
||||
datalines4;
|
||||
AND,AND,1,AGE,>,5
|
||||
AND,AND,1,SEX,NE,"'M'"
|
||||
AND,OR,2,Name,NOT IN,"('Jane','Janet')"
|
||||
AND,OR,2,Weight,>=,84.6
|
||||
;;;;
|
||||
run;
|
||||
%mp_filtercheck(work.inds,targetds=sashelp.class)
|
||||
%mp_filtergenerate(work.inds,outref=myfilter)
|
||||
data work.test;
|
||||
set sashelp.class;
|
||||
where %inc myfilter;;
|
||||
run;
|
||||
%mp_assertdsobs(work.test,
|
||||
desc=Valid filter,
|
||||
test=EQUALS 8,
|
||||
outds=work.test_results
|
||||
)
|
||||
|
||||
/* empty filter (return all records) */
|
||||
data work.inds;
|
||||
infile datalines4 dsd;
|
||||
input GROUP_LOGIC:$3. SUBGROUP_LOGIC:$3. SUBGROUP_ID:8. VARIABLE_NM:$32.
|
||||
OPERATOR_NM:$10. RAW_VALUE:$4000.;
|
||||
datalines4;
|
||||
;;;;
|
||||
run;
|
||||
%mp_filtercheck(work.inds,targetds=sashelp.class)
|
||||
%mp_filtergenerate(work.inds,outref=myfilter)
|
||||
data work.test;
|
||||
set sashelp.class;
|
||||
where %inc myfilter;;
|
||||
run;
|
||||
%mp_assertdsobs(work.test,
|
||||
desc=Empty filter (return all records) ,
|
||||
test=EQUALS 19,
|
||||
outds=work.test_results
|
||||
)
|
||||
|
||||
/* single line filter */
|
||||
data work.inds;
|
||||
infile datalines4 dsd;
|
||||
input GROUP_LOGIC:$3. SUBGROUP_LOGIC:$3. SUBGROUP_ID:8. VARIABLE_NM:$32.
|
||||
OPERATOR_NM:$10. RAW_VALUE:$4000.;
|
||||
datalines4;
|
||||
AND,OR,2,Name,IN,"('Jane','Janet')"
|
||||
;;;;
|
||||
run;
|
||||
%mp_filtercheck(work.inds,targetds=sashelp.class)
|
||||
%mp_filtergenerate(work.inds,outref=myfilter)
|
||||
data work.test;
|
||||
set sashelp.class;
|
||||
where %inc myfilter;;
|
||||
run;
|
||||
%mp_assertdsobs(work.test,
|
||||
desc=Single line filter ,
|
||||
test=EQUALS 2,
|
||||
outds=work.test_results
|
||||
)
|
||||
|
||||
/* single line 2 group filter */
|
||||
data work.inds;
|
||||
infile datalines4 dsd;
|
||||
input GROUP_LOGIC:$3. SUBGROUP_LOGIC:$3. SUBGROUP_ID:8. VARIABLE_NM:$32.
|
||||
OPERATOR_NM:$10. RAW_VALUE:$4000.;
|
||||
datalines4;
|
||||
OR,OR,2,Name,IN,"('Jane','Janet')"
|
||||
OR,OR,3,Name,IN,"('James')"
|
||||
;;;;
|
||||
run;
|
||||
%mp_filtercheck(work.inds,targetds=sashelp.class)
|
||||
%mp_filtergenerate(work.inds,outref=myfilter)
|
||||
data work.test;
|
||||
set sashelp.class;
|
||||
where %inc myfilter;;
|
||||
run;
|
||||
%mp_assertdsobs(work.test,
|
||||
desc=Single line 2 group filter ,
|
||||
test=EQUALS 3,
|
||||
outds=work.test_results
|
||||
)
|
||||
|
||||
/* filter with nothing returned */
|
||||
data work.inds;
|
||||
infile datalines4 dsd;
|
||||
input GROUP_LOGIC:$3. SUBGROUP_LOGIC:$3. SUBGROUP_ID:8. VARIABLE_NM:$32.
|
||||
OPERATOR_NM:$10. RAW_VALUE:$4000.;
|
||||
datalines4;
|
||||
AND,OR,2,Name,IN,"('Jane','Janet')"
|
||||
AND,OR,3,Name,IN,"('James')"
|
||||
;;;;
|
||||
run;
|
||||
%mp_filtercheck(work.inds,targetds=sashelp.class)
|
||||
%mp_filtergenerate(work.inds,outref=myfilter)
|
||||
data work.test;
|
||||
set sashelp.class;
|
||||
where %inc myfilter;;
|
||||
run;
|
||||
%mp_assertdsobs(work.test,
|
||||
desc=Filter with nothing returned,
|
||||
test=EQUALS 0,
|
||||
outds=work.test_results
|
||||
)
|
||||
|
||||
68
tests/base/mp_filtervalidate.test.sas
Normal file
68
tests/base/mp_filtervalidate.test.sas
Normal file
@@ -0,0 +1,68 @@
|
||||
/**
|
||||
@file
|
||||
@brief Testing mp_filtervalidate macro
|
||||
|
||||
<h4> SAS Macros </h4>
|
||||
@li mp_filtergenerate.sas
|
||||
@li mp_filtervalidate.sas
|
||||
@li mp_assertdsobs.sas
|
||||
|
||||
**/
|
||||
|
||||
|
||||
/* valid filter */
|
||||
data work.inds;
|
||||
infile datalines4 dsd;
|
||||
input GROUP_LOGIC:$3. SUBGROUP_LOGIC:$3. SUBGROUP_ID:8. VARIABLE_NM:$32.
|
||||
OPERATOR_NM:$10. RAW_VALUE:$4000.;
|
||||
datalines4;
|
||||
AND,AND,1,AGE,>,5
|
||||
AND,AND,1,SEX,NE,"'M'"
|
||||
AND,OR,2,Name,NOT IN,"('Jane','Janet')"
|
||||
AND,OR,2,Weight,>=,84.6
|
||||
;;;;
|
||||
run;
|
||||
%mp_filtergenerate(work.inds,outref=myfilter)
|
||||
%mp_filtervalidate(myfilter,sashelp.class,outds=work.results,abort=NO)
|
||||
%mp_assertdsobs(work.results,
|
||||
desc=Valid filter,
|
||||
test=EMPTY,
|
||||
outds=work.test_results
|
||||
)
|
||||
|
||||
/* empty filter (return all records) */
|
||||
data work.inds;
|
||||
infile datalines4 dsd;
|
||||
input GROUP_LOGIC:$3. SUBGROUP_LOGIC:$3. SUBGROUP_ID:8. VARIABLE_NM:$32.
|
||||
OPERATOR_NM:$10. RAW_VALUE:$4000.;
|
||||
datalines4;
|
||||
;;;;
|
||||
run;
|
||||
%mp_filtergenerate(work.inds,outref=myfilter)
|
||||
%mp_filtervalidate(myfilter,sashelp.class,outds=work.results,abort=NO)
|
||||
%mp_assertdsobs(work.results,
|
||||
desc=Valid filter,
|
||||
test=EMPTY,
|
||||
outds=work.test_results
|
||||
)
|
||||
|
||||
|
||||
|
||||
/* invalid filter*/
|
||||
data work.inds;
|
||||
infile datalines4 dsd;
|
||||
input GROUP_LOGIC:$3. SUBGROUP_LOGIC:$3. SUBGROUP_ID:8. VARIABLE_NM:$32.
|
||||
OPERATOR_NM:$10. RAW_VALUE:$4000.;
|
||||
datalines4;
|
||||
AND,AND,1,SEX,NE,2
|
||||
;;;;
|
||||
run;
|
||||
%mp_filtergenerate(work.inds,outref=myfilter)
|
||||
%mp_filtervalidate(myfilter,sashelp.class,outds=work.results,abort=NO)
|
||||
%let syscc=0;
|
||||
%mp_assertdsobs(work.results,
|
||||
desc=Valid filter,
|
||||
test=EQUALS 1,
|
||||
outds=work.test_results
|
||||
)
|
||||
|
||||
76
tests/base/mp_joflow.test.1.sas
Normal file
76
tests/base/mp_joflow.test.1.sas
Normal file
@@ -0,0 +1,76 @@
|
||||
/**
|
||||
@file
|
||||
@brief Testing mv_jobflow macro
|
||||
@details One of the remote jobs aborts with syscc>0 - test to
|
||||
make sure this comes back to the calling session
|
||||
|
||||
<h4> SAS Macros </h4>
|
||||
@li mp_assert.sas
|
||||
@li mv_createjob.sas
|
||||
@li mv_jobflow.sas
|
||||
**/
|
||||
|
||||
|
||||
/**
|
||||
* Test Case 1
|
||||
*/
|
||||
filename testprog temp;
|
||||
data _null_;
|
||||
file testprog;
|
||||
put '%put this is job: &_program;'
|
||||
/ '%put this was run in flow &flow_id;'
|
||||
/ 'data ;'
|
||||
/ ' rval=rand("uniform");'
|
||||
/ ' rand=rval*¯ovar1;'
|
||||
/ ' do x=1 to rand;'
|
||||
/ ' y=rand*¯ovar2;'
|
||||
/ ' if (rval>0.50) then abort;'
|
||||
/ ' else output;'
|
||||
/ ' end;'
|
||||
/ 'run;'
|
||||
;
|
||||
run;
|
||||
|
||||
%mv_createjob(path=/Public/temp,name=demo1,code=testprog)
|
||||
%mv_createjob(path=/Public/temp,name=demo2,code=testprog)
|
||||
|
||||
data work.inputjobs;
|
||||
_contextName='SAS Job Execution compute context';
|
||||
do flow_id=1 to 2;
|
||||
do i=1 to 4;
|
||||
_program='/Public/temp/demo1';
|
||||
macrovar1=10*i;
|
||||
macrovar2=4*i;
|
||||
output;
|
||||
i+1;
|
||||
_program='/Public/temp/demo2';
|
||||
macrovar1=40*i;
|
||||
macrovar2=44*i;
|
||||
output;
|
||||
end;
|
||||
end;
|
||||
run;
|
||||
|
||||
* Trigger the flow ;
|
||||
|
||||
%put NOTE: &=syscc;
|
||||
|
||||
%mv_jobflow(inds=work.inputjobs
|
||||
,maxconcurrency=2
|
||||
,outds=work.results
|
||||
,outref=myjoblog
|
||||
,raise_err=1
|
||||
,mdebug=1
|
||||
)
|
||||
|
||||
%put NOTE: &=syscc;
|
||||
|
||||
data _null_;
|
||||
infile myjoblog;
|
||||
input; put _infile_;
|
||||
run;
|
||||
|
||||
%mp_assert(
|
||||
iftrue=(&syscc ne 0),
|
||||
desc=Check that non zero return code is returned if called job fails
|
||||
)
|
||||
75
tests/base/mp_joflow.test.2.sas
Normal file
75
tests/base/mp_joflow.test.2.sas
Normal file
@@ -0,0 +1,75 @@
|
||||
/**
|
||||
@file
|
||||
@brief Testing mv_jobflow macro
|
||||
@details All jobs complete successfully with syscc = 0 - test to
|
||||
make sure this comes back to the calling session
|
||||
|
||||
<h4> SAS Macros </h4>
|
||||
@li mp_assert.sas
|
||||
@li mv_createjob.sas
|
||||
@li mv_jobflow.sas
|
||||
**/
|
||||
|
||||
|
||||
/**
|
||||
* Test Case 1
|
||||
*/
|
||||
filename testprog temp;
|
||||
data _null_;
|
||||
file testprog;
|
||||
put '%put this is job: &_program;'
|
||||
/ '%put this was run in flow &flow_id;'
|
||||
/ 'data ;'
|
||||
/ ' rval=rand("uniform");'
|
||||
/ ' rand=rval*¯ovar1;'
|
||||
/ ' do x=1 to rand;'
|
||||
/ ' y=rand*¯ovar2;'
|
||||
/ ' output;'
|
||||
/ ' end;'
|
||||
/ 'run;'
|
||||
;
|
||||
run;
|
||||
|
||||
%mv_createjob(path=/Public/temp,name=demo1,code=testprog)
|
||||
%mv_createjob(path=/Public/temp,name=demo2,code=testprog)
|
||||
|
||||
data work.inputjobs;
|
||||
_contextName='SAS Job Execution compute context';
|
||||
do flow_id=1 to 2;
|
||||
do i=1 to 4;
|
||||
_program='/Public/temp/demo1';
|
||||
macrovar1=10*i;
|
||||
macrovar2=4*i;
|
||||
output;
|
||||
i+1;
|
||||
_program='/Public/temp/demo2';
|
||||
macrovar1=40*i;
|
||||
macrovar2=44*i;
|
||||
output;
|
||||
end;
|
||||
end;
|
||||
run;
|
||||
|
||||
* Trigger the flow ;
|
||||
|
||||
%put NOTE: &=syscc;
|
||||
|
||||
%mv_jobflow(inds=work.inputjobs
|
||||
,maxconcurrency=2
|
||||
,outds=work.results
|
||||
,outref=myjoblog
|
||||
,raise_err=1
|
||||
,mdebug=1
|
||||
)
|
||||
|
||||
%put NOTE: &=syscc;
|
||||
|
||||
data _null_;
|
||||
infile myjoblog;
|
||||
input; put _infile_;
|
||||
run;
|
||||
|
||||
%mp_assert(
|
||||
iftrue=(&syscc eq 0),
|
||||
desc=Check that non zero return code is returned if called job fails
|
||||
)
|
||||
42
tests/base/mp_jsonout.test.sas
Normal file
42
tests/base/mp_jsonout.test.sas
Normal file
@@ -0,0 +1,42 @@
|
||||
/**
|
||||
@file
|
||||
@brief Testing mp_jsonout.sas macro
|
||||
|
||||
<h4> SAS Macros </h4>
|
||||
@li mp_jsonout.sas
|
||||
@li mp_assert.sas
|
||||
|
||||
**/
|
||||
|
||||
filename webref temp;
|
||||
|
||||
data demo;
|
||||
dtval=date();
|
||||
format dtval date9.;
|
||||
compare=put(date(),date9.);
|
||||
call symputx('compare',compare);
|
||||
run;
|
||||
|
||||
%mp_jsonout(OPEN,jref=webref)
|
||||
%mp_jsonout(OBJ,demo,jref=webref,fmt=Y)
|
||||
%mp_jsonout(CLOSE,jref=webref)
|
||||
|
||||
data _null_;
|
||||
infile webref;
|
||||
input;
|
||||
putlog _infile_;
|
||||
run;
|
||||
|
||||
libname web JSON fileref=webref;
|
||||
%let dtval=0;
|
||||
data work.test;
|
||||
set web.demo;
|
||||
call symputx('dtval',dtval);
|
||||
run;
|
||||
|
||||
|
||||
%mp_assert(
|
||||
iftrue=(&dtval=&compare),
|
||||
desc=Checking tables were created successfully,
|
||||
outds=work.test_results
|
||||
)
|
||||
62
tests/base/mp_validatecol.test.sas
Normal file
62
tests/base/mp_validatecol.test.sas
Normal file
@@ -0,0 +1,62 @@
|
||||
/**
|
||||
@file
|
||||
@brief Testing mp_validatecol.sas macro
|
||||
|
||||
<h4> SAS Macros </h4>
|
||||
@li mp_assertdsobs.sas
|
||||
@li mp_validatecol.sas
|
||||
|
||||
**/
|
||||
|
||||
|
||||
/**
|
||||
* Test 1 - LIBDS
|
||||
*/
|
||||
data test1;
|
||||
infile datalines4 dsd;
|
||||
input;
|
||||
libds=_infile_;
|
||||
%mp_validatecol(libds,LIBDS,is_libds)
|
||||
if is_libds=1;
|
||||
datalines4;
|
||||
some.libname
|
||||
!lib.blah
|
||||
%abort
|
||||
definite.ok
|
||||
not.ok!
|
||||
nineletrs._
|
||||
;;;;
|
||||
run;
|
||||
%mp_assertdsobs(work.test1,
|
||||
desc=Testing LIBDS,
|
||||
test=EQUALS 2,
|
||||
outds=work.test_results
|
||||
)
|
||||
|
||||
/**
|
||||
* Test 2 - ISNUM
|
||||
*/
|
||||
data test2;
|
||||
infile datalines4 dsd;
|
||||
input;
|
||||
infile=_infile_;
|
||||
%mp_validatecol(infile,ISNUM,is_numeric)
|
||||
if is_numeric=1;
|
||||
datalines4;
|
||||
1
|
||||
0001
|
||||
1e6
|
||||
-44
|
||||
above are good
|
||||
the rest are bad
|
||||
%abort
|
||||
1&somethingverybad.
|
||||
&
|
||||
+-1
|
||||
;;;;
|
||||
run;
|
||||
%mp_assertdsobs(work.test2,
|
||||
desc=Test2 - ISNUM,
|
||||
test=EQUALS 4,
|
||||
outds=work.test_results
|
||||
)
|
||||
8
tests/testinit.sas
Normal file
8
tests/testinit.sas
Normal file
@@ -0,0 +1,8 @@
|
||||
/**
|
||||
@file
|
||||
@brief init file for tests
|
||||
|
||||
**/
|
||||
|
||||
/* location in metadata or SAS Drive for temporary files */
|
||||
%let mcTestAppLoc=/Public/temp/macrocore;
|
||||
9
tests/testterm.sas
Normal file
9
tests/testterm.sas
Normal file
@@ -0,0 +1,9 @@
|
||||
/**
|
||||
@file
|
||||
@brief term file for tests
|
||||
|
||||
**/
|
||||
|
||||
%webout(OPEN)
|
||||
%webout(OBJ, TEST_RESULTS)
|
||||
%webout(CLOSE)
|
||||
45
tests/viya/mv_createwebservice.test.sas
Normal file
45
tests/viya/mv_createwebservice.test.sas
Normal file
@@ -0,0 +1,45 @@
|
||||
/**
|
||||
@file
|
||||
@brief Testing mv_createwebservice macro
|
||||
|
||||
<h4> SAS Macros </h4>
|
||||
@li mv_createwebservice.sas
|
||||
@li mv_getjobcode.sas
|
||||
|
||||
**/
|
||||
|
||||
/**
|
||||
* Test Case 1
|
||||
* Send special char in a service
|
||||
*/
|
||||
|
||||
filename testref temp;
|
||||
data _null_;
|
||||
file testref;
|
||||
put '01'x;
|
||||
run;
|
||||
%put TEST1: creating web service;
|
||||
%mv_createwebservice(
|
||||
path=&mcTestAppLoc/temp/macros,
|
||||
name=mv_createwebservice,
|
||||
code=testref
|
||||
)
|
||||
%put TEST1: fetching web service code;
|
||||
%mv_getjobcode(
|
||||
path=&mcTestAppLoc/temp/macros,
|
||||
name=mv_createwebservice,
|
||||
outref=compare
|
||||
)
|
||||
%put TEST1: checking web service code;
|
||||
data work.test_results;
|
||||
length test_description $256 test_result $4 test_comments $256;
|
||||
infile compare end=eof;
|
||||
input;
|
||||
if eof then do;
|
||||
if _infile_='01'x then test_result='PASS';
|
||||
else test_result='FAIL';
|
||||
test_description="Creating web service with invisible character";
|
||||
output;
|
||||
stop;
|
||||
end;
|
||||
run;
|
||||
49
tests/viya/mv_getjobcode.test.sas
Normal file
49
tests/viya/mv_getjobcode.test.sas
Normal file
@@ -0,0 +1,49 @@
|
||||
/**
|
||||
@file
|
||||
@brief Testing mv_getjobcode macro
|
||||
|
||||
<h4> SAS Macros </h4>
|
||||
@li mp_assert.sas
|
||||
@li mv_createjob.sas
|
||||
@li mv_getjobcode.sas
|
||||
|
||||
**/
|
||||
|
||||
/**
|
||||
* Test Case 1
|
||||
*/
|
||||
|
||||
/* write some code to a job */
|
||||
%let incode=%str(data test; set sashelp.class;run;);
|
||||
filename testref temp;
|
||||
data _null_;
|
||||
file testref;
|
||||
put "&incode";
|
||||
run;
|
||||
%mv_createjob(
|
||||
code=testref,
|
||||
path=&mcTestAppLoc/services/temp,
|
||||
name=some_job
|
||||
)
|
||||
|
||||
/* now get the code back */
|
||||
%mv_getjobcode(
|
||||
path=&mcTestAppLoc/services/temp,
|
||||
name=some_job,
|
||||
outref=mycode
|
||||
)
|
||||
|
||||
%let diditexist=NO;
|
||||
data work.test1;
|
||||
infile mycode;
|
||||
input;
|
||||
putlog _infile_;
|
||||
line=_infile_;
|
||||
check=symget('incode');
|
||||
if _infile_=symget('incode') then call symputx('diditexist','YES');
|
||||
run;
|
||||
|
||||
%mp_assert(
|
||||
iftrue=(&diditexist=NO),
|
||||
desc=Check if the code that was sent was successfully retrieved
|
||||
)
|
||||
70
tests/viya/mv_getjoblog.test.sas
Normal file
70
tests/viya/mv_getjoblog.test.sas
Normal file
@@ -0,0 +1,70 @@
|
||||
/**
|
||||
@file
|
||||
@brief Testing mv_createwebservice macro
|
||||
|
||||
<h4> SAS Macros </h4>
|
||||
@li mp_assert.sas
|
||||
@li mv_createjob.sas
|
||||
@li mv_jobexecute.sas
|
||||
@li mv_jobwaitfor.sas
|
||||
@li mv_getjoblog.sas
|
||||
|
||||
**/
|
||||
|
||||
/**
|
||||
* Test Case 1
|
||||
*/
|
||||
|
||||
/* create a service */
|
||||
filename testref temp;
|
||||
data _null_;
|
||||
file testref;
|
||||
put 'data;run;';
|
||||
put 'endsas;';
|
||||
run;
|
||||
%mv_createjob(
|
||||
path=&mcTestAppLoc/jobs/temp,
|
||||
code=testref,
|
||||
name=testjob
|
||||
)
|
||||
|
||||
%* Execute it;
|
||||
%mv_jobexecute(
|
||||
path=&mcTestAppLoc/jobs/temp,
|
||||
name=testjob,
|
||||
outds=work.info
|
||||
)
|
||||
|
||||
%* Wait for it to finish;
|
||||
data work.info;
|
||||
set work.info;
|
||||
where method='GET' and rel='state';
|
||||
run;
|
||||
%mv_jobwaitfor(ALL,inds=work.info,outds=work.jobstates)
|
||||
|
||||
%* and grab the uri;
|
||||
data _null_;
|
||||
set work.jobstates;
|
||||
call symputx('uri',uri);
|
||||
run;
|
||||
|
||||
%* Finally, fetch the log;
|
||||
%mv_getjoblog(uri=%str(&uri),outref=mylog)
|
||||
|
||||
|
||||
data _null_;
|
||||
infile mylog end=eof;
|
||||
input;
|
||||
putlog _infile_;
|
||||
retain found 0;
|
||||
if index(_infile_,'endsas;') then do;
|
||||
found=1;
|
||||
call symputx('found',found);
|
||||
end;
|
||||
else if eof and found ne 1 then call symputx('found',0);
|
||||
run;
|
||||
|
||||
%mp_assert(
|
||||
iftrue=(%str(&found)=1),
|
||||
desc=Check if the log was still fetched even though endsas was submitted
|
||||
)
|
||||
74
tests/viya/mv_getjobresult.test.sas
Normal file
74
tests/viya/mv_getjobresult.test.sas
Normal file
@@ -0,0 +1,74 @@
|
||||
/**
|
||||
@file
|
||||
@brief Testing mv_createwebservice macro
|
||||
|
||||
<h4> SAS Macros </h4>
|
||||
@li mp_assertdsobs.sas
|
||||
@li mv_createwebservice.sas
|
||||
@li mv_getjobresult.sas
|
||||
@li mv_jobflow.sas
|
||||
|
||||
**/
|
||||
|
||||
/**
|
||||
* Test Case 1
|
||||
*/
|
||||
|
||||
/* create a service */
|
||||
filename testref temp;
|
||||
data _null_;
|
||||
file testref;
|
||||
put 'data test; set sashelp.class;run;';
|
||||
put '%webout(OPEN)';
|
||||
put '%webout(OBJ,test)';
|
||||
put '%webout(CLOSE)';
|
||||
run;
|
||||
%mv_createwebservice(
|
||||
path=&mcTestAppLoc/services/temp,
|
||||
code=testref,
|
||||
name=testsvc
|
||||
)
|
||||
|
||||
/* trigger and wait for it to finish */
|
||||
data work.inputjobs;
|
||||
_program="&mcTestAppLoc/services/temp/testsvc";
|
||||
run;
|
||||
%mv_jobflow(inds=work.inputjobs
|
||||
,maxconcurrency=4
|
||||
,outds=work.results
|
||||
,outref=myjoblog
|
||||
)
|
||||
/* stream the log */
|
||||
data _null_;
|
||||
infile myjoblog;
|
||||
input;
|
||||
put _infile_;
|
||||
run;
|
||||
|
||||
/* fetch the uri */
|
||||
data _null_;
|
||||
set work.results;
|
||||
call symputx('uri',uri);
|
||||
put (_all_)(=);
|
||||
run;
|
||||
|
||||
/* now get the results */
|
||||
%mv_getjobresult(uri=&uri
|
||||
,result=WEBOUT_JSON
|
||||
,outref=myweb
|
||||
,outlib=myweblib
|
||||
)
|
||||
data _null_;
|
||||
infile myweb;
|
||||
input;
|
||||
putlog _infile_;
|
||||
run;
|
||||
data work.out;
|
||||
set myweblib.test;
|
||||
put (_all_)(=);
|
||||
run;
|
||||
%mp_assertdsobs(work.out,
|
||||
desc=Test1 - 19 obs from sashelp.class in service result,
|
||||
test=EQUALS 19,
|
||||
outds=work.test_results
|
||||
)
|
||||
Reference in New Issue
Block a user