def test_lscpu(): input_data = InputData().add(Specs.lscpu, LSCPU_1) result = run_test(system_profile, input_data) assert result["cores_per_socket"] == 1 input_data = InputData().add(Specs.lscpu, LSCPU_2) result = run_test(system_profile, input_data) assert result.get("cores_per_socket") is None
def test_gcp_license_codes(): input_data = InputData().add(Specs.gcp_license_codes, GCP_LICENSE_CODES_1) result = run_test(system_profile, input_data) assert result["is_marketplace"] is True input_data = InputData().add(Specs.gcp_license_codes, GCP_LICENSE_CODES_2) result = run_test(system_profile, input_data) assert result["is_marketplace"] is True input_data = InputData().add(Specs.gcp_license_codes, GCP_LICENSE_CODES_BAD) result = run_test(system_profile, input_data) assert result.get("is_marketplace") is None
def integration_test(): input_data = InputData("no_bash_bug") input_data.add(Specs.installed_rpms, CURRENT_VERSION) expected = make_pass("BASH_BUG", bash=CURRENT_VERSION, found=NOT_FOUND) yield input_data, expected input_data = InputData("is_bash_bug") input_data.add(Specs.installed_rpms, BUG_VERSION) expected = make_fail("BASH_BUG", bash=BUG_VERSION, found=FOUND) yield input_data, expected
def _run_rule(name, rule, input_data): """ Fixture for rule integration testing Use this fixture to create an integration test for your rule plugin. Sample code:: def test_myrule(run_rule): input_data = {'spec': Specs.installed_rpms, 'data': RPMS_DATA} expected = make_fail(ERROR_KEY, bad_data=data_expected) results = run_rule('my test name', my_rule, input_data) assert results == expected Arguments: name (str): Name to identify this test in output. rule (object): Your rule function object. data (list or dict): List of dict of each data spec your rule requires to trigger. If a single input data spec then a dict can be passed instead. Each dict must include both ``spec`` and ``data`` keys, and may optionally include ``path`` if necessary for the spec. Return: results of call to make_pass, make_fail, etc., or None Raises: KeyError: Raises if either spec or data keywords are not present. """ idata = InputData(name) input_data = input_data if isinstance(input_data, list) else [input_data] for d in input_data: if 'path' in d: idata.add(d['spec'], d['data'], path=d['path']) else: idata.add(d['spec'], d['data']) return run_test(rule, idata)