scripts: upload_prebuilts: sync remote SDK file
Oops, I accidentally merged a bug one month ago, and now the remote
SDK file is a month stale. See attached bug for details. The correct
behavior is to sync the remote file unless we specify not to.
Also added test coverage.
BUG=b:280879394
TEST=./run_tests
Change-Id: I3c91c70a1540e4129c0992e09d9289f8ea0c3087
Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/chromite/+/4505917
Auto-Submit: Greg Edelston <gredelston@google.com>
Tested-by: Greg Edelston <gredelston@google.com>
Reviewed-by: Jack Rosenthal <jrosenth@chromium.org>
Commit-Queue: Jack Rosenthal <jrosenth@chromium.org>
diff --git a/scripts/upload_prebuilts_unittest.py b/scripts/upload_prebuilts_unittest.py
index dc67119..503cc99 100644
--- a/scripts/upload_prebuilts_unittest.py
+++ b/scripts/upload_prebuilts_unittest.py
@@ -7,8 +7,11 @@
import copy
import multiprocessing
import os
+from typing import List
from unittest import mock
+import pytest
+
from chromite.lib import binpkg
from chromite.lib import cros_test_lib
from chromite.lib import gs
@@ -786,3 +789,47 @@
self.testSdkUpload(
tc_tarballs=tc_tarballs, tc_upload_path=tc_upload_path
)
+
+
+@pytest.mark.parametrize(
+ "extra_args,expected_sync",
+ [
+ ([], True),
+ (["--sync-remote-latest-sdk-file"], True),
+ (["--no-sync-remote-latest-sdk-file"], False),
+ (
+ [
+ "--no-sync-remote-latest-sdk-file",
+ "--sync-remote-latest-sdk-file",
+ ],
+ True,
+ ),
+ (
+ [
+ "--sync-remote-latest-sdk-file",
+ "--no-sync-remote-latest-sdk-file",
+ ],
+ False,
+ ),
+ ],
+)
+def test_parse_options_sync_remote_latest_file(
+ extra_args: List[str],
+ expected_sync: bool,
+):
+ """Test --sync-remote-latest-file and --no-sync-remote-latest-file.
+
+ Desired behavior:
+ * If either of those args is given, take the last one.
+ * If neither is given, default to True.
+
+ Args:
+ extra_args: Command-line args to pass into parse_options() besides the
+ bare minimum.
+ expected_sync: Whether options.sync_remote_latest_file should be True.
+ """
+ # Bare minimum args to run upload_prebuilts
+ args = ["--build-path", "/foo", "-u", "gs://foo/bar"]
+ args.extend(extra_args)
+ options, _ = prebuilt.ParseOptions(args)
+ assert options.sync_remote_latest_sdk_file == expected_sync