diff options
author | Dan Albert <danalbert@google.com> | 2024-02-08 22:15:31 +0000 |
---|---|---|
committer | Dan Albert <danalbert@google.com> | 2024-02-08 22:15:31 +0000 |
commit | 08cf75a72fd9e904be9b79a47a0e1b2155920096 (patch) | |
tree | feb2a562814b399fd6ab237bbc41d6d2ec21182c | |
parent | 3e651c3b11c7dae6ba89152d536178cc435d1a89 (diff) | |
download | external_updater-08cf75a72fd9e904be9b79a47a0e1b2155920096.tar.gz |
Add a test for Updater.current_version.
We don't have any tests that actually cover a protobuf involved thing
yet. This one's trivial, but shows how to do it.
Bug: None
Test: atest --host-unit-test-only
Change-Id: I6eb6ccd43663ec77af6ee38298b759a7f4eab8ac
-rw-r--r-- | Android.bp | 17 | ||||
-rw-r--r-- | test_base_updater.py | 56 |
2 files changed, 73 insertions, 0 deletions
@@ -138,6 +138,23 @@ python_test_host { }, } +// This test is intentionally not in the tests/ directory. Everything in the +// tests/ directory should be runnable with pytest, and this file is not because +// it depends on the generated protobuf modules. +python_test_host { + name: "external_updater_base_updater_test", + defaults: ["external_updater_test_defaults"], + main: "test_base_updater.py", + srcs: ["test_base_updater.py"], + libs: [ + "external_updater_lib", + "external_updater_test_lib", + ], + test_options: { + unit_test: true, + }, +} + // The tests in tests/endtoend are not built as a Soong module because we can't // run those tests via python_test_host. It's an end-to-end test so it needs to // run `repo`, but `repo init` will try to clone the real repo source (the thing diff --git a/test_base_updater.py b/test_base_updater.py new file mode 100644 index 0000000..e930a35 --- /dev/null +++ b/test_base_updater.py @@ -0,0 +1,56 @@ +# +# Copyright (C) 2024 The Android Open Source Project +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +# +"""Unit tests for base_updater.""" + +import unittest +from pathlib import Path + +import base_updater +# pylint: disable=import-error +import metadata_pb2 # type: ignore +# pylint: enable=import-error + + +class UpdaterTest(unittest.TestCase): + """Unit tests for Updater.""" + + def test_current_version(self) -> None: + """Tests that Updater.current_version returns the appropriate value.""" + updater = base_updater.Updater( + # This is absolute so we get the fast path out of the path canonicalization + # that would otherwise require us to define ANDROID_BUILD_TOP or run from a + # temp repo tree. + Path("/"), + metadata_pb2.Identifier(), + "old version", + ) + self.assertEqual(updater.current_version, "old version") + + identifier = metadata_pb2.Identifier() + identifier.version = "old version" + updater = base_updater.Updater( + # This is absolute so we get the fast path out of the path canonicalization + # that would otherwise require us to define ANDROID_BUILD_TOP or run from a + # temp repo tree. + Path("/"), + identifier, + "", + ) + self.assertEqual(updater.current_version, "old version") + + +if __name__ == "__main__": + unittest.main(verbosity=2) |