Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Introduce robotidy #459

Merged
merged 7 commits into from
Aug 30, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
name: SSHLibrary Python CI
name: Test SSHLibrary

on: [push, workflow_dispatch]
concurrency:
Expand Down
45 changes: 45 additions & 0 deletions .github/workflows/clean_code.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
name: SSHLibrary Python CI

on: [pull_request]
concurrency:
group: ${{ github.workflow }}-${{ github.ref }}
cancel-in-progress: true

jobs:
tidy:
name: Robotidy - Check Formatting
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- name: Set up Python
uses: actions/setup-python@v5
with:
python-version: "3.11"
- name: Install robotidy
run: |
pip install robotframework-tidy
- name: Check Test Formatting
run: |
robotidy --check --diff atest
validate-syntax:
name: Validate Test Syntax
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- name: Set up Python
uses: actions/setup-python@v5
with:
python-version: "3.11"
- name: Install SSHLibrary
run: |
python -m pip install --upgrade pip
pip install .
- name: Run tests
run: |
robot --dryrun -d results -e no-gh-actions -b console.log atest
- uses: actions/upload-artifact@v4
if: success() || failure()
with:
name: Syntax Validation
path: "results"
retention-days: 7
6 changes: 6 additions & 0 deletions atest/README.rst
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,11 @@ This guide tells how to run the acceptance tests of SSHLibrary. Acceptance tests

Because SSHLibrary is primary used on Linux, tests should be ran at least on it. If developing on OS X or Windows, setting up a virtual machine with Linux and SSHLibrary installed is the recommended approach.

Setup IDE
=========

Use ``robotframework-tidy`` to format the test files. It can be installed with pip: ``pip install robotframework-tidy``. If you do not format test cases according to robotidy, the PR check will fail automatically.

Setup on Linux
==============

Expand Down Expand Up @@ -209,3 +214,4 @@ In order to run the tests with IPv6, the ``::1`` must be used as host variable w

python atest/run.py --variable=HOST:::1 atest


3 changes: 1 addition & 2 deletions atest/__init__.robot
Original file line number Diff line number Diff line change
@@ -1,3 +1,2 @@
*** Settings ***
Force Tags Regression

Force Tags regression
167 changes: 87 additions & 80 deletions atest/connections.robot
Original file line number Diff line number Diff line change
@@ -1,132 +1,139 @@
*** Settings ***
Resource resources/common.robot
Test Teardown Close All Connections
Resource resources/common.robot

Test Teardown Close All Connections


*** Test Cases ***
Open Connection
Open Connection ${HOST}
Open Connection ${HOST}

Close Connection
[Setup] Login As Valid User
[Setup] Login As Valid User
Close Connection
Connection Should Be Closed

Close Connection Fails If No Connection
Run Keyword And Expect Error No open connection. Close Connection
Run Keyword And Expect Error No open connection. Close Connection

Switch Connection
${conn1_id} = Open Connection ${HOST} alias=one prompt=${PROMPT}
Login ${USERNAME} ${PASSWORD}
Write cd /tmp
${conn1_id} = Open Connection ${HOST} alias=one prompt=${PROMPT}
Login ${USERNAME} ${PASSWORD}
Write cd /tmp
Read Until Prompt
${conn_id2} = Open Connection ${HOST} alias=second prompt=${PROMPT}
Login ${USERNAME} ${PASSWORD}
${prev id} = Switch Connection ${conn1_id}
Should Be Equal ${prev id} ${conn_id2}
Write pwd
${output} = Read Until Prompt
Should Contain ${output} /tmp
${prev id} = Switch Connection second
Write pwd
${result} = Read Until Prompt
Should Contain ${result} ~
${conn_id2} = Open Connection ${HOST} alias=second prompt=${PROMPT}
Login ${USERNAME} ${PASSWORD}
${prev id} = Switch Connection ${conn1_id}
Should Be Equal ${prev id} ${conn_id2}
Write pwd
${output} = Read Until Prompt
Should Contain ${output} /tmp
${prev id} = Switch Connection second
Write pwd
${result} = Read Until Prompt
Should Contain ${result} ~

Switch Connection To None
[Setup] Login As Valid User
Switch Connection ${NONE}
[Setup] Login As Valid User
Switch Connection ${NONE}
Connection Should Be Closed

Switch to closed connection
Open Connection ${HOST} alias=SUT
Login ${USERNAME} ${PASSWORD}
Execute command ls
Open Connection ${HOST} alias=SUT
Login ${USERNAME} ${PASSWORD}
Execute command ls
close connection
Run keyword and expect error Non-existing index or alias 'SUT'. switch connection SUT
Run keyword and expect error Non-existing index or alias 'SUT'. switch connection SUT

Get pre-login banner without open connection
[Tags] no-gh-actions
${banner} = Get Pre Login Banner ${HOST}
Should Be Equal ${banner} Testing pre-login banner\n
[Tags] no-gh-actions
${banner} = Get Pre Login Banner ${HOST}
Should Be Equal ${banner} Testing pre-login banner\n

Get pre-login banner from current connection
Open Connection ${HOST} prompt=${PROMPT}
Login ${USERNAME} ${PASSWORD}
${banner} = Get Pre Login Banner
Should Be Equal ${banner} Testing pre-login banner\n
Open Connection ${HOST} prompt=${PROMPT}
Login ${USERNAME} ${PASSWORD}
${banner} = Get Pre Login Banner
Should Be Equal ${banner} Testing pre-login banner\n

