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: cover manifest generation with review-tools #2234

Closed
wants to merge 2 commits into from
Closed
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 @@ -55,7 +55,7 @@ jobs:
- codecov --token="$CODECOV_TOKEN"

- stage: osx-integration-store
if: type != cron
if: repo != "snapcore/snapcraft"
os: osx
install:
- brew upgrade python
Expand Down
69 changes: 54 additions & 15 deletions tests/integration/general/test_asset_recording.py
Expand Up @@ -16,8 +16,10 @@

import filecmp
import os
import shutil
import subprocess
import sys
import tempfile
import yaml

import apt
Expand All @@ -38,8 +40,39 @@ class AssetRecordingBaseTestCase(integration.TestCase):

def setUp(self):
super().setUp()
# The combination of snapd, lxd and armhf does not currently work.
if os.environ.get("ADT_TEST") and self.deb_arch == "armhf":
self.skipTest("The autopkgtest armhf runners can't install snaps")

self.useFixture(fixtures.EnvironmentVariable("SNAPCRAFT_BUILD_INFO", "1"))

# snapd has no easy way of telling me if a snap is installed from its cli.
try:
subprocess.check_output(["review-tools.snap-review", "--help"])
except FileNotFoundError:
subprocess.check_call(["sudo", "snap", "install", "review-tools", "--edge"])

def assert_review_passes(self, snap_file: str) -> None:
# review-tools do no really have access to tmp, let's assume it can look
# in its own snap directory and that that does not change as we cannot
# query what the data store is for a given snap.
review_tools_common_dir = os.path.expanduser(
os.path.join("~", "snap", "review-tools", "common")
)
os.makedirs(review_tools_common_dir, exist_ok=True)
with tempfile.NamedTemporaryFile(dir=review_tools_common_dir) as temp_snap_file:
shutil.copyfile(snap_file, temp_snap_file.name)
try:
subprocess.check_output(
["review-tools.snap-review", temp_snap_file.name]
)
except subprocess.CalledProcessError as call_error:
self.fail(
"{!r} does not pass the review:\n{}".format(
snap_file, call_error.stdout.decode()
)
)


class SnapcraftYamlRecordingTestCase(AssetRecordingBaseTestCase):
def test_prime_records_snapcraft_yaml_copy(self):
Expand All @@ -57,7 +90,7 @@ def test_prime_records_snapcraft_yaml_copy(self):

class ManifestRecordingTestCase(AssetRecordingBaseTestCase):
def test_prime_records_uname(self):
self.run_snapcraft("prime", project_dir="basic")
self.run_snapcraft(["snap", "--output", "basic.snap"], project_dir="basic")

recorded_yaml_path = os.path.join(self.prime_dir, "snap", "manifest.yaml")
with open(recorded_yaml_path) as recorded_yaml_file:
Expand All @@ -71,9 +104,10 @@ def test_prime_records_uname(self):
self.assertThat(
recorded_yaml["parts"]["dummy-part"]["uname"], Equals(expected_uname)
)
self.assert_review_passes("basic.snap")

def test_prime_records_installed_packages(self):
self.run_snapcraft("prime", project_dir="basic")
self.run_snapcraft(["snap", "--output", "basic.snap"], project_dir="basic")

recorded_yaml_path = os.path.join(self.prime_dir, "snap", "manifest.yaml")
with open(recorded_yaml_path) as recorded_yaml_file:
Expand All @@ -87,13 +121,11 @@ def test_prime_records_installed_packages(self):
recorded_yaml["parts"]["dummy-part"]["installed-packages"],
Contains(expected_package),
)
self.assert_review_passes("basic.snap")

def test_prime_records_installed_snaps(self):
if os.environ.get("ADT_TEST") and self.deb_arch == "armhf":
self.skipTest("The autopkgtest armhf runners can't install snaps")

subprocess.check_call(["sudo", "snap", "install", "core"])
self.run_snapcraft("prime", project_dir="basic")
self.run_snapcraft(["snap", "--output", "basic.snap"], project_dir="basic")

recorded_yaml_path = os.path.join(self.prime_dir, "snap", "manifest.yaml")
with open(recorded_yaml_path) as recorded_yaml_file:
Expand All @@ -106,20 +138,22 @@ def test_prime_records_installed_snaps(self):
recorded_yaml["parts"]["dummy-part"]["installed-snaps"],
Contains(expected_package),
)
self.assert_review_passes("basic.snap")

def test_prime_with_architectures(self):
"""Test the recorded manifest for a basic snap

This snap doesn't have stage or build packages and is declared that it
works on all architectures.
"""
self.run_snapcraft("prime", project_dir="basic")
self.run_snapcraft(["snap", "--output", "basic.snap"], project_dir="basic")

recorded_yaml_path = os.path.join(self.prime_dir, "snap", "manifest.yaml")
with open(recorded_yaml_path) as recorded_yaml_file:
recorded_yaml = yaml.load(recorded_yaml_file)

self.assertThat(recorded_yaml["architectures"], Equals(["all"]))
self.assert_review_passes("basic.snap")

