# Path: xmanager/cloud/cloud_build.py
# _CLOUD_BUILD_TIMEOUT_SECONDS = flags.DEFINE_integer(
#     'xm_cloud_build_timeout_seconds', 1200,
#     'The amount of time that builds should be allowed to run, '
#     'to second granularity.')
# _USE_CLOUD_BUILD_CACHE = flags.DEFINE_boolean(
#     'xm_use_cloud_build_cache',
#     False,
#     'Use Cloud Build cache to speed up the Docker build. '
#     'An image with the same name tagged as :latest should exist.'
#     'More details at https://cloud.google.com/cloud-build/docs/speeding-up-builds#using_a_cached_docker_image'  # pylint:disable=g-line-too-long
# )
# _USE_KANIKO = flags.DEFINE_boolean(
#     'xm_use_kaniko', False,
#     'Use kaniko backend for Cloud Build and enable caching.')
# _KANIKO_CACHE_TTL = flags.DEFINE_string('xm_kaniko_cache_ttl', '336h',
#                                         'Cache ttl to use for kaniko builds.')
# class Client:
#   def __init__(self,
#                project: Optional[str] = None,
#                bucket: Optional[str] = None,
#                credentials=None,
#                cloud_build_timeout_seconds: Optional[int] = None,
#                use_cloud_build_cache: Optional[bool] = None,
#                use_kaniko: Optional[bool] = None,
#                kaniko_cache_ttl: Optional[str] = None):
#   def upload_tar_to_storage(self, archive_path: str, destination_name: str):
#   def build_docker_image(self, image: str, directory: str,
#                          upload_name: str) -> str:
#   def _build_request_body(self, bucket_path, repository, tag) -> Dict[str, Any]:
#   def wait_for_build(self, build_id: str, kaniko_image: str) -> str:


from absl.testing import absltest
from xmanager.cloud import cloud_build

  def test_build_request_body_use_kaniko(self):
    client = cloud_build.Client(
        'my-project',
        'my-bucket',
        'fake-creds',
        use_kaniko=True,
        use_cloud_build_cache=False)
    image = client._build_request_body('path/to/project', 'my-image', 'live')
    self.assertEqual(
        image, {
            'source': {
                'storageSource': {
                    'bucket': 'my-bucket',
                    'object': 'path/to/project',
                },
            },
            'steps': [{
                'args': [
                    '--destination=my-image:live',
                    '--destination=my-image:latest',
                    '--cache=true',
                    '--cache-ttl=336h',
                ],
                'name': 'gcr.io/kaniko-project/executor:latest',
            }],
            'timeout': '1200s'
        })

  def test_build_request_body_use_build_cache(self):

# Path: xmanager/cloud/cloud_build.py
# _CLOUD_BUILD_TIMEOUT_SECONDS = flags.DEFINE_integer(
#     'xm_cloud_build_timeout_seconds', 1200,
#     'The amount of time that builds should be allowed to run, '
#     'to second granularity.')
# _USE_CLOUD_BUILD_CACHE = flags.DEFINE_boolean(
#     'xm_use_cloud_build_cache',
#     False,
#     'Use Cloud Build cache to speed up the Docker build. '
#     'An image with the same name tagged as :latest should exist.'
#     'More details at https://cloud.google.com/cloud-build/docs/speeding-up-builds#using_a_cached_docker_image'  # pylint:disable=g-line-too-long
# )
# _USE_KANIKO = flags.DEFINE_boolean(
#     'xm_use_kaniko', False,
#     'Use kaniko backend for Cloud Build and enable caching.')
# _KANIKO_CACHE_TTL = flags.DEFINE_string('xm_kaniko_cache_ttl', '336h',
#                                         'Cache ttl to use for kaniko builds.')
# class Client:
#   def __init__(self,
#                project: Optional[str] = None,
#                bucket: Optional[str] = None,
#                credentials=None,
#                cloud_build_timeout_seconds: Optional[int] = None,
#                use_cloud_build_cache: Optional[bool] = None,
#                use_kaniko: Optional[bool] = None,
#                kaniko_cache_ttl: Optional[str] = None):
#   def upload_tar_to_storage(self, archive_path: str, destination_name: str):
#   def build_docker_image(self, image: str, directory: str,
#                          upload_name: str) -> str:
#   def _build_request_body(self, bucket_path, repository, tag) -> Dict[str, Any]:
#   def wait_for_build(self, build_id: str, kaniko_image: str) -> str:


# Path: xmanager/cloud/cloud_build_test.py
from absl.testing import absltest
from xmanager.cloud import cloud_build


  def test_build_request_body_use_kaniko(self):
    client = cloud_build.Client(
        'my-project',
        'my-bucket',
        'fake-creds',
        use_kaniko=True,
        use_cloud_build_cache=False)
    image = client._build_request_body('path/to/project', 'my-image', 'live')
    self.assertEqual(
        image, {
            'source': {
                'storageSource': {
                    'bucket': 'my-bucket',
                    'object': 'path/to/project',
                },
            },
            'steps': [{
                'args': [
                    '--destination=my-image:live',
                    '--destination=my-image:latest',
                    '--cache=true',
                    '--cache-ttl=336h',
                ],
                'name': 'gcr.io/kaniko-project/executor:latest',
            }],
            'timeout': '1200s'
        })

  def test_build_request_body_use_build_cache(self):

    client = cloud_build.Client(