From 63bf00e28f1e448e24821ac78c0a080a4685da94 Mon Sep 17 00:00:00 2001 From: munja Date: Thu, 21 Apr 2022 23:51:47 +0100 Subject: [PATCH] fix: adding (and fixing) tests for ms_* macro suite --- sasjs/sasjsconfig.json | 10 +---- server/ms_createuser.sas | 7 +++- server/ms_getusers.sas | 10 ++++- tests/serveronly/ms_createuser.test.sas | 50 +++++++++++++++++++++++++ tests/serveronly/ms_getusers.test.sas | 23 ++++++++++++ tests/serveronly/ms_runstp.test.sas | 33 +++++++++++----- tests/testinit.sas | 7 +++- 7 files changed, 117 insertions(+), 23 deletions(-) create mode 100644 tests/serveronly/ms_createuser.test.sas create mode 100644 tests/serveronly/ms_getusers.test.sas diff --git a/sasjs/sasjsconfig.json b/sasjs/sasjsconfig.json index cf3659f..aeb6988 100644 --- a/sasjs/sasjsconfig.json +++ b/sasjs/sasjsconfig.json @@ -65,7 +65,7 @@ }, { "name": "server", - "serverUrl": "https://sas.analytium.co.uk:5000", + "serverUrl": "https://sas.analytium.co.uk:5006", "serverType": "SASJS", "httpsAgentOptions": { "allowInsecureRequests": false @@ -74,13 +74,7 @@ "macroFolders": [ "server", "tests/serveronly" - ], - "programFolders": [], - "binaryFolders": [], - "deployConfig": { - "deployServicePack": true, - "deployScripts": [] - } + ] }, { "name": "docsonly", diff --git a/server/ms_createuser.sas b/server/ms_createuser.sas index 227e3be..619d62b 100644 --- a/server/ms_createuser.sas +++ b/server/ms_createuser.sas @@ -20,19 +20,24 @@ @param [in] isadmin= (false) Set to true to give the user admin rights @param [in] displayName= (0) Set a friendly name (spaces & special characters are ok). If not provided, username will be used instead. + @param [in] mdebug= (0) Set to 1 to enable DEBUG messages @param [out] outds= (work.ms_createuser) This output dataset will contain the values from the JSON response (such as the id of the new user) |ID:best.|DISPLAYNAME:$8.|USERNAME:$8.|ISACTIVE:best.|ISADMIN:best.| |---|---|---|---|---| |`6 `|`New User `|`newuser `|`1 `|`0 `| - @param [in] mdebug= (0) Set to 1 to enable DEBUG messages +

SAS Macros

@li mf_getuniquefileref.sas @li mf_getuniquelibref.sas @li mp_abort.sas +

Related Files

+ @li ms_createuser.test.sas + @li ms_getusers.sas + **/ %macro ms_createuser(username,password diff --git a/server/ms_getusers.sas b/server/ms_getusers.sas index 857eff8..c3c6ace 100644 --- a/server/ms_getusers.sas +++ b/server/ms_getusers.sas @@ -1,12 +1,14 @@ /** @file @brief Fetches the list of users from SASjs Server - @details Fetches the list of users from SASjs Server. + @details Fetches the list of users from SASjs Server and writes them to an + output dataset. Example: %ms_getusers(outds=userlist) + @param [in] mdebug= (0) Set to 1 to enable DEBUG messages @param [out] outds= (work.ms_getusers) This output dataset will contain the list of user accounts. Format: |DISPLAYNAME:$18.|USERNAME:$10.|ID:best.| @@ -17,13 +19,17 @@ |`Ivor Townsend `|`ivor `|`4`| |`New User `|`newuser `|`5`| - @param [in] mdebug= (0) Set to 1 to enable DEBUG messages +

SAS Macros

@li mf_getuniquefileref.sas @li mf_getuniquelibref.sas @li mp_abort.sas +

Related Files

+ @li ms_createuser.sas + @li ms_getusers.test.sas + **/ %macro ms_getusers( diff --git a/tests/serveronly/ms_createuser.test.sas b/tests/serveronly/ms_createuser.test.sas new file mode 100644 index 0000000..1479ab8 --- /dev/null +++ b/tests/serveronly/ms_createuser.test.sas @@ -0,0 +1,50 @@ +/** + @file + @brief Testing ms_createuser.sas macro + +

SAS Macros

+ @li mf_getuniquename.sas + @li mp_assert.sas + @li mp_assertscope.sas + @li ms_createuser.sas + @li ms_getusers.sas + +**/ + +%let user=%substr(%mf_getuniquename(),1,8); + +%mp_assertscope(SNAPSHOT) +%ms_createuser(&user,passwrd,outds=test1,mdebug=&sasjs_mdebug) +%mp_assertscope(COMPARE + ,ignorelist=MCLIB0_JADP1LEN MCLIB0_JADPNUM MCLIB0_JADVLEN +) + +%let id=0; +data _null_; + set work.test1; + call symputx('id',id); +run; +%mp_assert( + iftrue=(&id>0), + desc=Checking that user was created with an ID, + outds=work.test_results +) + +/* double check by querying the list of users */ +%ms_getusers(outds=work.test2) +%let checkid=0; +data _null_; + set work.test2; + where username="&user"; + call symputx('checkid',id); +run; +%mp_assert( + iftrue=(&checkid=&id), + desc=Checking that fetched user exists and has the same ID, + outds=work.test_results +) + + + + + diff --git a/tests/serveronly/ms_getusers.test.sas b/tests/serveronly/ms_getusers.test.sas new file mode 100644 index 0000000..addc778 --- /dev/null +++ b/tests/serveronly/ms_getusers.test.sas @@ -0,0 +1,23 @@ +/** + @file + @brief Testing ms_getusers.sas macro + +

SAS Macros

+ @li ms_getusers.sas + @li mp_assertdsobs.sas + @li mp_assertscope.sas + +**/ + + +%mp_assertscope(SNAPSHOT) +%ms_getusers(outds=work.test1,mdebug=&sasjs_mdebug) +%mp_assertscope(COMPARE + ,ignorelist=MCLIB0_JADP1LEN MCLIB0_JADPNUM MCLIB0_JADVLEN +) + +%mp_assertdsobs(work.test1,test=ATLEAST 1) + + + + diff --git a/tests/serveronly/ms_runstp.test.sas b/tests/serveronly/ms_runstp.test.sas index 0218482..68e1e79 100644 --- a/tests/serveronly/ms_runstp.test.sas +++ b/tests/serveronly/ms_runstp.test.sas @@ -3,14 +3,31 @@ @brief Testing ms_runstp.sas macro

SAS Macros

- @li ms_runstp.sas + @li mf_getuniquename.sas @li mp_assert.sas @li mp_assertscope.sas + @li ms_createfile.sas + @li ms_runstp.sas **/ +/* first, create an STP to run */ +filename stpcode temp; +data _null_; + file stpcode; + put '%put hello world;'; +run; + +options mprint; +%let fname=%mf_getuniquename(); + +%ms_createfile(/sasjs/tests/&fname..sas + ,inref=stpcode + ,mdebug=1 +) + %mp_assertscope(SNAPSHOT) -%ms_runstp(/Public/app/frs/allan/services/common/appinit +%ms_runstp(/sasjs/tests/&fname ,debug=131 ,outref=weboot ) @@ -24,20 +41,16 @@ data _null_; putlog _infile_; run; -data work.httpheaders; - set webeen.httpheaders; - call symputx('test1',content_type); -run; - +%let test1=0; data work.log; set webeen.log; put (_all_)(=); - if _n_>10 then stop; + if _n_>10 then call symputx('test1',1); run; %mp_assert( - iftrue=("&test1"="application/json"), - desc=Checking line was created, + iftrue=("&test1"="1"), + desc=Checking log was returned, outds=work.test_results ) diff --git a/tests/testinit.sas b/tests/testinit.sas index 7c5e363..c72ba4a 100644 --- a/tests/testinit.sas +++ b/tests/testinit.sas @@ -14,16 +14,19 @@ /* set defaults */ %mp_init() -%global _debug; +%global _debug sasjs_mdebug; + +%let sasjs_mdebug=0; %macro loglevel(); %if "&_debug"="2477" or "&_debug"="fields,log,trace" %then %do; %put debug mode activated; options mprint mprintnest; + %let sasjs_mdebug=1; %end; %mend loglevel; %loglevel() %put Initialised &_program; -%put _all_; \ No newline at end of file +%put _all_;