blob: db61d530967c20d57b9a8d893910e5a537ae9d96 [file] [log] [blame]
Mike Frysingerf1ba7ad2022-09-12 05:42:57 -04001# Copyright 2021 The ChromiumOS Authors
Alex Klein39701332021-02-24 14:34:58 -07002# 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 Klein9ea00b52021-02-24 14:47:22 -07007import os
8
Mike Frysinger2c024062021-05-22 15:43:22 -04009from chromite.third_party.google import protobuf
Mike Frysinger1cc8f1f2022-04-28 22:40:40 -040010
Alex Klein39701332021-02-24 14:34:58 -070011from chromite.api import compile_build_api_proto
12
13
14def test_versions_match():
Alex Klein1699fab2022-09-08 08:46:06 -060015 """Verify the versions match.
Alex Klein39701332021-02-24 14:34:58 -070016
Alex Klein1699fab2022-09-08 08:46:06 -060017 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 Klein39701332021-02-24 14:34:58 -070020
Alex Klein54c891a2023-01-24 10:45:41 -070021 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 Klein1699fab2022-09-08 08:46:06 -060025 """
Trent Apted5a2038f2023-07-26 15:23:46 +100026 assert (
27 f"{compile_build_api_proto.PROTOC_MAJOR_VERSION}."
28 f"{compile_build_api_proto.PROTOC_VERSION}"
29 ) == protobuf.__version__, (
Alex Klein54c891a2023-01-24 10:45:41 -070030 "The protobuf library or compile_build_api_proto.PROTOC_VERSION has "
31 "been updated, but the other has not. They must be updated together."
Alex Klein1699fab2022-09-08 08:46:06 -060032 )
Alex Klein9ea00b52021-02-24 14:47:22 -070033
34
35def test_compiles(tmpdir):
Alex Klein1699fab2022-09-08 08:46:06 -060036 """Test the script successfully compiles something."""
37 assert not os.listdir(tmpdir)
38 compile_build_api_proto.main(["--destination", str(tmpdir)])
39 # It may produce an __init__.py even if nothing else succeeded, so make sure
40 # we have more than just that.
41 assert len(os.listdir(tmpdir)) > 1