• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1# Copyright 2021 Google LLC
2#
3# Licensed under the Apache License, Version 2.0 (the "License");
4# you may not use this file except in compliance with the License.
5# You may obtain a copy of the License at
6#
7#      http://www.apache.org/licenses/LICENSE-2.0
8#
9# Unless required by applicable law or agreed to in writing, software
10# distributed under the License is distributed on an "AS IS" BASIS,
11# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12# See the License for the specific language governing permissions and
13# limitations under the License.
14"""Tests for filestore_utils."""
15import unittest
16from unittest import mock
17
18import parameterized
19
20import config_utils
21import filestore
22from filestore import github_actions
23import filestore_utils
24import test_helpers
25
26
27class GetFilestoreTest(unittest.TestCase):
28  """Tests for get_filestore."""
29
30  @parameterized.parameterized.expand([
31      ({
32          'is_github': True,
33      }, github_actions.GithubActionsFilestore),
34  ])
35  def test_get_filestore(self, config_kwargs, filestore_cls):
36    """Tests that get_filestore returns the right filestore given a certain
37    platform."""
38    run_config = test_helpers.create_run_config(**config_kwargs)
39    filestore_impl = filestore_utils.get_filestore(run_config)
40    self.assertIsInstance(filestore_impl, filestore_cls)
41
42  @mock.patch('config_utils.BaseConfig.platform', return_value='other')
43  @mock.patch('config_utils._get_ci_environment',
44              return_value=config_utils.GenericCiEnvironment())
45  def test_get_filestore_unsupported_platform(self, _, __):
46    """Tests that get_filestore exceptions given a platform it doesn't
47    support."""
48    run_config = test_helpers.create_run_config()
49    with self.assertRaises(filestore.FilestoreError):
50      filestore_utils.get_filestore(run_config)
51