11 Commits

Author SHA1 Message Date
Maciej Borzecki
d51c6d701a testutil: create the prefix of absolute paths when mocking commands
When mocking a command at an absolute path, create the leading prefix.

Signed-off-by: Maciej Borzecki <maciej.zenon.borzecki@canonical.com>
2019-11-22 11:25:22 +01:00
Maciej Borzecki
bf24be3119 testutil: make mocked command work with shellcheck from snaps
When shellcheck is running from a snap it will get a private /tmp. Scripts are
generated in a workdir that is places under /tmp, but inside the host mount
namespace, thus the file will not be accessible by shellcheck.

Work around that by feeding the script to be checked through stdin.

Signed-off-by: Maciej Borzecki <maciej.zenon.borzecki@canonical.com>
2019-04-03 12:53:02 +02:00
Maciej Borzecki
a1f3919502 testutil: run mocked commands though shellcheck
Shell is deceivingly easy to write. It's best that we run the test snippets
through shellcheck.

This adds ~2s to whole suite execution time on my box.

Signed-off-by: Maciej Borzecki <maciej.zenon.borzecki@canonical.com>
2019-03-28 08:35:32 +01:00
Michael Vogt
a16f175a4a testutil: do not import check.v1 as . ... 2018-05-23 12:13:45 +02:00
Zygmunt Krynicki
24d58c47be testutil: rename UNMOUNT_NOFOLLOW to umountNoFollow (#5099)
Signed-off-by: Zygmunt Krynicki <zygmunt.krynicki@canonical.com>
2018-04-26 08:14:56 +02:00
Maciej Borzecki
15f918ab36 testutil: do not use echo for printing potentially conflicting arguments
This comes as a result of investigating a failure of
SnapSuite.TestSnapRunAppWithStraceIntegration on Arch. In this particular case,
/bin/sh is symlinked to bash, thus `echo` is actually a [/usr]/bin/echo coming
from coreutils.

strace command in the test is called like this (sans the newlines and \):
  sudo -E <strace-path> -u maciek -f \
       -e !select,pselect6,_newselect,clock_gettime \
       <snap-confine-path> \
       snap.snapname.app \
       /usr/lib/snapd/snap-exec \
       snapname.app --arg1 arg2

Then the piece of shell script is expected to save each argument in a separate
line, with the script:

 for arg in "$@"; do
    echo "$arg" >> %[1]q
 done

the arguments -E and -e will be called like this:

  echo "-E"  <-- actually /usr/bin/echo "-E"
  echo "-e"

According to echo(1) both -e and -E are valid arguments and will be 'swallowed'
by the command, thus never appearing in the output.

Fix this by using a printf which does not have this problem.

Signed-off-by: Maciej Borzecki <maciej.zenon.borzecki@canonical.com>
2018-01-26 13:23:10 +01:00
Samuele Pedroni
bad49acb3d many: cleanup MockCommands and don't leave a process around after hookstate tests (#3367) 2017-05-22 18:34:11 +02:00
John R. Lenton
18e7b01b29 address review feedback 2016-09-06 17:03:07 +01:00
Michael Vogt
43072fbf4f use echo instead of printf to avoid % escaping issues (less portable but portable enough) 2016-06-03 19:28:19 +02:00
Michael Vogt
1eb6dcfa03 improve MockCommand.Calls() 2016-06-03 16:18:52 +02:00
Michael Vogt
f1fe59ac44 add MockCommand test 2016-06-03 16:01:38 +02:00