Mike Frysinger | f1ba7ad | 2022-09-12 05:42:57 -0400 | [diff] [blame] | 1 | # Copyright 2021 The ChromiumOS Authors |
Alex Klein | 3970133 | 2021-02-24 14:34:58 -0700 | [diff] [blame] | 2 | # Use of this source code is governed by a BSD-style license that can be |
| 3 | # found in the LICENSE file. |
| 4 | |
| 5 | """compile_build_api_proto tests.""" |
| 6 | |
Alex Klein | 9ea00b5 | 2021-02-24 14:47:22 -0700 | [diff] [blame] | 7 | import os |
| 8 | |
Mike Frysinger | 2c02406 | 2021-05-22 15:43:22 -0400 | [diff] [blame] | 9 | from chromite.third_party.google import protobuf |
Mike Frysinger | 1cc8f1f | 2022-04-28 22:40:40 -0400 | [diff] [blame] | 10 | |
Alex Klein | 3970133 | 2021-02-24 14:34:58 -0700 | [diff] [blame] | 11 | from chromite.api import compile_build_api_proto |
| 12 | |
| 13 | |
| 14 | def test_versions_match(): |
Alex Klein | 1699fab | 2022-09-08 08:46:06 -0600 | [diff] [blame] | 15 | """Verify the versions match. |
Alex Klein | 3970133 | 2021-02-24 14:34:58 -0700 | [diff] [blame] | 16 | |
Alex Klein | 1699fab | 2022-09-08 08:46:06 -0600 | [diff] [blame] | 17 | The protoc version in the compile script needs to be compatible with the |
| 18 | version of the library we're using (in chromite/third_party). For now, that |
| 19 | means we're checking equality. |
Alex Klein | 3970133 | 2021-02-24 14:34:58 -0700 | [diff] [blame] | 20 | |
Alex Klein | 54c891a | 2023-01-24 10:45:41 -0700 | [diff] [blame] | 21 | TODO: Investigate whether, e.g. 1.2.0 ~= 1.2.3, and we only need to check |
| 22 | the major and minor components. |
| 23 | TODO: Investigate using protobuf.__version__ instead of hard coding a |
| 24 | version in compile_build_api_proto. |
Alex Klein | 1699fab | 2022-09-08 08:46:06 -0600 | [diff] [blame] | 25 | """ |
Aaron Massey | ee4555c | 2023-07-27 22:39:57 +0000 | [diff] [blame^] | 26 | assert compile_build_api_proto.PROTOC_VERSION == protobuf.__version__, ( |
Alex Klein | 54c891a | 2023-01-24 10:45:41 -0700 | [diff] [blame] | 27 | "The protobuf library or compile_build_api_proto.PROTOC_VERSION has " |
| 28 | "been updated, but the other has not. They must be updated together." |
Alex Klein | 1699fab | 2022-09-08 08:46:06 -0600 | [diff] [blame] | 29 | ) |
Alex Klein | 9ea00b5 | 2021-02-24 14:47:22 -0700 | [diff] [blame] | 30 | |
| 31 | |
| 32 | def test_compiles(tmpdir): |
Alex Klein | 1699fab | 2022-09-08 08:46:06 -0600 | [diff] [blame] | 33 | """Test the script successfully compiles something.""" |
| 34 | assert not os.listdir(tmpdir) |
| 35 | compile_build_api_proto.main(["--destination", str(tmpdir)]) |
| 36 | # It may produce an __init__.py even if nothing else succeeded, so make sure |
| 37 | # we have more than just that. |
| 38 | assert len(os.listdir(tmpdir)) > 1 |