예제 #1
0
class TestConan(unittest.TestCase):
    def setUp(self):
        self._repos = Repos()

    def _create_test_library(self):
        return self._repos.create_repo('lib').checkout('master')

    def _create_test_app(self):
        app_master = self._repos.create_repo('app').checkout('master')
        app_master.set_version('6.0.0')
        return app_master

    def _create_conan(self, output=NullOutput()):
        return Conan(output)

    def test_check_empty_requires(self):
        artifacts = {'lib': []}
        self._create_test_library()
        output = MagicMock()
        output.resolved = MagicMock()
        app_branch = self._create_test_app()
        resolved_packages, requires = self._create_conan(
            output).resolve_requires(artifacts, app_branch)
        self.assertIsNone(resolved_packages)
        self.assertIsNone(requires)

    def test_check_requires_resolve(self):
        artifacts = {'lib': ['1.2.3']}
        app_branch = self._create_test_app()
        app_branch.set_requires('lib/1.x')
        resolved_packages, requires = self._create_conan().resolve_requires(
            artifacts, app_branch)
        self.assertEqual('lib/1.2.3', resolved_packages)
        self.assertEqual(('lib', '1.x'), requires)

    def test_check_requires_unresolved(self):
        artifacts = {'lib': ['2.2.3']}
        app_branch = self._create_test_app()
        app_branch.set_requires('lib/1.x')
        resolved_packages, requires = self._create_conan().resolve_requires(
            artifacts, app_branch)
        self.assertIsNone(resolved_packages)
        self.assertEqual(('lib', '1.x'), requires)

    def test_check_requires_requires_syntax_error(self):
        lib = self._repos.create_repo('lib')
        branch = lib.checkout('master')
        branch.set_requires('invalid | format')
        conan = self._create_conan()
        self.assertRaises(Exception, lambda: conan._determine_requires(branch))

    def test_conan_install(self):
        app_branch = self._create_test_app()
        app_branch.set_requires('lib/2.x')
        artifacts = {'lib': ['2.0.3']}

        output = MagicMock()
        self._create_conan(output).install(app_branch, artifacts)
        output.installing.assert_called_once()
        output.installing.assert_called_with(ANY, 'lib/2.0.3')
예제 #2
0
def test_conan_install_parametrized(require_version, versions,
                                    expected_version):
    app_branch = Repos().create_repo('lib').checkout('master')
    app_branch.set_requires(require_version)
    artifacts = {'lib': versions}

    output = MagicMock()
    Conan(output).install(app_branch, artifacts)
    output.installing.assert_called_once()
    output.installing.assert_called_with(ANY, expected_version)
예제 #3
0
class TestGitRepos(unittest.TestCase):
    def setUp(self):
        self._repos = Repos()

    def test_create_repo(self):
        repo = self._repos.create_repo("ProjectName")
        self.assertIn(repo, self._repos.get_repos())

    def test_no_repos_after_creation(self):
        self.assertEqual(0, len(self._repos.get_repos()))

    def test_create_two_repos(self):
        repo1 = self._repos.create_repo("Prj1")
        repo2 = self._repos.create_repo("Prj2")
        self.assertIn(repo1, self._repos.get_repos())
        self.assertIn(repo2, self._repos.get_repos())

    def test_create_repo_that_already_exists__expect__return_existing(self):
        repo1 = self._repos.create_repo('repo')
        repo2 = self._repos.create_repo('repo')
        self.assertEqual(repo1, repo2)
예제 #4
0
 def _create_repo(self, buildmachine):
     repos = Repos()
     repos.set_buildmachine(buildmachine)
     return repos.create_repo(self._project_name)
예제 #5
0
 def setUp(self):
     self._repos = Repos()
예제 #6
0
 def setUp(self):
     self._repos = Repos()
     self._repo = self._repos.create_repo('theRepo')
     self._build_id_generator = BuildIdGenerator()
