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: use SNAPCRAFT_PACKAGE_TYPE everywhere #2295

Merged
merged 4 commits into from Sep 27, 2018
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
2 changes: 1 addition & 1 deletion .travis.yml
Expand Up @@ -65,7 +65,7 @@ jobs:
- python3 -m pip install -r requirements.txt
- python3 -m pip install -r requirements-devel.txt
script:
- SNAPCRAFT_FROM_BREW=1 ./runtests.sh tests.integration.store.test_store_login_logout use-run
- SNAPCRAFT_PACKAGE_TYPE=brew ./runtests.sh tests.integration.store.test_store_login_logout use-run

- stage: snap
if: type != cron
Expand Down
6 changes: 3 additions & 3 deletions TESTING.md
Expand Up @@ -116,13 +116,13 @@ The snaps tests script has more complex arguments. For an explanation of them, r

python3 -m snaps_tests -h

The integration and snaps suites can be run using the snapcraft source from the repository, or using the snapacraft command installed in the system. By default, they will use the source code, so you can modify your clone of the repository and verify that your changes are correct. If instead you want to verify that the snapcraft version installed in your system is correct, run them with the environment variable `SNAPCRAFT_FROM_DEB` or `SNAPCRAFT_FROM_SNAP` set, like this:
The integration and snaps suites can be run using the snapcraft source from the repository, or using the snapacraft command installed in the system. By default, they will use the source code, so you can modify your clone of the repository and verify that your changes are correct. If instead you want to verify that the snapcraft version installed in your system is correct, run them with the environment variable `SNAPCRAFT_PACKAGE_TYPE` set to either "snap" or "deb", like this:

SNAPCRAFT_FROM_DEB=1 ./runtests.sh tests/integration
SNAPCRAFT_PACKAGE_TYPE=snap ./runtests.sh tests/integration

or

SNAPCRAFT_FROM_SNAP=1 ./runtests.sh tests/integration
SNAPCRAFT_PACKAGE_TYPE=type ./runtests.sh tests/integration

## Setting up the store test user

Expand Down
2 changes: 1 addition & 1 deletion debian/tests/integrationtests
Expand Up @@ -23,5 +23,5 @@ chmod 777 /home/ubuntu/autopkgtest_tmp

for suite in $suites; do
echo "$suite"
su ubuntu -c "SNAPCRAFT_FROM_DEB=1 SNAPCRAFT_SLOW_TESTS=${SNAPCRAFT_SLOW_TESTS} TEST_STORE=fake ADT_TEST=1 PATH=/snap/bin:$PATH TMPDIR=\$HOME/autopkgtest_tmp python3 -m unittest discover -b -v -s ${suite} -p ${SNAPCRAFT_TEST_PATTERN}"
su ubuntu -c "SNAPCRAFT_PACKAGE_TYPE=deb SNAPCRAFT_SLOW_TESTS=${SNAPCRAFT_SLOW_TESTS} TEST_STORE=fake ADT_TEST=1 PATH=/snap/bin:$PATH TMPDIR=\$HOME/autopkgtest_tmp python3 -m unittest discover -b -v -s ${suite} -p ${SNAPCRAFT_TEST_PATTERN}"
done
2 changes: 1 addition & 1 deletion debian/tests/snapstests
Expand Up @@ -28,4 +28,4 @@ EOF

systemctl daemon-reload

su ubuntu -c "ADT_TEST=1 SNAPCRAFT_FROM_DEB=1 python3 -m snaps_tests --ip localhost"
su ubuntu -c "ADT_TEST=1 SNAPCRAFT_PACKAGE_TYPE=deb python3 -m snaps_tests --ip localhost"
7 changes: 4 additions & 3 deletions snaps_tests/__init__.py
Expand Up @@ -109,10 +109,11 @@ def setUp(self):
super().setUp()

