Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

tests/unit/go: use tests.session wrapper for running tests as a user #9976

Merged
merged 5 commits into from
Mar 5, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
12 changes: 6 additions & 6 deletions secboot/secboot_tpm_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -1162,7 +1162,7 @@ func (s *secbootSuite) TestUnlockEncryptedVolumeUsingKeyErr(c *C) {
func (s *secbootSuite) TestUnlockVolumeUsingSealedKeyIfEncryptedFdeRevealKeyTruncatesStreamFiles(c *C) {
// this test uses a real systemd-run --user so check here if that
// actually works
if output, err := exec.Command("systemd-run", "--user", "--wait", "--collect", "true").CombinedOutput(); err != nil {
if output, err := exec.Command("systemd-run", "--user", "--wait", "--collect", "--service-type=exec", "true").CombinedOutput(); err != nil {
c.Skip(fmt.Sprintf("systemd-run not working: %v", osutil.OutputErr(output, err)))
}

Expand Down Expand Up @@ -1264,7 +1264,7 @@ service result: exit-code
func (s *secbootSuite) TestUnlockVolumeUsingSealedKeyIfEncryptedFdeRevealKeyErr(c *C) {
// this test uses a real systemd-run --user so check here if that
// actually works
if output, err := exec.Command("systemd-run", "--user", "--wait", "--collect", "true").CombinedOutput(); err != nil {
if output, err := exec.Command("systemd-run", "--user", "--wait", "--collect", "--service-type=exec", "/bin/true").CombinedOutput(); err != nil {
c.Skip(fmt.Sprintf("systemd-run not working: %v", osutil.OutputErr(output, err)))
}

Expand Down Expand Up @@ -1302,7 +1302,7 @@ service result: exit-code
func (s *secbootSuite) TestUnlockVolumeUsingSealedKeyIfEncryptedFdeRevealKey(c *C) {
// this test uses a real systemd-run --user so check here if that
// actually works
if output, err := exec.Command("systemd-run", "--user", "--wait", "--collect", "true").CombinedOutput(); err != nil {
if output, err := exec.Command("systemd-run", "--user", "--wait", "--collect", "--service-type=exec", "/bin/true").CombinedOutput(); err != nil {
c.Skip(fmt.Sprintf("systemd-run not working: %v", osutil.OutputErr(output, err)))
}

Expand Down Expand Up @@ -1363,7 +1363,7 @@ printf "unsealed-key-from-hook"
func (s *secbootSuite) TestLockSealedKeysCallsFdeReveal(c *C) {
// this test uses a real systemd-run --user so check here if that
// actually works
if output, err := exec.Command("systemd-run", "--user", "--wait", "--collect", "true").CombinedOutput(); err != nil {
if output, err := exec.Command("systemd-run", "--user", "--wait", "--collect", "--service-type=exec", "/bin/true").CombinedOutput(); err != nil {
c.Skip(fmt.Sprintf("systemd-run not working: %v", osutil.OutputErr(output, err)))
}

Expand Down Expand Up @@ -1394,7 +1394,7 @@ cat - > %s
func (s *secbootSuite) TestLockSealedKeysHonorsRuntimeMax(c *C) {
// this test uses a real systemd-run --user so check here if that
// actually works
if output, err := exec.Command("systemd-run", "--user", "--wait", "--collect", "true").CombinedOutput(); err != nil {
if output, err := exec.Command("systemd-run", "--user", "--wait", "--collect", "--service-type=exec", "/bin/true").CombinedOutput(); err != nil {
c.Skip(fmt.Sprintf("systemd-run not working: %v", osutil.OutputErr(output, err)))
}

Expand All @@ -1421,7 +1421,7 @@ func (s *secbootSuite) TestLockSealedKeysHonorsRuntimeMax(c *C) {
func (s *secbootSuite) TestLockSealedKeysHonorsParanoia(c *C) {
// this test uses a real systemd-run --user so check here if that
// actually works
if output, err := exec.Command("systemd-run", "--user", "--wait", "--collect", "true").CombinedOutput(); err != nil {
if output, err := exec.Command("systemd-run", "--user", "--wait", "--collect", "--service-type=exec", "/bin/true").CombinedOutput(); err != nil {
c.Skip(fmt.Sprintf("systemd-run not working: %v", osutil.OutputErr(output, err)))
}

Expand Down
55 changes: 42 additions & 13 deletions tests/unit/go/task.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,19 @@ summary: Run project static and unit tests
# Start before anything else as it takes a long time.
priority: 1000

# tests.session requires busctl, which is not available on 14.04, but we still
# want to run the tests there at the same time, we should not run into problems
# with delayed session cleanup on this system

prepare: |
if not os.query is-trusty; then
tests.session -u test prepare
fi

restore: |
if not os.query is-trusty; then
tests.session -u test restore
fi
rm -rf /tmp/static-unit-tests

execute: |
Expand All @@ -25,16 +37,33 @@ execute: |
skip="${skip:-} SKIP_NAKEDRET=1"
fi

su -l -c "cd /tmp/static-unit-tests/src/github.com/snapcore/snapd && \
GO111MODULE=off \
PATH=$PATH \
GOPATH=/tmp/static-unit-tests \
${skip:-} \
./run-checks --static" test

su -l -c "cd /tmp/static-unit-tests/src/github.com/snapcore/snapd && \
GO111MODULE=off\
PATH=$PATH \
GOPATH=/tmp/static-unit-tests \
SKIP_COVERAGE=1 \
./run-checks --unit" test
if not os.query is-trusty; then
tests.session -u test exec sh -c "cd /tmp/static-unit-tests/src/github.com/snapcore/snapd && \
GO111MODULE=off \
PATH=$PATH \
GOPATH=/tmp/static-unit-tests \
${skip:-} \
./run-checks --static"

tests.session -u test exec sh -c "cd /tmp/static-unit-tests/src/github.com/snapcore/snapd && \
GO111MODULE=off \
PATH=$PATH \
GOPATH=/tmp/static-unit-tests \
SKIP_COVERAGE=1 \
./run-checks --unit"
else
# 14.04 only
su -l -c "cd /tmp/static-unit-tests/src/github.com/snapcore/snapd && \
GO111MODULE=off \
PATH=$PATH \
GOPATH=/tmp/static-unit-tests \
${skip:-} \
./run-checks --static" test

su -l -c "cd /tmp/static-unit-tests/src/github.com/snapcore/snapd && \
GO111MODULE=off \
PATH=$PATH \
GOPATH=/tmp/static-unit-tests \
SKIP_COVERAGE=1 \
./run-checks --unit" test
fi