blob: 7bf08eed01ee8a34fc6c106d75bb30e8480a5a68 [file] [log] [blame]
Antoine Mussobfd8f2a2014-09-23 15:31:40 +02001#!/usr/bin/env python
2
3# Copyright 2012 Hewlett-Packard Development Company, L.P.
4# Copyright 2014 Wikimedia Foundation Inc.
5#
6# Licensed under the Apache License, Version 2.0 (the "License"); you may
7# not use this file except in compliance with the License. You may obtain
8# a copy of the License at
9#
10# http://www.apache.org/licenses/LICENSE-2.0
11#
12# Unless required by applicable law or agreed to in writing, software
13# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
14# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
15# License for the specific language governing permissions and limitations
16# under the License.
17
18import logging
19import os
20
21import git
22
23from zuul.merger.merger import Repo
24from tests.base import ZuulTestCase
25
26logging.basicConfig(level=logging.DEBUG,
27 format='%(asctime)s %(name)-32s '
28 '%(levelname)-8s %(message)s')
29
30
31class TestMergerRepo(ZuulTestCase):
32
33 log = logging.getLogger("zuul.test.merger.repo")
34 workspace_root = None
35
36 def setUp(self):
James E. Blair83005782015-12-11 14:46:03 -080037 self.skip("Disabled for early v3 development")
38
39 # def setUp(self):
40 # super(TestMergerRepo, self).setUp()
41 # self.workspace_root = os.path.join(self.test_root, 'workspace')
Antoine Mussobfd8f2a2014-09-23 15:31:40 +020042
43 def test_ensure_cloned(self):
44 parent_path = os.path.join(self.upstream_root, 'org/project1')
45
46 # Forge a repo having a submodule
47 parent_repo = git.Repo(parent_path)
48 parent_repo.git.submodule('add', os.path.join(
49 self.upstream_root, 'org/project2'), 'subdir')
50 parent_repo.index.commit('Adding project2 as a submodule in subdir')
51 # git 1.7.8 changed .git from being a directory to a file pointing
52 # to the parent repository /.git/modules/*
53 self.assertTrue(os.path.exists(
54 os.path.join(parent_path, 'subdir', '.git')),
55 msg='.git file in submodule should be a file')
56
57 work_repo = Repo(parent_path, self.workspace_root,
58 'none@example.org', 'User Name')
59 self.assertTrue(
60 os.path.isdir(os.path.join(self.workspace_root, 'subdir')),
61 msg='Cloned repository has a submodule placeholder directory')
62 self.assertFalse(os.path.exists(
63 os.path.join(self.workspace_root, 'subdir', '.git')),
64 msg='Submodule is not initialized')
65
66 sub_repo = Repo(
67 os.path.join(self.upstream_root, 'org/project2'),
68 os.path.join(self.workspace_root, 'subdir'),
69 'none@example.org', 'User Name')
70 self.assertTrue(os.path.exists(
71 os.path.join(self.workspace_root, 'subdir', '.git')),
72 msg='Cloned over the submodule placeholder')
73
74 self.assertEquals(
75 os.path.join(self.upstream_root, 'org/project1'),
76 work_repo.createRepoObject().remotes[0].url,
77 message="Parent clone still point to upstream project1")
78
79 self.assertEquals(
80 os.path.join(self.upstream_root, 'org/project2'),
81 sub_repo.createRepoObject().remotes[0].url,
82 message="Sub repository points to upstream project2")