def test_load_policy_bundle_paths(mock_default_config, tmpdir, config_filenames): # setup files to read input_dir = tmpdir.mkdir(INPUT_BUNDLES_DIR) mock_test_files(input_dir, config_filenames) output_dir_name = tmpdir.strpath + "/bundles" # setup the default config load_defaults(configdir=tmpdir) # function under test load_policy_bundle_paths(src_dir=input_dir.strpath) # get and validate the relevant config bits config = get_config() assert config["policy_bundles"] is not None assert len(config["policy_bundles"]) == len(config_filenames) for config_filename in config_filenames: policy_bundle = next( policy_bundle for policy_bundle in config["policy_bundles"] if policy_bundle["bundle_path"] == output_dir_name + "/" + config_filename) assert policy_bundle is not None if config_filename == "anchore_default_bundle.json": assert policy_bundle["active"] else: assert not policy_bundle["active"] assert os.path.exists(policy_bundle["bundle_path"])
def test_empty_src_dirs(mock_default_config, tmpdir): # setup the default config load_defaults(configdir=tmpdir) # function under test load_policy_bundle_paths(src_dirs=[]) # get and validate the relevant config bits config = get_config() assert config["policy_bundles"] is None
def setup_engine_config(db_connect_str): """ Sets the config for the service to bootstrap a specific db. :param db_connect_str: :return: """ from anchore_engine.configuration import localconfig localconfig.load_defaults() localconfig.localconfig['credentials'] = { 'database': { 'db_connect': db_connect_str } }
def setup_engine_config(cls, db_connect_str): """ Sets the config for the service to bootstrap a specific db. :param db_connect_str: :return: """ from anchore_engine.configuration import localconfig localconfig.load_defaults() localconfig.localconfig["credentials"] = { "database": { "db_connect": db_connect_str } } return localconfig.localconfig
def test_load_filepath_to_config(mock_default_config, tmpdir, config_key, config_filename): # setup files to read input_dir = tmpdir.mkdir(INPUT_CONFIG_DIR) mock_test_file(input_dir, config_filename) output_dir_name = tmpdir.strpath # setup the default config load_defaults(configdir=tmpdir) load_filepath_to_config(config_key, config_filename, src_dir=input_dir.strpath) config = get_config() assert config["anchore_scanner_analyzer_config_file"] is not None assert (config["anchore_scanner_analyzer_config_file"] == output_dir_name + "/" + config_filename) assert os.path.exists(config["anchore_scanner_analyzer_config_file"])
def test_load_policy_bundle_paths(mock_default_config, tmpdir, config_filename_sets): # setup files to read src_dirs = [] i = 0 for set in config_filename_sets: input_dir = tmpdir.mkdir(INPUT_BUNDLES_DIR_ROOT + "_" + str(i)) i += 1 mock_test_files(input_dir, set) src_dirs.append(input_dir.strpath) # setup the expected output. We will expect to see output_dir_name contain the # files in config_filenames_flat output_dir_name = tmpdir.strpath + "/bundles" config_filenames_flat = [ filename for set in config_filename_sets for filename in set ] # setup the default config load_defaults(configdir=tmpdir) # function under test load_policy_bundle_paths(src_dirs=src_dirs) # get and validate the relevant config bits config = get_config() assert config["policy_bundles"] is not None assert len(config["policy_bundles"]) == len(config_filenames_flat) for config_filename in config_filenames_flat: policy_bundle = next( policy_bundle for policy_bundle in config["policy_bundles"] if policy_bundle["bundle_path"] == output_dir_name + "/" + config_filename) assert policy_bundle is not None if config_filename == "anchore_default_bundle.json": assert policy_bundle["active"] else: assert not policy_bundle["active"] assert os.path.exists(policy_bundle["bundle_path"])