1# 2# Copyright (C) 2023 The Android Open Source Project 3# 4# Licensed under the Apache License, Version 2.0 (the "License"); 5# you may not use this file except in compliance with the License. 6# You may obtain a copy of the License at 7# 8# http://www.apache.org/licenses/LICENSE-2.0 9# 10# Unless required by applicable law or agreed to in writing, software 11# distributed under the License is distributed on an "AS IS" BASIS, 12# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13# See the License for the specific language governing permissions and 14# limitations under the License. 15# 16"""Tests for fakeproject.""" 17from pathlib import Path 18 19from .fakeproject import FakeProject 20 21 22class TestFakeProject: 23 """Tests for fakeproject.FakeProject.""" 24 25 def test_constructor_initializes_upstream_repo(self, tmp_path: Path) -> None: 26 """Tests that the constructor initializes the "upstream" git repo.""" 27 project = FakeProject( 28 tmp_path / "local", tmp_path / "upstream", tmp_path / "mirror" 29 ) 30 assert ( 31 project.upstream.commit_message_at_revision("HEAD") == "Initial commit.\n" 32 ) 33 34 def test_initial_import(self, tmp_path: Path) -> None: 35 """Tests that initial_import merges and creates metadata files.""" 36 project = FakeProject( 37 tmp_path / "local", tmp_path / "upstream", tmp_path / "mirror" 38 ) 39 project.upstream.commit( 40 "Add README.md.", update_files={"README.md": "Hello, world!"} 41 ) 42 43 upstream_sha = project.upstream.head() 44 project.initial_import() 45 46 # The import is done in the mirror repository. The cloned repository in the repo 47 # tree should not be created until init_and_sync() is called. 48 assert not project.local.path.exists() 49 50 assert ( 51 project.android_mirror.commit_message_at_revision("HEAD^") 52 == f"Merge {project.upstream.path}\n" 53 ) 54 assert ( 55 project.android_mirror.commit_message_at_revision("HEAD") 56 == "Add metadata files.\n" 57 ) 58 metadata = project.android_mirror.file_contents_at_revision("HEAD", "METADATA") 59 assert 'type: "GIT"' in metadata 60 assert f'value: "{project.upstream.path.as_uri()}"' in metadata 61 assert f'version: "{upstream_sha}"' in metadata 62