Exemplo n.º 1
0
    def test_contract_bad(self):
        context = ExecutionContext()
        source = [{
            'metric': 'A',
            'limit': 100.0,
            'usage': 0.0
        }, {
            'metric': 'B',
            'limit': 100.0,
            'usage': 90.0
        }, {
            'metric': 'C',
            'limit': 100.0,
            'usage': 100.0
        }]
        mock_service = self.make_mock_service(source, source)
        observer = GcpAgent(service=mock_service,
                            discovery_doc=MOCK_DISCOVERY,
                            default_variables={'project': 'PROJECT'})

        project_quota = {'A': 95.0, 'B': 10.0}
        regions = [('region1', project_quota), ('region2', {'C': 1.0})]

        contract = make_quota_contract(observer, project_quota, regions)
        result = contract.verify(context)
        self.assertFalse(result)
        self.assertEqual(3, len(result.clause_results))
        self.assertTrue(result.clause_results[0])
        self.assertTrue(result.clause_results[1])
        self.assertFalse(result.clause_results[2])
Exemplo n.º 2
0
  def test_contract_ok(self):
    source = [{'metric': 'A', 'limit': 100.0, 'usage': 0.0},
              {'metric': 'B', 'limit': 100.0, 'usage': 90.0},
              {'metric': 'C', 'limit': 100.0, 'usage': 100.0}]

    mock_service = self.make_mock_service(source, source)
    observer = GcpAgent(service=mock_service, discovery_doc=MOCK_DISCOVERY,
                        default_variables={'project': 'PROJECT'})
    project_quota = {'A': 95.0, 'B': 10.0}
    regions = [('region1', project_quota)]

    contract = make_quota_contract(observer, project_quota, regions)
    got_result = contract.verify()
    self.assertTrue(got_result)
    self.assertEqual(2, len(got_result.clause_results))
Exemplo n.º 3
0
  def test_contract_bad(self):
    context = ExecutionContext()
    source = [{'metric': 'A', 'limit': 100.0, 'usage': 0.0},
              {'metric': 'B', 'limit': 100.0, 'usage': 90.0},
              {'metric': 'C', 'limit': 100.0, 'usage': 100.0}]
    mock_service = self.make_mock_service(source, source)
    observer = GcpAgent(service=mock_service, discovery_doc=MOCK_DISCOVERY,
                        default_variables={'project': 'PROJECT'})

    project_quota = {'A': 95.0, 'B': 10.0}
    regions = [('region1', project_quota), ('region2', {'C': 1.0})]

    contract = make_quota_contract(observer, project_quota, regions)
    result = contract.verify(context)
    self.assertFalse(result)
    self.assertEqual(3, len(result.clause_results))
    self.assertTrue(result.clause_results[0])
    self.assertTrue(result.clause_results[1])
    self.assertFalse(result.clause_results[2])