aboutsummaryrefslogtreecommitdiff
path: root/test/insert.t
diff options
context:
space:
mode:
authorTad Fisher <tad@simple.com>2017-03-19 23:48:03 -0700
committerTad Fisher <tad@simple.com>2017-03-20 00:56:34 -0700
commit224c4dc57ee42215806c6fb8b92e64ddebaa7fd7 (patch)
tree66cb88d1fb3a776ac0cdb1439fece71be662613d /test/insert.t
parentacfab191e6bb33f840f0a7106c3eb4cd1ab76267 (diff)
Use expect for interactive tests
Diffstat (limited to 'test/insert.t')
-rwxr-xr-xtest/insert.t45
1 files changed, 38 insertions, 7 deletions
diff --git a/test/insert.t b/test/insert.t
index 0c19d11..b4af4f5 100755
--- a/test/insert.t
+++ b/test/insert.t
@@ -16,9 +16,18 @@ test_expect_success 'Prompts before overwriting key URI' '
uri1="otpauth://totp/Example:alice@google.com?secret=JBSWY3DPEHPK3PXP&issuer=Foo"
uri2="otpauth://totp/Example:alice@google.com?secret=JBSWY3DPEHPK3PXP&issuer=Bar"
- test_pass_init &&
- "$PASS" otp insert "$uri1" passfile &&
- test_faketty "$PASS" otp insert "$uri2" passfile < <(echo n) &&
+ test_pass_init
+ "$PASS" otp insert "$uri1" passfile
+ expect <<EOD
+ spawn "$PASS" otp insert "$uri2" passfile
+ expect {
+ "An entry already exists" {
+ send "n\r"
+ exp_continue
+ }
+ eof
+ }
+EOD
[[ $("$PASS" show passfile) == "$uri1" ]]
'
@@ -43,16 +52,38 @@ test_expect_success 'Reads non-terminal input' '
test_expect_success 'Reads terminal input in noecho mode' '
uri="otpauth://totp/Example:alice@google.com?secret=JBSWY3DPEHPK3PXP&issuer=Example"
- test_pass_init &&
- test_faketty "$PASS" otp insert passfile < <(echo -ne "$uri\n$uri\n") &&
+ test_pass_init
+ expect <<EOD
+ spawn "$PASS" otp insert passfile
+ expect {
+ "Enter" {
+ send "$uri\r"
+ exp_continue
+ }
+ "Retype" {
+ send "$uri\r"
+ exp_continue
+ }
+ eof
+ }
+EOD
[[ $("$PASS" show passfile) == "$uri" ]]
'
test_expect_success 'Reads terminal input in echo mode' '
uri="otpauth://totp/Example:alice@google.com?secret=JBSWY3DPEHPK3PXP&issuer=Example"
- test_pass_init &&
- test_faketty "$PASS" otp insert -e passfile <<< "$uri" &&
+ test_pass_init
+ expect <<EOD
+ spawn "$PASS" otp insert -e passfile
+ expect {
+ "Enter" {
+ send "$uri\r"
+ exp_continue
+ }
+ eof
+ }
+EOD
[[ $("$PASS" show passfile) == "$uri" ]]
'