This is useful when comparing more complex structure from external packages,
when the structures may have unexported fields that would otherwise be picked up
by check.DeepEquals.
Signed-off-by: Maciej Borzecki <maciej.zenon.borzecki@canonical.com>
The FileEquals checker can verify that the file content is equal to strings,
byte slices or something that implements fmt.Stringer. Extend the functionality
to allow checking that file contents are the same as of a reference file.
Signed-off-by: Maciej Borzecki <maciej.zenon.borzecki@canonical.com>
The standard session bus configuration searches for service activation
files found in /usr/share/dbus-1/services, and may load other custom
local configuration. This could cause the test suite to spawn arbitrary
services installed on the system.
By using a custom daemon configuration file, without this servicedir
configuration, we ensure that tests using the fixture only see names
provided by the test suite.
When not using ggcgo, the value of runtime.Compiler is "gc" not "go".
Thanks to @niemeyer for spotting this.
Signed-off-by: Ian Johnson <ian.johnson@canonical.com>
Add three checkers relevant for examining symbolic links:
- SymlinkTargetEquals checks for a fixed target
- SymlinkTargetContains checks for a substring
- SymlinkTargetMatches checks for a regular expression
They are modelled after FileContentsChecker but implement fewer
variants as symbolic link targets are usually short strings.
Signed-off-by: Zygmunt Krynicki <me@zygoon.pl>
make their order of execution also LIFO which is more expected
fix places that were wrong, also cleanup some of devicestate
suites to use AddCleanup more and not need specific TearDownTest
This commit avoids extra imports in timeouts.go and tweaks
the TimeoutTestSuite to follow the testutil_test pattern and
adds a MockRuntimeARCH() helper.
This commit is squashed history taken out of the refresh-app-awareness-v2
branch. It aggregated most of the new D-Bus helper logic in a pair of
packages. The dbusutil package contains non-silly logic to connect
to the session and system bus, as well as public mocking helpers.
The dbustest sub-package contains two helpers that provide dbus.Conn
for testing interaction and for testing bus access.
Note that I chose to leave behind one file in testutils, as it contains
existing test code used by user agent code. I can do that in another pass
to isolate it from this move.
This code is used in feature/refresh-app-awareness-v2, for both the
existing code in "snap run" and the new code in sandbox/cgroup package.
Signed-off-by: Zygmunt Krynicki <zygmunt.krynicki@canonical.com>
If we set this before calling shellcheck, if shellcheck is a snap, then we could
have issues mocking specifically systemctl, where shellcheck as a snap tries to
use `systemctl is-system-running` if there is a system key mismatch, and this
will call our mocked systemctl which leads to undesirable and very confusing
unit test failures.
Longer term we may want to consider not setting PATH in this manner as there
have been other similar bugs where some system tool is a snap and it affects
unit tests in a confusing way.
Signed-off-by: Ian Johnson <ian.johnson@canonical.com>
This patch adds support code for testing code making DBus calls.
It is similar in spirit to our HTTP testing code. A DBus connection
is provided, marshaling messages sent between application code driven
by the test and the message bus.
This allows testing any DBus interaction in isolation, with any scenario
that is desired.
Signed-off-by: Zygmunt Krynicki <zygmunt.krynicki@canonical.com>
On 14.04, the script file is apparently kept open for writingby flock(1) and
subsequent attempt to execve() it fails with ETXTBSY. Workaround that and place
the lock on the parent directory instead.
$ strace -e flock,execve -f /tmp/check-737788169571723474/0/usr/lib/snapd/snap-seccomp
...
flock(3, LOCK_EX) = 0
Process 18827 attached
[pid 18827] execve("/tmp/check-737788169571723474/0/usr/lib/snapd/snap-seccomp", ["/tmp/check-737788169571723474/0/"...], [/* 75 vars */]) = -1 ETXTBSY (Text file busy)
flock: /tmp/check-737788169571723474/0/usr/lib/snapd/snap-seccomp: Text file busy
[pid 18827] +++ exited with 69 +++
--- SIGCHLD {si_signo=SIGCHLD, si_code=CLD_EXITED, si_pid=18827, si_status=69, si_utime=0, si_stime=0} ---
+++ exited with 69 +++
Signed-off-by: Maciej Borzecki <maciej.zenon.borzecki@canonical.com>
The script generated by MockCommand() writes the call list into the log. Thus,
it cannot be called in parallel without risking the call log being corrupted by
interleaving writes.
Add a locked variant of mocked command that wraps the script execution with a
flock call that takes an exclusive lock.
Signed-off-by: Maciej Borzecki <maciej.zenon.borzecki@canonical.com>
The pair of helpers turn numeric flags for mount(2) and umount(2) to a
list of source constants that are useful for debugging. We had,
partially, similar helpers in lowlevel test-only code. Those are now
simple wrappers around the more general logic.
Due to cyclic imports osutil -> testutil -> osutil I've added the
new helpers to osutil/mount.
The new helpers will be shortly used by snap-update-ns logging
routines.
Signed-off-by: Zygmunt Krynicki <me@zygoon.pl>