def test_get_projects_yaml(self): """Testing get_projects() yaml get_schedule().""" repo = Repository('oss-fuzz', 'dir', 'projects', [ Repository('test0', 'dir', 'projects/test0', [ Repository('Dockerfile', 'file', 'projects/test0/Dockerfile'), Repository('project.yaml', 'file', 'projects/test0/project.yaml') ]), Repository('test1', 'dir', 'projects/test1', [ Repository('Dockerfile', 'file', 'projects/test1/Dockerfile'), Repository('project.yaml', 'file', 'projects/test1/project.yaml') ]) ]) repo.contents[0].contents[1].set_yaml_contents(b'builds_per_day: 2') repo.contents[1].contents[1].set_yaml_contents(b'builds_per_day: 3') self.assertEqual( get_projects(repo), { 'test0': ProjectMetadata('0 6,18 * * *', 'builds_per_day: 2', 'name: test'), 'test1': ProjectMetadata('0 6,14,22 * * *', 'builds_per_day: 3', 'name: test') })
def test_sync_projects_update(self): """Testing sync_projects() updating a schedule.""" cloud_scheduler_client = CloudSchedulerClient() with ndb.Client().context(): Project(name='test1', schedule='0 8 * * *', project_yaml_contents='', dockerfile_contents='').put() Project(name='test2', schedule='0 9 * * *', project_yaml_contents='', dockerfile_contents='').put() projects = { 'test1': ProjectMetadata('0 8 * * *', '', ''), 'test2': ProjectMetadata('0 7 * * *', '', '') } sync_projects(cloud_scheduler_client, projects) projects_query = Project.query() self.assertEqual({ 'test1': '0 8 * * *', 'test2': '0 7 * * *' }, {project.name: project.schedule for project in projects_query})
def test_sync_projects_create(self): """"Testing sync_projects() creating new schedule.""" cloud_scheduler_client = CloudSchedulerClient() with ndb.Client().context(): Project(name='test1', schedule='0 8 * * *', project_yaml_contents='', dockerfile_contents='').put() projects = { 'test1': ProjectMetadata('0 8 * * *', '', ''), 'test2': ProjectMetadata('0 7 * * *', '', '') } sync_projects(cloud_scheduler_client, projects) projects_query = Project.query() self.assertEqual({ 'test1': '0 8 * * *', 'test2': '0 7 * * *' }, {project.name: project.schedule for project in projects_query}) self.assertCountEqual([ { 'name': 'projects/test-project/location/us-central1/jobs/' 'test2-scheduler-fuzzing', 'pubsub_target': { 'topic_name': 'projects/test-project/topics/request-build', 'data': b'test2' }, 'schedule': '0 7 * * *' }, { 'name': 'projects/test-project/location/us-central1/jobs/' 'test2-scheduler-coverage', 'pubsub_target': { 'topic_name': 'projects/test-project/topics/request-coverage-build', 'data': b'test2' }, 'schedule': '0 6 * * *' }, ], cloud_scheduler_client.schedulers)
def test_get_projects_non_directory_type_project(self): """Testing get_projects() when a file in projects/ is not of type 'dir'.""" repo = Repository('oss-fuzz', 'dir', 'projects', [ Repository('test0', 'dir', 'projects/test0', [ Repository('Dockerfile', 'file', 'projects/test0/Dockerfile'), Repository('project.yaml', 'file', 'projects/test0/project.yaml') ]), Repository('test1', 'file', 'projects/test1') ]) self.assertEqual( get_projects(repo), {'test0': ProjectMetadata('0 6 * * *', 'name: test', 'name: test')})
def test_get_projects_no_docker_file(self): """Testing get_projects() with missing dockerfile""" repo = Repository('oss-fuzz', 'dir', 'projects', [ Repository('test0', 'dir', 'projects/test0', [ Repository('Dockerfile', 'file', 'projects/test0/Dockerfile'), Repository('project.yaml', 'file', 'projects/test0/project.yaml') ]), Repository('test1', 'dir', 'projects/test1') ]) self.assertEqual( get_projects(repo), {'test0': ProjectMetadata('0 6 * * *', 'name: test', 'name: test')})