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# 15################################################################################ 16"""Unit tests for build_project.""" 17import json 18import os 19import sys 20import unittest 21from unittest import mock 22 23from pyfakefs import fake_filesystem_unittest 24 25FUNCTIONS_DIR = os.path.dirname(__file__) 26sys.path.append(FUNCTIONS_DIR) 27# pylint: disable=wrong-import-position 28 29import build_project 30import test_utils 31 32# pylint: disable=no-member 33 34 35class TestRequestCoverageBuilds(fake_filesystem_unittest.TestCase): 36 """Unit tests for sync.""" 37 38 def setUp(self): 39 self.maxDiff = None # pylint: disable=invalid-name 40 self.setUpPyfakefs() 41 42 @mock.patch('build_lib.get_signed_url', return_value='test_url') 43 @mock.patch('build_project.get_datetime_now', 44 return_value=test_utils.FAKE_DATETIME) 45 def test_get_build_steps(self, mock_url, mock_get_datetime_now): 46 """Test for get_build_steps.""" 47 del mock_url, mock_get_datetime_now 48 project_yaml_contents = ('language: c++\n' 49 'sanitizers:\n' 50 ' - address\n' 51 ' - memory\n' 52 ' - undefined\n' 53 'architectures:\n' 54 ' - x86_64\n' 55 ' - i386\n') 56 self.fs.create_dir(test_utils.PROJECT_DIR) 57 test_utils.create_project_data(test_utils.PROJECT, project_yaml_contents) 58 59 expected_build_steps_file_path = test_utils.get_test_data_file_path( 60 'expected_build_steps.json') 61 self.fs.add_real_file(expected_build_steps_file_path) 62 with open(expected_build_steps_file_path) as expected_build_steps_file: 63 expected_build_steps = json.load(expected_build_steps_file) 64 65 config = build_project.Config(False, False, None, False) 66 project_yaml, dockerfile = build_project.get_project_data( 67 test_utils.PROJECT) 68 build_steps = build_project.get_build_steps(test_utils.PROJECT, 69 project_yaml, dockerfile, 70 test_utils.IMAGE_PROJECT, 71 test_utils.BASE_IMAGES_PROJECT, 72 config) 73 self.assertEqual(build_steps, expected_build_steps) 74 75 76if __name__ == '__main__': 77 unittest.main(exit=False) 78