diff --git a/.github/workflows/test-module.yml b/.github/workflows/test-module.yml new file mode 100644 index 000000000..91c441392 --- /dev/null +++ b/.github/workflows/test-module.yml @@ -0,0 +1,26 @@ +name: Test module + +on: + workflow_dispatch: + inputs: + debug_shell: + description: "Debug shell" + required: true + type: boolean + workflow_run: + workflows: ["Publish images"] + types: [completed] + +jobs: + module: + if: ${{ github.event.workflow_run.conclusion == 'success' || github.event.workflow_run.conclusion == '' }} + uses: NethServer/ns8-github-actions/.github/workflows/module-info.yml@main + run_tests: + needs: module + uses: NethServer/ns8-github-actions/.github/workflows/test-on-digitalocean-infra.yml@main + with: + args: "ghcr.io/${{needs.module.outputs.owner}}/${{needs.module.outputs.name}}:${{needs.module.outputs.tag}}" + repo_ref: ${{needs.module.outputs.sha}} + debug_shell: ${{ github.event.inputs.debug_shell == 'true' || false }} + secrets: + do_token: ${{ secrets.do_token }} diff --git a/.gitignore b/.gitignore new file mode 100644 index 000000000..94d0240ab --- /dev/null +++ b/.gitignore @@ -0,0 +1 @@ +/tests/outputs diff --git a/tests/00_nethvoice_install_dependencies.robot b/tests/00_nethvoice_install_dependencies.robot new file mode 100644 index 000000000..da44e1f57 --- /dev/null +++ b/tests/00_nethvoice_install_dependencies.robot @@ -0,0 +1,21 @@ +*** Settings *** +Library SSHLibrary +Resource ./api.resource + +*** Test Cases *** +Setup internal user provider + ${response} = Run task cluster/add-internal-provider {"image":"openldap","node":1} + Set Global Variable ${openldap_module_id} ${response['module_id']} + Set Global Variable ${users_domain} domain.ns8.local + Run task module/${openldap_module_id}/configure-module {"domain":"${users_domain}","admuser":"admin","admpass":"Nethesis,1234","provision":"new-domain"} + +Check if nethvoice-proxy is installed correctly + Run task cluster/alter-repository {"name": "default", "status": true, "testing": true} + ... rc_expected=0 + ${output} ${rc} = Execute Command add-module nethvoice-proxy + ... return_rc=True + Should Be Equal As Integers ${rc} 0 + &{output} = Evaluate ${output} + Set Global Variable ${proxy_module_id} ${output.module_id} + Run task cluster/alter-repository {"name": "default", "status": true, "testing": true} + ... rc_expected=0 diff --git a/tests/01_nethvoice_add-module.robot b/tests/01_nethvoice_add-module.robot new file mode 100644 index 000000000..a86b08ab4 --- /dev/null +++ b/tests/01_nethvoice_add-module.robot @@ -0,0 +1,10 @@ +*** Settings *** +Library SSHLibrary + +*** Test Cases *** +Check if nethvoice is installed correctly + ${output} ${rc} = Execute Command add-module ${IMAGE_URL} 1 + ... return_rc=True + Should Be Equal As Integers ${rc} 0 + &{output} = Evaluate ${output} + Set Global Variable ${module_id} ${output.module_id} diff --git a/tests/10_nethvoice_actions/00_configure_module_validation.robot b/tests/10_nethvoice_actions/00_configure_module_validation.robot new file mode 100644 index 000000000..c135a7c8c --- /dev/null +++ b/tests/10_nethvoice_actions/00_configure_module_validation.robot @@ -0,0 +1,8 @@ +*** Settings *** +Library SSHLibrary +Resource ../api.resource + +*** Test Cases *** +Input can't be empty + ${response} = Run task module/${module_id}/configure-module + ... {} rc_expected=10 decode_json=False diff --git a/tests/10_nethvoice_actions/00_set-nethvoice-admin-password_validation.robot b/tests/10_nethvoice_actions/00_set-nethvoice-admin-password_validation.robot new file mode 100644 index 000000000..6886d04c3 --- /dev/null +++ b/tests/10_nethvoice_actions/00_set-nethvoice-admin-password_validation.robot @@ -0,0 +1,8 @@ +*** Settings *** +Library SSHLibrary +Resource ../api.resource + +*** Test Cases *** +Input can't be empty + ${response} = Run task module/${module_id}/set-nethvoice-admin-password + ... {} rc_expected=10 decode_json=False diff --git a/tests/10_nethvoice_actions/10_configure_integrations.robot b/tests/10_nethvoice_actions/10_configure_integrations.robot new file mode 100644 index 000000000..f526818a5 --- /dev/null +++ b/tests/10_nethvoice_actions/10_configure_integrations.robot @@ -0,0 +1,21 @@ +*** Settings *** +Library SSHLibrary +Resource ../api.resource + +*** Test Cases *** +Check if nethvoice can be configured correctly + ${response} = Run task module/${module_id}/configure-module + ... {"nethvoice_host": "voice.ns8.local", "nethcti_ui_host": "cti.ns8.local", "user_domain": "${users_domain}", "reports_international_prefix": "+39", "lets_encrypt": false} + ... decode_json=False + +Check if nethvoice is configured as expected + ${response} = Run task module/${module_id}/get-configuration {} + Should Be Equal As Strings ${response['nethvoice_host']} voice.ns8.local + Should Be Equal As Strings ${response['nethcti_ui_host']} cti.ns8.local + Should Be Equal As Strings ${response['user_domain']} ${users_domain} + Should Be Equal As Strings ${response['reports_international_prefix']} +39 + Should Be Equal As Strings ${response['lets_encrypt']} False + +Check if the password can be changed + ${response} = Run task module/${module_id}/set-nethvoice-admin-password + ... {"nethvoice_admin_password": "Nethesis,1234"} diff --git a/tests/99_nethvoice_remove-modules.robot b/tests/99_nethvoice_remove-modules.robot new file mode 100644 index 000000000..cedaa83dd --- /dev/null +++ b/tests/99_nethvoice_remove-modules.robot @@ -0,0 +1,17 @@ +*** Settings *** +Library SSHLibrary +Resource ./api.resource + +*** Test Cases *** +Check if nethvoice-proxy is removed correctly + ${rc} = Execute Command remove-module --no-preserve ${proxy_module_id} + ... return_rc=True return_stdout=False + Should Be Equal As Integers ${rc} 0 + +Check if nethvoice is removed correctly + ${rc} = Execute Command remove-module --no-preserve ${module_id} + ... return_rc=True return_stdout=False + Should Be Equal As Integers ${rc} 0 + +Remove internal domain + Run task cluster/remove-internal-domain {"domain":"${users_domain}"} diff --git a/tests/api.resource b/tests/api.resource new file mode 100644 index 000000000..575bc9478 --- /dev/null +++ b/tests/api.resource @@ -0,0 +1,14 @@ +*** Settings *** +Library SSHLibrary + +*** Keywords *** +Run task + [Arguments] ${action} ${input} ${decode_json}=${TRUE} ${rc_expected}=0 + ${stdout} ${stderr} ${rc} = Execute Command api-cli run ${action} --data '${input}' return_stdout=True return_stderr=True return_rc=True + Should Be Equal As Integers ${rc_expected} ${rc} Run task ${action} failed!${\n}${stderr} + IF ${decode_json} and len($stdout) > 0 + ${response} = Evaluate json.loads('''${stdout}''') modules=json + ELSE + ${response} = Set Variable ${stdout} + END + [Return] ${response} diff --git a/tests/nethvoice.robot b/tests/nethvoice.robot deleted file mode 100644 index ed641ae03..000000000 --- a/tests/nethvoice.robot +++ /dev/null @@ -1,25 +0,0 @@ -*** Settings *** -Library SSHLibrary - -*** Test Cases *** -Check if nethvoice is installed correctly - ${output} ${rc} = Execute Command add-module ${IMAGE_URL} 1 - ... return_rc=True - Should Be Equal As Integers ${rc} 0 - &{output} = Evaluate ${output} - Set Suite Variable ${module_id} ${output.module_id} - -Check if nethvoice can be configured - ${rc} = Execute Command api-cli run module/${module_id}/configure-module --data '{}' - ... return_rc=True return_stdout=False - Should Be Equal As Integers ${rc} 0 - -Check if nethvoice works as expected - ${rc} = Execute Command sleep 10 && curl -f http://127.0.0.1/nethvoice/ - ... return_rc=True return_stdout=False - Should Be Equal As Integers ${rc} 0 - -Check if nethvoice is removed correctly - ${rc} = Execute Command remove-module --no-preserve ${module_id} - ... return_rc=True return_stdout=False - Should Be Equal As Integers ${rc} 0