예제 #7
0
class TestJenkins(unittest.TestCase):
    def setUp(self):
        self._repos = Repos()
        self._repo = self._repos.create_repo('theRepo')
        self._build_id_generator = BuildIdGenerator()

    def _create_jenkins(self, artifactory=Artifactory()):
        return Jenkins(
            artifactory, self._repos,
            {'build_strategy': BuildStrategyA(self._build_id_generator)})

    def _create_jenkins_artifactory_mock(self):
        self._mock_artifactory = Artifactory()
        self._mock_artifactory.publish = MagicMock()
        return self._create_jenkins(self._mock_artifactory)

    def _get_or_create_branch(self, branch_name, version, requires=''):
        branch = self._repo.checkout(branch_name)
        branch.set_version(version)
        branch.set_requires(requires)
        return branch

    def test_build_develop(self):
        self._build_id_generator.generate_id = MagicMock(
            return_value="theBuildId")
        branch = self._get_or_create_branch('develop', '1.2.3')
        branch.get_commit_sha = MagicMock(return_value="0000000")
        jenkins = self._create_jenkins_artifactory_mock()
        jenkins.build(branch)
        self._mock_artifactory.publish.assert_called_with(
            'theRepo', '1.2.3-theBuildId+0000000')

    def test_build_release(self):
        self._build_id_generator.generate_id = MagicMock(
            return_value="theBuildId")
        branch = self._get_or_create_branch('release/1.2', '1.2.3')
        branch.get_commit_sha = MagicMock(return_value="0000000")
        jenkins = self._create_jenkins_artifactory_mock()
        jenkins.build(branch)
        self._mock_artifactory.publish.assert_called_with(
            'theRepo', '1.2.3-rc.theBuildId+0000000')

    def test_build_master(self):
        self._build_id_generator.generate_id = MagicMock(
            return_value="theBuildId")
        branch = self._get_or_create_branch('master', '1.2.3')
        branch.get_commit_sha = MagicMock(return_value="0000000")
        jenkins = self._create_jenkins_artifactory_mock()
        jenkins.build(branch)
        self._mock_artifactory.publish.assert_called_with('theRepo', '1.2.3')

    def test_build_feature_a__assume_not_published(self):
        self._build_id_generator.generate_id = MagicMock(
            return_value="theBuildId")
        branch = self._get_or_create_branch('feature/a', '1.2.3')
        branch.get_commit_sha = MagicMock(return_value="0000000")
        jenkins = self._create_jenkins_artifactory_mock()
        jenkins.build(branch)
        self._mock_artifactory.publish.assert_not_called()

    def test_build_hotfix_1_2_4(self):
        self._build_id_generator.generate_id = MagicMock(
            return_value="theBuildId")
        branch = self._get_or_create_branch('hotfix/a', '1.2.4')
        branch.get_commit_sha = MagicMock(return_value="0000000")
        jenkins = self._create_jenkins_artifactory_mock()
        jenkins.build(branch)
        self._mock_artifactory.publish.assert_called_with(
            'theRepo', '1.2.4-rc.theBuildId+0000000')

    def test_build_support_1_2(self):
        self._build_id_generator.generate_id = MagicMock(
            return_value="theBuildId")
        branch = self._get_or_create_branch('support/1.2', '1.2.5')
        branch.get_commit_sha = MagicMock(return_value="0000000")
        jenkins = self._create_jenkins_artifactory_mock()
        jenkins.build(branch)
        self._mock_artifactory.publish.assert_called_with('theRepo', '1.2.5')

    def test_build__build_same_lib_twice__expect_app_rebuild(self):
        artifactory = Artifactory()
        jenkins = self._create_jenkins(artifactory)

        lib_repo = self._repos.create_repo('lib')
        lib_dev = lib_repo.checkout('develop')
        lib_dev.set_version('1.0.1')
        lib_dev.push()

        app_repo = self._repos.create_repo('app')
        app = app_repo.checkout('develop')
        app.set_version('1.0.1')
        app.set_requires('lib/1.x')
        app.push()

        # Expect a rebuild of 'app' because a new artifact for 'lib' will be created
        self.assertEqual(1, len(artifactory.get_artifacts()['app']))
        lib_dev.push()
        self.assertEqual(2, len(artifactory.get_artifacts()['app']))

    def test_push_app__before_lib_available__conan_install_should_fail(self):
        jenkins = self._create_jenkins()

        lib_repo = self._repos.create_repo('lib')
        lib_repo.checkout('master').set_version('1.0.1')

        app_repo = self._repos.create_repo('app')
        app = app_repo.checkout('master')
        app.set_version('1.0.1')
        app.set_requires('lib/1.x')
        # conan install should fail with exception
        self.assertRaises(Exception, lambda: app.push())