Test of the ms_getusers macro

This code is also available in: Deutsch Español Français
Difficulty Level
Beginner
Published on :
Attention : This code requires administrator privileges.
This script performs a comprehensive test of the `ms_getusers` macro. It begins by checking variable isolation (scope) to ensure that the macro does not pollute the global environment. Then, it simulates an administration scenario by creating a unique group via `ms_creategroup`, adding a user to it via `ms_adduser2group`, and verifying that `ms_getusers` correctly extracts this new member.
Data Analysis

Type : MIXTE


The script generates its own test data (group creation) via administration macros and queries system metadata (users/groups) via the macro being tested.

1 Code Block
MACRO CALL Data
Explanation :
Initialization of the scope test (scope snapshot), execution of the `ms_getusers` macro to retrieve all users, verification that no variables have leaked (except listed exceptions), and assertion that the output table contains at least one observation.
Copied!
1%mp_assertscope(SNAPSHOT)
2%ms_getusers(outds=work.test1,mdebug=&sasjs_mdebug)
3%mp_assertscope(COMPARE
4 ,ignorelist=MCLIB0_JADP1LEN MCLIB0_JADPNUM MCLIB0_JADVLEN
5)
6 
7%mp_assertdsobs(work.test1,test=ATLEAST 1)
2 Code Block
DATA STEP Data
Explanation :
Generation of a unique group name and creation of this group via `ms_creategroup`. The generated group ID (groupid) is retrieved into a macro variable `gid` via a Data Step.
Copied!
1/* create a group */
2%let group=%substr(%mf_getuniquename(),1,8);
3%ms_creategroup(&group, desc=some desc,mdebug=&sasjs_mdebug,outds=work.group)
4%let gid=0;
5DATA _null_;
6 SET work.group;
7 call symputx('gid',groupid);
8RUN;
3 Code Block
MACRO CALL
Explanation :
Adding the user with ID 1 to the newly created group via `ms_adduser2group`, then extracting the members of this specific group into the `test2` table.
Copied!
1/* add a member */
2%ms_adduser2group(uid=1,gid=&gid)
3 
4/* extract the members */
5%ms_getusers(group=&group,outds=test2)
4 Code Block
MACRO CALL
Explanation :
Final check: the script iterates through the resulting table to confirm the presence of the user (ID 1) and uses `mp_assert` to validate the test's success in the results.
Copied!
1/* check the user is in the output list */
2%let checkid=0;
3DATA _null_;
4 SET work.test2;
5 IF id=1 THEN call symputx('checkid',1);
6RUN;
7%mp_assert(
8 iftrue=(&checkid=1),
9 desc=Checking that admin user was created in the new group,
10 outds=work.test_results
11)
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.

Related Documentation

Aucune documentation spécifique pour cette catégorie.