Switch Connection When Previous Connection Was Closed
Open Connection ${HOST} alias=alias1
Open Connection ${HOST} alias=alias2
Switch Connection alias1
Open Connection ${HOST} alias=alias1
Open Connection ${HOST} alias=alias2
Switch Connection alias1
Close Connection
Connection Should Be Closed
${old_index}= Switch Connection alias2
Should Be Equal As Strings ${old_index} None
Run Keyword And Expect Error Non-existing index or alias 'alias1'. Switch Connection alias1
${conn}= Get Connection
Should Be Equal As Strings ${conn.index} 2
Should Be Equal As Strings ${conn.alias} alias2
${old_index} = Switch Connection alias2
Should Be Equal As Strings ${old_index} None
Run Keyword And Expect Error Non-existing index or alias 'alias1'. Switch Connection alias1
${conn} = Get Connection
Should Be Equal As Strings ${conn.index} 2
Should Be Equal As Strings ${conn.alias} alias2

Switch Connection Using Index When Previous Connection Was Closed
Open Connection ${HOST}
Open Connection ${HOST}
Switch Connection 1
Open Connection ${HOST}
Open Connection ${HOST}
Switch Connection 1
Close Connection
Connection Should Be Closed
Switch Connection 2
Run Keyword And Expect Error Non-existing index or alias '1'. Switch Connection 1
${conn}= Get Connection
Should Be Equal As Strings ${conn.index} 2
Switch Connection 2
Run Keyword And Expect Error Non-existing index or alias '1'. Switch Connection 1
${conn} = Get Connection
Should Be Equal As Strings ${conn.index} 2

Open Connection When Previous Connection Was Closed
Open Connection ${HOST} alias=alias1
Open Connection ${HOST} alias=alias1
Close Connection
Connection Should Be Closed
${idx}= Open Connection ${HOST} alias=alias2
Should Be Equal ${idx} ${2}
${conn}= Get Connection 2
Should Be Equal ${conn.index} ${2}
Should Be Equal ${conn.alias} alias2
${conn}= Get Connection alias2
Should Be Equal ${conn.index} ${2}
Should Be Equal ${conn.alias} alias2
${idx} = Open Connection ${HOST} alias=alias2
Should Be Equal ${idx} ${2}
${conn} = Get Connection 2
Should Be Equal ${conn.index} ${2}
Should Be Equal ${conn.alias} alias2
${conn} = Get Connection alias2
Should Be Equal ${conn.index} ${2}
Should Be Equal ${conn.alias} alias2

Reuse Closed Connection Alias
Open Connection ${HOST} alias=alias1
Open Connection ${HOST} alias=alias1
Close Connection
Connection Should Be Closed
Open Connection ${HOST} alias=alias1
${conn}= Get Connection 2
Should Be Equal ${conn.index} ${2}
Should Be Equal ${conn.alias} alias1
${conn}= Get Connection alias1
Should Be Equal ${conn.index} ${2}
Should Be Equal ${conn.alias} alias1
Open Connection ${HOST} alias=alias1
${conn} = Get Connection 2
Should Be Equal ${conn.index} ${2}
Should Be Equal ${conn.alias} alias1
${conn} = Get Connection alias1
Should Be Equal ${conn.index} ${2}
Should Be Equal ${conn.alias} alias1

Connection To Host Read From SSH Config File
Open Connection ${TEST_HOSTNAME}
Login ${USERNAME} ${PASSWORD} read_config=True
Open Connection ${TEST_HOSTNAME}
Login ${USERNAME} ${PASSWORD} read_config=True

Connection To Host Ignoring SSH Config File
Open Connection ${TEST_HOSTNAME}
Run Keyword And Expect Error *Err* Login ${USERNAME} ${PASSWORD} read_config=False
Run Keyword And Expect Error *Err* Login With Public Key ${KEY USERNAME} ${KEY} read_config=False
Open Connection ${TEST_HOSTNAME}
Run Keyword And Expect Error *Err* Login ${USERNAME} ${PASSWORD} read_config=False
Run Keyword And Expect Error *Err* Login With Public Key ${KEY USERNAME} ${KEY} read_config=False

Write In Teardown Should Not Hang If Auth Failed
Open Connection ${HOST}
Run Keyword And Expect Error Authentication failed* Login ${USERNAME} invalid
[Teardown] Run Keyword And Expect Error *Cannot open session, you need to establish a connection first. Write ls
Open Connection ${HOST}
Run Keyword And Expect Error Authentication failed* Login ${USERNAME} invalid
[Teardown] Run Keyword And Expect Error *Cannot open session, you need to establish a connection first. Write ls

Write Bare In Teardown Should Not Hang If Auth Failed
Open Connection ${HOST}
Run Keyword And Expect Error Login with public key failed* Login With Public Key ${USERNAME} ${KEY}_invalid
[Teardown] Run Keyword And Expect Error *Cannot open session, you need to establish a connection first. Write Bare ls
Open Connection ${HOST}
Run Keyword And Expect Error
... Login with public key failed*
... Login With Public Key
... ${USERNAME}
... ${KEY}_invalid
[Teardown] Run Keyword And Expect Error *Cannot open session, you need to establish a connection first. Write Bare ls

Login With Agent
[Tags] no-gh-actions
Open Connection ${HOST}
Login ${KEY USERNAME} allow_agent=True
[Tags] no-gh-actions
Open Connection ${HOST}
Login ${KEY USERNAME} allow_agent=True


*** Keywords ***
Connection Should Be Closed
Run Keyword And Expect Error No open connection. Write pwd
Run Keyword And Expect Error No open connection. Write pwd
Loading
Loading