Пример #1
0
    def test_add_wildcard(self):
        registry = BaseCheckRegistry()
        resource_s_check = TestCheck("resource_*")
        registry.register(resource_s_check)
        checks = registry.get_checks("resource_*")
        self.assertEqual(1, len(checks))
        self.assertEqual(resource_s_check, checks[0])

        self.assertNotIn("resource_*", registry.checks)
        self.assertIn("resource_*", registry.wildcard_checks)
Пример #2
0
    def test_get_check_no_wildcard(self):
        registry = BaseCheckRegistry()
        resource_1_check = TestCheck("resource_1", id="CKV_T_1")
        resource_2_check1 = TestCheck("resource_2", id="CKV_T_2")
        resource_2_check2 = TestCheck("resource_2", id="CKV_T_3")
        registry.register(resource_1_check)
        registry.register(resource_2_check1)
        registry.register(resource_2_check2)

        resource_1_checks = registry.get_checks("resource_1")
        self.assertEqual(1, len(resource_1_checks))
        self.assertEqual(resource_1_check, resource_1_checks[0])

        resource_2_checks = registry.get_checks("resource_2")
        self.assertEqual(2, len(resource_2_checks))
        self.assertIn(resource_2_check1, resource_2_checks)
        self.assertIn(resource_2_check2, resource_2_checks)

        self.assertEqual(0, len(registry.get_checks("resource")))
        self.assertEqual(0, len(registry.get_checks("resource_10")))
Пример #3
0
    def test_get_check_mixed(self):
        registry = BaseCheckRegistry()
        resource_1_check = TestCheck("resource_1", id="CKV_T_1")
        resource_2_check = TestCheck("resource_2", id="CKV_T_2")
        resource_s_check = TestCheck("resource_*", id="CKV_T_4")
        resource_as_check = TestCheck("resource_a*", id="CKV_T_3")
        s_check = TestCheck("*", id="CKV_T_4")
        s_2_check = TestCheck("*_2", id="CKV_T_5")
        registry.register(resource_1_check)
        registry.register(resource_2_check)
        registry.register(resource_s_check)
        registry.register(resource_as_check)
        registry.register(s_check)
        registry.register(s_2_check)

        resource_1_checks = registry.get_checks("resource_1")
        self.assertEqual(3, len(resource_1_checks))
        self.assertIn(s_check, resource_1_checks)
        self.assertIn(resource_1_check, resource_1_checks)
        self.assertIn(resource_s_check, resource_1_checks)

        resource_10_checks = registry.get_checks("resource_10")
        self.assertEqual(2, len(resource_10_checks))
        self.assertIn(s_check, resource_10_checks)
        self.assertIn(resource_s_check, resource_10_checks)

        resource_2_checks = registry.get_checks("resource_2")
        self.assertEqual(4, len(resource_2_checks))
        self.assertIn(s_check, resource_2_checks)
        self.assertIn(s_2_check, resource_2_checks)
        self.assertIn(resource_2_check, resource_2_checks)
        self.assertIn(resource_s_check, resource_2_checks)

        resource__checks = registry.get_checks("resource_")
        self.assertEqual(2, len(resource__checks))
        self.assertIn(s_check, resource__checks)
        self.assertIn(resource_s_check, resource__checks)
Пример #4
0
    def test_get_check_wildcard(self):
        registry = BaseCheckRegistry()
        resource_s_check = TestCheck("resource_*", id="CKV_T_1")
        resource_as_check = TestCheck("resource_a*", id="CKV_T_2")
        s_check = TestCheck("*", id="CKV_T_3")
        s_2_check = TestCheck("*_2", id="CKV_T_4")
        registry.register(resource_s_check)
        registry.register(resource_as_check)
        registry.register(s_check)
        registry.register(s_2_check)

        resource_1_checks = registry.get_checks("resource_1")
        self.assertEqual(2, len(resource_1_checks))
        self.assertIn(s_check, resource_1_checks)
        self.assertIn(resource_s_check, resource_1_checks)

        resource_2_checks = registry.get_checks("resource_2")
        self.assertEqual(3, len(resource_2_checks))
        self.assertIn(s_check, resource_2_checks)
        self.assertIn(s_2_check, resource_2_checks)
        self.assertIn(resource_s_check, resource_2_checks)

        resource__checks = registry.get_checks("resource_")
        self.assertEqual(2, len(resource__checks))
        self.assertIn(s_check, resource__checks)
        self.assertIn(resource_s_check, resource__checks)

        resource_abc_checks = registry.get_checks("resource_abc")
        self.assertEqual(3, len(resource_abc_checks))
        self.assertIn(s_check, resource_abc_checks)
        self.assertIn(resource_s_check, resource_abc_checks)
        self.assertIn(resource_as_check, resource_abc_checks)

        r_checks = registry.get_checks("r")
        self.assertEqual(1, len(r_checks))
        self.assertIn(s_check, r_checks)

        resource_checks = registry.get_checks("resource")
        self.assertEqual(1, len(resource_checks))
        self.assertIn(s_check, resource_checks)

        resource_checks = registry.get_checks("resource_ABC")
        self.assertEqual(2, len(resource_checks))
        self.assertIn(s_check, resource_checks)
        self.assertIn(resource_s_check, resource_checks)