| 1 |
# This Source Code Form is subject to the terms of the Mozilla Public |
| 2 |
# License, v. 2.0. If a copy of the MPL was not distributed with this |
| 3 |
# file, You can obtain one at http://mozilla.org/MPL/2.0/. |
| 4 |
|
| 5 |
from unittest import mock |
| 6 |
|
| 7 |
import mozunit |
| 8 |
import pytest |
| 9 |
|
| 10 |
from mozversioncontrol import get_repository_object |
| 11 |
|
| 12 |
STEPS = { |
| 13 |
"hg": [], |
| 14 |
"git": [ |
| 15 |
"git remote add blah https://example.com/blah", |
| 16 |
""" |
| 17 |
git remote add unified hg::https://hg.mozilla.org/mozilla-unified |
| 18 |
git remote add central hg::https://hg.mozilla.org/central |
| 19 |
git remote add try hg::https://hg.mozilla.org/try |
| 20 |
git remote add firefox https://github.com/mozilla-firefox/firefox |
| 21 |
""", |
| 22 |
], |
| 23 |
"jj": [], |
| 24 |
} |
| 25 |
|
| 26 |
|
| 27 |
@pytest.mark.parametrize( |
| 28 |
"is_cinnabar,expected_remotes", |
| 29 |
( |
| 30 |
( |
| 31 |
True, |
| 32 |
[ |
| 33 |
"central", |
| 34 |
"unified", |
| 35 |
], |
| 36 |
), |
| 37 |
(False, ["firefox"]), |
| 38 |
), |
| 39 |
) |
| 40 |
def test_get_upstream_remotes(is_cinnabar, expected_remotes, repo): |
| 41 |
# Test is only relevant for Git. |
| 42 |
if not repo.vcs == "git": |
| 43 |
return |
| 44 |
|
| 45 |
repo.execute_next_step() |
| 46 |
|
| 47 |
vcs = get_repository_object(repo.dir) |
| 48 |
vcs.is_cinnabar_repo = mock.MagicMock(name="is_cinnabar_repo") |
| 49 |
vcs.is_cinnabar_repo.return_value = is_cinnabar |
| 50 |
|
| 51 |
remotes = vcs.get_mozilla_upstream_remotes() |
| 52 |
|
| 53 |
assert list(remotes) == [], "No official remotes should be found." |
| 54 |
|
| 55 |
repo.execute_next_step() |
| 56 |
|
| 57 |
remotes = sorted(list(vcs.get_mozilla_upstream_remotes())) |
| 58 |
|
| 59 |
assert remotes == expected_remotes, "Multiple non-try remotes should be found." |
| 60 |
|
| 61 |
|
| 62 |
if __name__ == "__main__": |
| 63 |
mozunit.main() |