self.patchelf_command = "patchelf"
if os.getenv("SNAPCRAFT_FROM_SNAP", False):
package_type = os.getenv("SNAPCRAFT_PACKAGE_TYPE")
if package_type == "snap":
self.snapcraft_command = "/snap/bin/snapcraft"
self.patchelf_command = "/snap/snapcraft/current/usr/bin/patchelf"
elif os.getenv("SNAPCRAFT_FROM_DEB", False):
elif package_type == "deb":
self.snapcraft_command = "/usr/bin/snapcraft"
elif os.getenv("VIRTUAL_ENV"):
self.snapcraft_command = os.path.join(
Expand All @@ -124,7 +125,7 @@ def setUp(self):
else:
raise EnvironmentError(
"snapcraft is not setup correctly for testing. Either set "
"SNAPCRAFT_FROM_SNAP or SNAPCRAFT_FROM_DEB to run from either "
"SNAPCRAFT_PACKAGE_TYPE to 'snap' or 'deb', to run from either "
"the snap or deb, or make sure your venv is properly setup "
"as described in HACKING.md."
)
Expand Down
3 changes: 0 additions & 3 deletions spread.yaml
@@ -1,9 +1,6 @@
project: snapcraft

environment:
# FIXME: This variable is only used by the spread_tests/ suite.
SNAPCRAFT_FROM_SNAP: "1"

# This variable can be set to either "deb" or "snap". It defaults to "snap".
SNAPCRAFT_PACKAGE_TYPE: "$(HOST: echo ${SNAPCRAFT_PACKAGE_TYPE:-snap})"

Expand Down
27 changes: 13 additions & 14 deletions tests/integration/__init__.py
Expand Up @@ -48,9 +48,16 @@ class RegisterError(Exception):
class TestCase(testtools.TestCase):
def setUp(self):
super().setUp()
if os.getenv("SNAPCRAFT_FROM_SNAP", False):

self.patchelf_command = "patchelf"
self.execstack_command = "execstack"

package_type = os.getenv("SNAPCRAFT_PACKAGE_TYPE")
if package_type == "snap":
self.snapcraft_command = "/snap/bin/snapcraft"
elif os.getenv("SNAPCRAFT_FROM_DEB", False):
self.patchelf_command = "/snap/snapcraft/current/usr/bin/patchelf"
self.execstack_command = "/snap/snapcraft/current/usr/sbin/execstack"
elif package_type == "deb":
self.snapcraft_command = "/usr/bin/snapcraft"
self.snapcraft_parser_command = "/usr/bin/snapcraft-parser"
elif os.getenv("VIRTUAL_ENV") and sys.platform == "win32":
Expand All @@ -65,24 +72,16 @@ def setUp(self):
self.snapcraft_parser_command = os.path.join(
os.getenv("VIRTUAL_ENV"), "bin", "snapcraft-parser"
)
elif os.getenv("SNAPCRAFT_FROM_BREW", False):
elif package_type == "brew":
self.snapcraft_command = "/usr/local/bin/snapcraft"
else:
raise EnvironmentError(
"snapcraft is not setup correctly for testing. Either set "
"SNAPCRAFT_FROM_SNAP, SNAPCRAFT_FROM_DEB or "
"SNAPCRAFT_FROM_BREW to run from either the snap, deb or "
"brew, or make sure your venv is properly setup as described "
"in HACKING.md."
"SNAPCRAFT_PACKAGE_TYPE to 'snap', 'deb' or 'brew', to run from "
"either the snap, deb or homebrew or make sure your venv is properly "
"setup as described in HACKING.md."
)

if os.getenv("SNAPCRAFT_FROM_SNAP", False):
self.patchelf_command = "/snap/snapcraft/current/usr/bin/patchelf"
self.execstack_command = "/snap/snapcraft/current/usr/sbin/execstack"
else:
self.patchelf_command = "patchelf"
self.execstack_command = "execstack"

self.snaps_dir = os.path.join(os.path.dirname(__file__), "snaps")
temp_cwd_fixture = fixture_setup.TempCWD()
self.useFixture(temp_cwd_fixture)
Expand Down
2 changes: 1 addition & 1 deletion tests/integration/containers/test_container_builds.py
Expand Up @@ -25,7 +25,7 @@
class ContainerBuildsTestCase(integration.TestCase):
def setUp(self):
super().setUp()
if os.getenv("SNAPCRAFT_FROM_SNAP", False):
if os.getenv("SNAPCRAFT_PACKAGE_TYPE") == "snap":
self.skipTest(
"container build tests when running from a snap are "
"currently broken LP: #1738210"
Expand Down
10 changes: 0 additions & 10 deletions tests/integration/general/test_global_properties.py
Expand Up @@ -13,7 +13,6 @@
#
# You should have received a copy of the GNU General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>.
import os

import testscenarios

Expand All @@ -28,15 +27,6 @@ class UnicodePropertyTestCase(testscenarios.WithScenarios, integration.TestCase)
]

def test_invalid_unicode_workaround(self):
if not (
os.getenv("SNAPCRAFT_FROM_SNAP", False)
or os.getenv("SNAPCRAFT_FROM_DEB", False)
):
self.skipTest(
"The yaml unicode patch is applied to the snap "
"and python3-yaml package, but not PyYAML in PyPI"
)

snapcraft_yaml = fixture_setup.SnapcraftYaml(
self.path,
name=self.name,
Expand Down
2 changes: 1 addition & 1 deletion tests/integration/general/test_parser.py
Expand Up @@ -30,7 +30,7 @@ class ParserTestCase(integration.TestCase):

def setUp(self):
super().setUp()
if os.getenv("SNAPCRAFT_FROM_SNAP", False):
if os.getenv("SNAPCRAFT_PACKAGE_TYPE") == "snap":
self.skipTest("The snapcraft-parser is not provided by the snap")
self.useFixture(fixtures.EnvironmentVariable("TMPDIR", self.path))

Expand Down
2 changes: 1 addition & 1 deletion tools/travis/run_integration_test.sh
Expand Up @@ -61,7 +61,7 @@ setup_lxd() {
$lxc config set "$name" environment.GITHUB_TEST_PASSWORD "$GITHUB_TEST_PASSWORD"
$lxc config set "$name" environment.GH_TOKEN "$GH_TOKEN"
$lxc config set "$name" environment.LC_ALL "C.UTF-8"
$lxc config set "$name" environment.SNAPCRAFT_FROM_SNAP "1"
$lxc config set "$name" environment.SNAPCRAFT_PACKAGE_TYPE "snap"

$lxc exec "$name" -- apt update
}
Expand Down