133 lines
5.5 KiB
Plaintext
133 lines
5.5 KiB
Plaintext
*** Settings ***
|
|
Documentation Integration tests for shell asset extraction
|
|
Library Collections
|
|
Library OperatingSystem
|
|
Library Process
|
|
Library String
|
|
|
|
*** Variables ***
|
|
${PYTHON} python
|
|
${SHELL_ASSETS_JSON} docs/reference/shell_assets.json
|
|
${SHELL_ASSETS_YAML} docs/reference/shell_assets.yaml
|
|
${WRAPPERS_DIR} docs/reference/shell_wrappers
|
|
|
|
*** Test Cases ***
|
|
Run Shell Asset Extraction
|
|
[Documentation] Test running the shell asset extraction tool
|
|
[Tags] discovery shell
|
|
${result}= Run Process ${PYTHON} -m cleveragents.discovery.shell_assets cwd=${CURDIR}/..
|
|
Should Be Equal As Numbers ${result.rc} 0
|
|
Should Contain ${result.stdout} Shell Asset Extraction Summary
|
|
Should Contain ${result.stdout} Total scripts found
|
|
|
|
Verify Shell Asset Catalog Files
|
|
[Documentation] Verify that shell asset catalog files are created
|
|
[Tags] discovery shell
|
|
File Should Exist ${SHELL_ASSETS_JSON}
|
|
File Should Exist ${SHELL_ASSETS_YAML}
|
|
|
|
${json_content}= Get File ${SHELL_ASSETS_JSON}
|
|
${catalog}= Evaluate json.loads('''${json_content}''') json
|
|
|
|
Dictionary Should Contain Key ${catalog} scripts
|
|
Dictionary Should Contain Key ${catalog} environment_map
|
|
Dictionary Should Contain Key ${catalog} statistics
|
|
|
|
Analyze Start Local Script
|
|
[Documentation] Verify start_local.sh analysis
|
|
[Tags] discovery shell
|
|
${json_content}= Get File ${SHELL_ASSETS_JSON}
|
|
${catalog}= Evaluate json.loads('''${json_content}''') json
|
|
|
|
${scripts}= Get From Dictionary ${catalog} scripts
|
|
${start_local}= Set Variable ${NONE}
|
|
|
|
FOR ${script} IN @{scripts}
|
|
${name}= Get From Dictionary ${script} name
|
|
IF '${name}' == 'start_local.sh'
|
|
${start_local}= Set Variable ${script}
|
|
Exit For Loop
|
|
END
|
|
END
|
|
|
|
Should Not Be Equal ${start_local} ${NONE} start_local.sh not found
|
|
|
|
${requires_docker}= Get From Dictionary ${start_local} requires_docker
|
|
${requires_git}= Get From Dictionary ${start_local} requires_git
|
|
${python_replacement}= Get From Dictionary ${start_local} python_replacement_suggested
|
|
|
|
Should Be True ${requires_docker}
|
|
Should Be True ${requires_git}
|
|
Should Be True ${python_replacement}
|
|
|
|
Check Environment Variables
|
|
[Documentation] Verify environment variables are extracted
|
|
[Tags] discovery shell
|
|
${json_content}= Get File ${SHELL_ASSETS_JSON}
|
|
${catalog}= Evaluate json.loads('''${json_content}''') json
|
|
|
|
${env_map}= Get From Dictionary ${catalog} environment_map
|
|
${env_count}= Get Length ${env_map}
|
|
Should Be True ${env_count} > 0 No environment variables found
|
|
|
|
# Check that each variable maps to scripts
|
|
FOR ${var} ${scripts} IN &{env_map}
|
|
${script_count}= Get Length ${scripts}
|
|
Should Be True ${script_count} > 0 Variable ${var} has no scripts
|
|
END
|
|
|
|
Verify Script Statistics
|
|
[Documentation] Verify shell script statistics
|
|
[Tags] discovery shell
|
|
${json_content}= Get File ${SHELL_ASSETS_JSON}
|
|
${catalog}= Evaluate json.loads('''${json_content}''') json
|
|
|
|
${stats}= Get From Dictionary ${catalog} statistics
|
|
|
|
Dictionary Should Contain Key ${stats} total_scripts
|
|
Dictionary Should Contain Key ${stats} docker_required
|
|
Dictionary Should Contain Key ${stats} git_required
|
|
Dictionary Should Contain Key ${stats} idempotent
|
|
Dictionary Should Contain Key ${stats} python_replacement
|
|
|
|
${total}= Get From Dictionary ${stats} total_scripts
|
|
Should Be True ${total} > 0 No scripts found
|
|
|
|
Check Python Wrappers
|
|
[Documentation] Verify Python wrapper generation
|
|
[Tags] discovery shell
|
|
${wrapper_exists}= Run Keyword And Return Status Directory Should Exist ${WRAPPERS_DIR}
|
|
|
|
Run Keyword If ${wrapper_exists}
|
|
... Check Wrapper Files
|
|
|
|
Validate Catalog Consistency
|
|
[Documentation] Ensure JSON and YAML catalogs contain the same data
|
|
[Tags] discovery shell
|
|
${json_content}= Get File ${SHELL_ASSETS_JSON}
|
|
${json_data}= Evaluate json.loads('''${json_content}''') json
|
|
|
|
${yaml_content}= Get File ${SHELL_ASSETS_YAML}
|
|
${yaml_data}= Evaluate yaml.safe_load('''${yaml_content}''') yaml
|
|
|
|
# Compare script counts
|
|
${json_scripts}= Get From Dictionary ${json_data} scripts
|
|
${yaml_scripts}= Get From Dictionary ${yaml_data} scripts
|
|
${json_count}= Get Length ${json_scripts}
|
|
${yaml_count}= Get Length ${yaml_scripts}
|
|
Should Be Equal As Numbers ${json_count} ${yaml_count}
|
|
|
|
*** Keywords ***
|
|
Check Wrapper Files
|
|
[Documentation] Check Python wrapper files if directory exists
|
|
@{wrappers}= List Files In Directory ${WRAPPERS_DIR} *.py
|
|
${wrapper_count}= Get Length ${wrappers}
|
|
|
|
Should Be True ${wrapper_count} > 0 No Python wrappers found
|
|
|
|
FOR ${wrapper} IN @{wrappers}
|
|
${content}= Get File ${WRAPPERS_DIR}/${wrapper}
|
|
Should Contain ${content} def run_
|
|
Should Contain ${content} subprocess.run
|
|
Should Contain Any ${content} """ '''
|
|
END |