def test_prime_without_architectures_records_current_arch(self):
"""Test the recorded manifest for a basic snap
Expand All @@ -128,18 +162,19 @@ def test_prime_without_architectures_records_current_arch(self):
that it works on all architectures, which makes it specific to the
current architecture.
"""
self.run_snapcraft("prime", project_dir="basic-without-arch")
self.run_snapcraft(
["snap", "--output", "basic-without-arch.snap"],
project_dir="basic-without-arch",
)

recorded_yaml_path = os.path.join(self.prime_dir, "snap", "manifest.yaml")
with open(recorded_yaml_path) as recorded_yaml_file:
recorded_yaml = yaml.load(recorded_yaml_file)

self.assertThat(recorded_yaml["architectures"], Equals([self.deb_arch]))
self.assert_review_passes("basic-without-arch.snap")

def test_prime_records_build_snaps(self):
if os.environ.get("ADT_TEST") and self.deb_arch == "armhf":
self.skipTest("The autopkgtest armhf runners can't install snaps")

self.useFixture(fixture_setup.WithoutSnapInstalled("hello"))
snapcraft_yaml = fixture_setup.SnapcraftYaml(self.path)
snapcraft_yaml.update_part(
Expand Down Expand Up @@ -306,14 +341,15 @@ def test_prime_with_bzr_source(self):
self.init_source_control()
self.commit('"test-commit"', unchanged=True)

self.run_snapcraft("prime")
self.run_snapcraft(["snap", "--output", "bzr.snap"])

recorded_yaml_path = os.path.join(self.prime_dir, "snap", "manifest.yaml")
with open(recorded_yaml_path) as recorded_yaml_file:
recorded_yaml = yaml.load(recorded_yaml_file)

commit = self.get_revno()
self.assertThat(recorded_yaml["parts"]["bzr"]["source-commit"], Equals(commit))
self.assert_review_passes("bzr.snap")


class ManifestRecordingGitSourceTestCase(
Expand All @@ -325,14 +361,15 @@ def test_prime_with_git_source(self):
self.init_source_control()
self.commit('"test-commit"', allow_empty=True)

self.run_snapcraft("prime")
self.run_snapcraft(["snap", "--output", "git.snap"])

recorded_yaml_path = os.path.join(self.prime_dir, "snap", "manifest.yaml")
with open(recorded_yaml_path) as recorded_yaml_file:
recorded_yaml = yaml.load(recorded_yaml_file)

commit = self.get_revno()
self.assertThat(recorded_yaml["parts"]["git"]["source-commit"], Equals(commit))
self.assert_review_passes("git.snap")


class ManifestRecordingHgSourceTestCase(
Expand All @@ -345,7 +382,7 @@ def test_prime_with_hg_source(self):
open("1", "w").close()
self.commit("1", "1")

self.run_snapcraft("prime")
self.run_snapcraft(["snap", "--output", "hg.snap"])

recorded_yaml_path = os.path.join(self.prime_dir, "snap", "manifest.yaml")
with open(recorded_yaml_path) as recorded_yaml_file:
Expand All @@ -355,6 +392,7 @@ def test_prime_with_hg_source(self):
self.assertThat(
recorded_yaml["parts"]["mercurial"]["source-commit"], Equals(commit)
)
self.assert_review_passes("hg.snap")


class ManifestRecordingSubversionSourceTestCase(
Expand All @@ -372,10 +410,11 @@ def test_prime_with_subversion_source(self):
self.update(cwd="local/")
subprocess.check_call(["rm", "-rf", "local/"], stdout=subprocess.DEVNULL)

self.run_snapcraft("prime")
self.run_snapcraft(["snap", "--output", "svn.snap"])

recorded_yaml_path = os.path.join(self.prime_dir, "snap", "manifest.yaml")
with open(recorded_yaml_path) as recorded_yaml_file:
recorded_yaml = yaml.load(recorded_yaml_file)

self.assertThat(recorded_yaml["parts"]["svn"]["source-commit"], Equals("1"))
self.assert_review_passes("svn.snap")
25 changes: 25 additions & 0 deletions tests/integration/store/test_store_push.py
Expand Up @@ -18,6 +18,7 @@
import re
import subprocess

import fixtures
from testtools.matchers import FileExists, MatchesRegex

from tests import integration
Expand Down Expand Up @@ -60,6 +61,30 @@ def test_push_with_login(self):
expected = r".*Ready to release!.*".format(name)
self.assertThat(output, MatchesRegex(expected, flags=re.DOTALL))

def test_push_with_manifest(self):
# Make a snap
self.addCleanup(self.logout)
self.login()

# Change to a random name and version.
name = self.get_unique_name()
version = self.get_unique_version()
self.copy_project_to_cwd("basic")
self.update_name_and_version(name, version)

self.useFixture(fixtures.EnvironmentVariable("SNAPCRAFT_BUILD_INFO", "on"))
self.run_snapcraft("snap")

# Register the snap
self.register(name)
# Upload the snap
snap_file_path = "{}_{}_{}.snap".format(name, version, "all")
self.assertThat(os.path.join(snap_file_path), FileExists())

output = self.run_snapcraft(["push", snap_file_path])
expected = r".*Ready to release!.*".format(name)
self.assertThat(output, MatchesRegex(expected, flags=re.DOTALL))

def test_push_and_release(self):
# Make a snap
self.addCleanup(self.logout)
Expand Down