From 48664005876bb23debe6ec739f9ac9e845c278bd Mon Sep 17 00:00:00 2001 From: Maciej Borzecki Date: Thu, 4 Mar 2021 09:29:32 +0100 Subject: [PATCH] tests/unit/go: use su for running unit tests on 14.04 The tests.session helper requires busctl which is not available on 14.04, however we still want to run tests on those systems. Signed-off-by: Maciej Borzecki --- tests/unit/go/task.yaml | 46 ++++++++++++++++++++++++++++++----------- 1 file changed, 34 insertions(+), 12 deletions(-) diff --git a/tests/unit/go/task.yaml b/tests/unit/go/task.yaml index 45fe7cfa500..8c202f2fce3 100644 --- a/tests/unit/go/task.yaml +++ b/tests/unit/go/task.yaml @@ -3,11 +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: | - tests.session -u test prepare + if not os.query is-trusty; then + tests.session -u test prepare + fi restore: | - tests.session -u test restore + if not os.query is-trusty; then + tests.session -u test restore + fi rm -rf /tmp/static-unit-tests execute: | @@ -29,13 +37,27 @@ execute: | skip="${skip:-} SKIP_NAKEDRET=1" fi - tests.session -u test exec sh -c "cd /tmp/static-unit-tests/src/github.com/snapcore/snapd && \ - 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 && \ - PATH=$PATH \ - GOPATH=/tmp/static-unit-tests \ - SKIP_COVERAGE=1 \ - ./run-checks --unit" + if not os.query is-trusty; then + tests.session -u test exec sh -c "cd /tmp/static-unit-tests/src/github.com/snapcore/snapd && \ + 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 && \ + 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 && \ + 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 && \ + PATH=$PATH \ + GOPATH=/tmp/static-unit-tests \ + SKIP_COVERAGE=1 \ + ./run-checks --unit" test + fi