File: ssh_test.sh

package info (click to toggle)
kworkflow 20191112-1.2
  • links: PTS
  • area: main
  • in suites: bookworm, sid, trixie
  • size: 2,836 kB
  • sloc: perl: 7,354; sh: 2,397; ansic: 80; python: 44; makefile: 38
file content (122 lines) | stat: -rwxr-xr-x 2,841 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
#!/bin/bash

#
# NOTE: We're not testing the ssh command here, just the kw ssh operation
#

. ./src/vm.sh --source-only
. ./tests/utils --source-only

INVALID_ARG="Invalid arguments"
NO_SUCH_FILE="No such file"
TEST_PATH="tests/.tmp"

SSH_OK="ssh -p 3333 127.0.0.1"

function suite
{
  suite_addTest "vmSshFailsTest"
  suite_addTest "vmSshTest"
  suite_addTest "vmSshCommandTest"
  suite_addTest "vmSshScriptTest"
}

function setupSsh
{
  local -r current_path=$PWD

  rm -rf $TEST_PATH

  mkdir -p $TEST_PATH

  cp -f tests/samples/kworkflow.config $TEST_PATH
  cp -f tests/samples/dmesg $TEST_PATH

  cd $TEST_PATH
  load_configuration
  cd $current_path
}

function tearDownSsh
{
  rm -rf $TEST_PATH
}

function vmSshFailsTest
{
  setupSsh

  local args="--lala"
  local ret=$(vm_ssh $args)

  assertTrue "We expected a substring \"$INVALID_ARG: $args\", but we got \"$ret\"" '[[ $ret =~ "$INVALID_ARG: $args" ]]'

  args="-m"
  ret=$(vm_ssh $args)
  assertTrue "We expected a substring \"$INVALID_ARG: $args\", but we got \"$ret\"" '[[ $ret =~ "$INVALID_ARG: $args" ]]'

  args="-d="
  ret=$(vm_ssh $args)
  assertTrue "We expected a substring \"$INVALID_ARG: $args\", but we got \"$ret\"" '[[ $ret =~ "$INVALID_ARG: $args" ]]'

  args="-c"
  ret=$(vm_ssh $args)
  assertTrue "We expected a substring \"$INVALID_ARG: $args\", but we got \"$ret\"" '[[ $ret =~ "$INVALID_ARG: $args" ]]'

  args="-s"
  ret=$(vm_ssh $args)
  assertTrue "We expected a substring \"$INVALID_ARG: $args\", but we got \"$ret\"" '[[ $ret =~ "$INVALID_ARG: $args" ]]'

  args="-s="
  ret=$(vm_ssh $args)
  assertTrue "We expected a substring \"$NO_SUCH_FILE\", but we got \"$ret\"" '[[ $ret =~ "$NO_SUCH_FILE" ]]'

  args="--script="
  ret=$(vm_ssh $args)
  assertTrue "We expected a substring \"$NO_SUCH_FILE\", but we got \"$ret\"" '[[ $ret =~ "$NO_SUCH_FILE" ]]'

  tearDownSsh
}

function vmSshTest
{
  setupSsh

  ret=$(vm_ssh 2>&1)

  assertTrue "We expected a substring \"$SSH_OK\", but we got \"$ret\"" '[[ $ret =~ "$SSH_OK" ]]'

  tearDownSsh
}

function vmSshCommandTest
{
  setupSsh

  ret=$(vm_ssh -c="pwd" 2>&1)
  msg="$SSH_OK pwd"
  assertTrue "We expected a substring \"$msg\", but we got \"$ret\"" '[[ $ret =~ "$msg" ]]'

  ret=$(vm_ssh --command="ls /etc/" 2>&1)
  msg="$SSH_OK ls /etc/"
  assertTrue "We expected a substring \"$msg\", but we got \"$ret\"" '[[ $ret =~ "$msg" ]]'

  tearDownSsh
}

function vmSshScriptTest
{
  setupSsh

  ret=$(vm_ssh -s="/not/a/valid/path/xpto" 2>&1)
  msg="$NO_SUCH_FILE: \"/not/a/valid/path/xpto\""
  assertTrue "We expected a substring \"$msg\", but we got \"$ret\"" '[[ $ret =~ "$msg" ]]'

  ret=$(vm_ssh -s="$TEST_PATH/dmesg" 2>&1)
  msg="$SSH_OK \"bash -s\" -- < $TEST_PATH/dmesg"
  assertTrue "We expected a substring \"$msg\", but we got \"$ret\"" '[[ $ret =~ "$msg" ]]'

  tearDownSsh
}

invoke_shunit