xref: /aosp_15_r20/tools/external_updater/test_base_updater.py (revision 3c875a214f382db1236d28570d1304ce57138f32)
1*3c875a21SAndroid Build Coastguard Worker#
2*3c875a21SAndroid Build Coastguard Worker# Copyright (C) 2024 The Android Open Source Project
3*3c875a21SAndroid Build Coastguard Worker#
4*3c875a21SAndroid Build Coastguard Worker# Licensed under the Apache License, Version 2.0 (the "License");
5*3c875a21SAndroid Build Coastguard Worker# you may not use this file except in compliance with the License.
6*3c875a21SAndroid Build Coastguard Worker# You may obtain a copy of the License at
7*3c875a21SAndroid Build Coastguard Worker#
8*3c875a21SAndroid Build Coastguard Worker#      http://www.apache.org/licenses/LICENSE-2.0
9*3c875a21SAndroid Build Coastguard Worker#
10*3c875a21SAndroid Build Coastguard Worker# Unless required by applicable law or agreed to in writing, software
11*3c875a21SAndroid Build Coastguard Worker# distributed under the License is distributed on an "AS IS" BASIS,
12*3c875a21SAndroid Build Coastguard Worker# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13*3c875a21SAndroid Build Coastguard Worker# See the License for the specific language governing permissions and
14*3c875a21SAndroid Build Coastguard Worker# limitations under the License.
15*3c875a21SAndroid Build Coastguard Worker#
16*3c875a21SAndroid Build Coastguard Worker"""Unit tests for base_updater."""
17*3c875a21SAndroid Build Coastguard Worker
18*3c875a21SAndroid Build Coastguard Workerimport unittest
19*3c875a21SAndroid Build Coastguard Workerfrom pathlib import Path
20*3c875a21SAndroid Build Coastguard Worker
21*3c875a21SAndroid Build Coastguard Workerimport base_updater
22*3c875a21SAndroid Build Coastguard Worker# pylint: disable=import-error
23*3c875a21SAndroid Build Coastguard Workerimport metadata_pb2  # type: ignore
24*3c875a21SAndroid Build Coastguard Worker# pylint: enable=import-error
25*3c875a21SAndroid Build Coastguard Worker
26*3c875a21SAndroid Build Coastguard Worker
27*3c875a21SAndroid Build Coastguard Workerclass UpdaterTest(unittest.TestCase):
28*3c875a21SAndroid Build Coastguard Worker    """Unit tests for Updater."""
29*3c875a21SAndroid Build Coastguard Worker
30*3c875a21SAndroid Build Coastguard Worker    def test_current_version(self) -> None:
31*3c875a21SAndroid Build Coastguard Worker        """Tests that Updater.current_version returns the appropriate value."""
32*3c875a21SAndroid Build Coastguard Worker        updater = base_updater.Updater(
33*3c875a21SAndroid Build Coastguard Worker            # This is absolute so we get the fast path out of the path canonicalization
34*3c875a21SAndroid Build Coastguard Worker            # that would otherwise require us to define ANDROID_BUILD_TOP or run from a
35*3c875a21SAndroid Build Coastguard Worker            # temp repo tree.
36*3c875a21SAndroid Build Coastguard Worker            Path("/"),
37*3c875a21SAndroid Build Coastguard Worker            metadata_pb2.Identifier(),
38*3c875a21SAndroid Build Coastguard Worker            "old version",
39*3c875a21SAndroid Build Coastguard Worker        )
40*3c875a21SAndroid Build Coastguard Worker        self.assertEqual(updater.current_version, "old version")
41*3c875a21SAndroid Build Coastguard Worker
42*3c875a21SAndroid Build Coastguard Worker        identifier = metadata_pb2.Identifier()
43*3c875a21SAndroid Build Coastguard Worker        identifier.version = "old version"
44*3c875a21SAndroid Build Coastguard Worker        updater = base_updater.Updater(
45*3c875a21SAndroid Build Coastguard Worker            # This is absolute so we get the fast path out of the path canonicalization
46*3c875a21SAndroid Build Coastguard Worker            # that would otherwise require us to define ANDROID_BUILD_TOP or run from a
47*3c875a21SAndroid Build Coastguard Worker            # temp repo tree.
48*3c875a21SAndroid Build Coastguard Worker            Path("/"),
49*3c875a21SAndroid Build Coastguard Worker            identifier,
50*3c875a21SAndroid Build Coastguard Worker            "",
51*3c875a21SAndroid Build Coastguard Worker        )
52*3c875a21SAndroid Build Coastguard Worker        self.assertEqual(updater.current_version, "old version")
53*3c875a21SAndroid Build Coastguard Worker
54*3c875a21SAndroid Build Coastguard Worker
55*3c875a21SAndroid Build Coastguard Workerif __name__ == "__main__":
56*3c875a21SAndroid Build Coastguard Worker    unittest.main(verbosity=2)
57