def test_internal_zalando_ingress(self): """Ensure ManifestChecker does not return an error for internal Zalando ingress manifest""" content = get_content("manifests/internal-zalando-ingress.yaml") errors = self.checker.check(content) assert not errors
def test_invalid_zalando_ingress(self): """Ensure ManifestChecker returns an error for invalid Zalando ingress manifest""" content = get_content("manifests/invalid-zalando-ingress.yaml") errors = self.checker.check(content) assert len(errors) > 0
def test_multidoc_resources(self): """ Ensure ValuesChecker returns an error for a multi-document values file """ content = get_content("values/multidoc-values.yaml") errors = self.checker.check(content) assert len(errors) > 0
def test_good_resources_answers(self): """ Ensure AnswersChecker returns no error for answers with proper resources """ content = get_content("answers/good-resources-answers.yaml") errors = self.checker.check(content) assert not errors
def test_no_requests_answers(self): """ Ensure AnswersChecker returns an error for flat answers with resources but no requests """ content = get_content("answers/no-requests-answers.yaml") errors = self.checker.check(content) assert len(errors) > 0
def test_good_init_deployment(self): """ Ensure ManifestChecker does not return an error for a deployment with init containers """ content = get_content("manifests/good-init-deployment.yaml") errors = self.checker.check(content) assert not errors
def test_good_cronjob(self): """ Ensure ManifestChecker does not return an error for a valid CronJob """ content = get_content("manifests/good-cronjob.yaml") errors = self.checker.check(content) assert not errors
def test_no_limits_deployment(self): """ Ensure ManifestChecker returns an error for a Deployment with no limits """ content = get_content("manifests/no-limits-deployment.yaml") errors = self.checker.check(content) assert len(errors) > 0
def test_no_resources_job(self): """ Ensure ManifestChecker returns an error for a Job with no resources """ content = get_content("manifests/no-resources-job.yaml") errors = self.checker.check(content) assert len(errors) > 0
def test_multidoc_invalid_ingress(self): """ Ensure ManifestChecker returns an error for a multi-document manifest including a single invalid Ingress """ content = get_content("manifests/invalid-ingress-multidoc.yaml") errors = self.checker.check(content) assert len(errors) > 0
def test_nginx_ingress(self): """ Ensure ManifestChecker does not return an error for an NGINX ingress """ content = get_content("manifests/nginx-ingress.yaml") errors = self.checker.check(content) assert not errors
def test_good_resources_answers(self): """ Ensure ValuesChecker returns no errors for values with proper resources """ content = get_content("values/good-resources-values.yaml") errors = self.checker.check(content) assert not errors
def test_multidoc_resources(self): """ Ensure AnswersChecker returns an error for a multi-document answers file """ content = get_content("answers/multidoc-answers.yaml") errors = self.checker.check(content) assert len(errors) > 0
def test_check_with_node_constraints(self, *mocks): """ Ensures the profile check passes when no constraints are found """ profile = Profile(self.workflow) profile.load = mock.Mock() profile.load.return_value = get_content("profiles/with_node_constraints.yml") errors = profile._check_services(profile.check_constraints, profile.data) self.assertEqual(0, len(errors))
def test_check_resources_empty(self, *mocks): """ Ensures the profile check fails when resources constraints are empty """ profile = Profile(self.workflow) profile.load = mock.Mock() profile.load.return_value = get_content("profiles/resources_nothing_set.yml") errors = profile._check_services(profile.check_resources, profile.data) self.assertRegex(" ".join(errors), r"resource constraints not found")
def test_check_no_node_constraints(self, *mocks): """ Ensures the profile check fails when `node.` constraints are not found """ profile = Profile(self.workflow) profile.load = mock.Mock() profile.load.return_value = get_content("profiles/no_node_constraints.yml") errors = profile._check_services(profile.check_constraints, profile.data) self.assertRegex(" ".join(errors), r"node constraints not found")
def test_check_no_resources(self, *mocks): """ Ensures the profile check fails when no resource constraints are found """ profile = Profile(self.workflow) profile.load = mock.Mock() profile.load.return_value = get_content('profiles/no_constraints.yml') errors = profile._check_services(profile.check_resources, profile.data) self.assertRegex(' '.join(errors), r'resource constraints not found')
def test_check_global_mode(self, *mocks): """ Ensures the profile check does not fail when there is no constraint on a global service """ profile = Profile(self.workflow) profile.load = mock.Mock() profile.load.return_value = get_content("profiles/global_no_constraints.yml") errors = profile._check_services(profile.check_constraints, profile.data) self.assertEqual(0, len(errors), errors)
def test_get_simplified_merge_commits(self, *mocks): """ Ensure the merge commits are properly simplified down """ content = get_content('git-log.txt') commits = git.Commit.from_log(content) self.assertEquals(36, len(commits)) simplified = git.get_simplified_merge_commits(commits) self.assertEquals(6, len(simplified))
def test_set_resources_empty_resources_left_alone(self, *mocks): """ Ensures when services.x.deploy doesn't exist it is not added """ content = get_content("profiles/no_constraints.yml") data = yaml_load(content) service_name, data = list(data["services"].items())[0] profile = Profile(self.workflow) profile.set_resources(service_name, data) self.assertEqual("deploy" not in data, True)
def test_set_resources_memory_reservation_no_limit(self, *mocks): """ Ensures memory limit is matched to reservation when no limit is given """ merge_profile_mock = mocks[0] merge_profile_mock.return_value = get_content( 'profiles/reservation_no_limit.yml') profile = Profile(self.workflow) param = {} content = profile._compile( param) # the param is ignored because it's using the mock merge_profile_mock.assert_called_with(param) data = yaml_load(content) resources = data['services']['app']['deploy']['resources'] self.assertEqual(resources['limits']['memory'], resources['reservations']['memory'])
def test_set_resources_memory_limit_and_reservation(self, *mocks): """ Ensures memory reservation and limit are left alone when they are both defined """ merge_profile_mock = mocks[0] merge_profile_mock.return_value = get_content( 'profiles/limit_and_reservation.yml') profile = Profile(self.workflow) param = {} content = profile._compile( param) # the param is ignored because it's using the mock merge_profile_mock.assert_called_with(param) data = yaml_load(content) resources = data['services']['app']['deploy']['resources'] self.assertEqual('10M', resources['reservations']['memory']) self.assertEqual('100M', resources['limits']['memory'])
def test_set_resources_memory_limit_no_reservation(self, *mocks): """ Ensures memory reservation is matched to limit when no reservation is given """ merge_profile_mock = mocks[0] merge_profile_mock.return_value = get_content( "profiles/limit_no_reservation.yml" ) profile = Profile(self.workflow) param = {} content = profile._compile( param ) # the param is ignored because it's using the mock merge_profile_mock.assert_called_with(param) data = yaml_load(content) resources = data["services"]["app"]["deploy"]["resources"] self.assertEqual( resources["reservations"]["memory"], resources["limits"]["memory"] )
def _get_manager(self, content=None): content = content or get_content('git-branch.txt') manager = git.BranchManager.from_git_output(content) return manager