2021-06-21 15:28:21 +00:00
|
|
|
# Copyright 2021 Google LLC
|
|
|
|
#
|
|
|
|
# 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.
|
|
|
|
"""Tests for filestore_utils."""
|
|
|
|
import unittest
|
|
|
|
from unittest import mock
|
|
|
|
|
|
|
|
import parameterized
|
|
|
|
|
2021-11-01 12:29:38 +00:00
|
|
|
import platform_config
|
2021-06-21 15:28:21 +00:00
|
|
|
import filestore
|
|
|
|
from filestore import github_actions
|
|
|
|
import filestore_utils
|
|
|
|
import test_helpers
|
|
|
|
|
|
|
|
|
|
|
|
class GetFilestoreTest(unittest.TestCase):
|
|
|
|
"""Tests for get_filestore."""
|
|
|
|
|
|
|
|
@parameterized.parameterized.expand([
|
|
|
|
({
|
2021-11-01 12:29:38 +00:00
|
|
|
'cfl_platform': 'github',
|
2021-06-21 15:28:21 +00:00
|
|
|
}, github_actions.GithubActionsFilestore),
|
|
|
|
])
|
|
|
|
def test_get_filestore(self, config_kwargs, filestore_cls):
|
|
|
|
"""Tests that get_filestore returns the right filestore given a certain
|
|
|
|
platform."""
|
|
|
|
run_config = test_helpers.create_run_config(**config_kwargs)
|
|
|
|
filestore_impl = filestore_utils.get_filestore(run_config)
|
|
|
|
self.assertIsInstance(filestore_impl, filestore_cls)
|
|
|
|
|
2021-08-04 01:13:59 +00:00
|
|
|
@mock.patch('config_utils.BaseConfig.platform', return_value='other')
|
2021-11-01 12:29:38 +00:00
|
|
|
@mock.patch('config_utils._get_platform_config',
|
|
|
|
return_value=platform_config.BasePlatformConfig())
|
2021-08-04 01:13:59 +00:00
|
|
|
def test_get_filestore_unsupported_platform(self, _, __):
|
2021-06-21 15:28:21 +00:00
|
|
|
"""Tests that get_filestore exceptions given a platform it doesn't
|
|
|
|
support."""
|
2021-08-04 01:13:59 +00:00
|
|
|
run_config = test_helpers.create_run_config()
|
|
|
|
with self.assertRaises(filestore.FilestoreError):
|
|
|
|
filestore_utils.get_filestore(run_config)
|