From f18eaea8cf879829a93a5c375f13a1bd76bc105d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Fran=C3=A7ois=20Garillot?= <4142+huitseeker@users.noreply.github.com> Date: Mon, 16 Nov 2020 14:41:06 -0500 Subject: [PATCH] Test examples (#87) * Fixing simple_login example * Adds script that tests the simple_login example * Add GH action to run said script Co-authored-by: Kevin Lewi --- .github/workflows/main.yml | 20 ++++++++++ scripts/simple_login.exp | 80 ++++++++++++++++++++++++++++++++++++++ 2 files changed, 100 insertions(+) create mode 100755 scripts/simple_login.exp diff --git a/.github/workflows/main.yml b/.github/workflows/main.yml index 15f3a3d..49f1755 100644 --- a/.github/workflows/main.yml +++ b/.github/workflows/main.yml @@ -35,6 +35,26 @@ jobs: command: test args: --no-default-features --features ${{ matrix.backend_feature }} + simple-login-test: + runs-on: ubuntu-latest + strategy: + fail-fast: false + name: test simple_login command-line example + steps: + - name: install expect + run: sudo apt-get install expect + - name: Checkout sources + uses: actions/checkout@v2 + - name: install rust + uses: actions-rs/toolchain@v1 + with: + profile: minimal + toolchain: nightly + override: true + components: rustfmt, clippy + - name: Run expect (which then runs cargo run) + run: expect -f scripts/simple_login.exp + cross-test: name: Test on ${{ matrix.target }} (using cross) runs-on: ubuntu-latest diff --git a/scripts/simple_login.exp b/scripts/simple_login.exp new file mode 100755 index 0000000..9abb3ab --- /dev/null +++ b/scripts/simple_login.exp @@ -0,0 +1,80 @@ +#!/bin/expect -f + +set timeout 1 +spawn cargo run --example simple_login +match_max 100000 +sleep 1 +expect "* +\r +Currently registered usernames: \\\[\\\]\r +\r +Enter an option (1 or 2):\r +1) Register a user\r +2) Login as a user\r +\r +" +sleep .1 +send -- "1\r" +expect "Username: \r" +send -- "foo\r" +expect "Password: \r" +send -- "bar\r" +expect "* +\r +Currently registered usernames: \\\[\"foo\"\\\]\r +\r +Enter an option (1 or 2):\r +1) Register a user\r +2) Login as a user\r +\r +" +sleep .1 +send -- "2\r" +expect "Username: \r" +send -- "baz\r" +expect "Password: \r" +send -- "quux\r" +expect "*Error: Could not find username registered\r +\r +Currently registered usernames: \\\[\"foo\"\\\]\r +\r +Enter an option (1 or 2):\r +1) Register a user\r +2) Login as a user\r +\r +" +sleep .1 +send -- "2\r" +expect "Username: \r" +send -- "foo\r" +expect "Password: \r" +send -- "baz\r" +expect "*Incorrect password, please try again.\r +\r +Currently registered usernames: \\\[\"foo\"\\\]\r +\r +Enter an option (1 or 2):\r +1) Register a user\r +2) Login as a user\r +\r +" +sleep .1 +send -- "2\r" +expect "Username: \r" +send -- "foo\r" +expect "Password: \r" +send -- "bar\r" +expect "* +\r +*Login success!\r +\r +Currently registered usernames: \\\[\"foo\"\\\]\r +\r +Enter an option (1 or 2):\r +1) Register a user\r +2) Login as a user\r +\r +" +sleep .1 +send -- "" +expect eof