pub fn mock_crate_index(
  crates: &HashMap<String, String>,
  mock_dir: Option<&Path>,
) -> Option<TempDir> {
  let index_url_mock_dir = TempDir::new().unwrap();

  // If an existing directory is provided, use that instead
  let index_dir = match mock_dir {
    Some(dir) => dir,
    None => index_url_mock_dir.as_ref(),
  };

  for (name, version) in crates {
    let crate_index_path = if name.len() < 4 {
      index_dir.join(name.len().to_string()).join(name)
    } else {
      index_dir
        .join(&name.as_str()[0..2])
        .join(&name.as_str()[2..4])
        .join(name)
    };

    create_dir_all(crate_index_path.parent().unwrap()).unwrap();
    write(
      crate_index_path,
      json!({
        "name": name,
        "vers": version,
        "deps": [],
        "cksum": "8a648e87a02fa31d9d9a3b7c76dbfee469402fbb4af3ae98b36c099d8a82bb18",
        "features": {},
        "yanked": false,
        "links": null
      })
      .to_string(),
    )
    .unwrap();
  }

  // Return the generated TempDir in the event that `mock_dir` was not provided
  if mock_dir.is_none() {
    Some(index_url_mock_dir)
  } else {
    None
  }
}
/// Create a mock cache in a temporary directory that contains a set of given crates
Create a mock cache in a temporary directory that contains a set of given crates
Create a mock cache in a temporary directory that contains a set of given crates
pub fn mock_crate_index(
  crates: &HashMap<String, String>,
  mock_dir: Option<&Path>,
) -> Option<TempDir> {
  let index_url_mock_dir = TempDir::new().unwrap();
  // If an existing directory is provided, use that instead
  let index_dir = match mock_dir {
    Some(dir) => dir,
    None => index_url_mock_dir.as_ref(),
  };
  for (name, version) in crates {
    let crate_index_path = if name.len() < 4 {
      index_dir.join(name.len().to_string()).join(name)
    } else {
      index_dir
        .join(&name.as_str()[0..2])
        .join(&name.as_str()[2..4])
        .join(name)
    };
    create_dir_all(crate_index_path.parent().unwrap()).unwrap();
    write(
      crate_index_path,
      json!({
        "name": name,
        "vers": version,
        "deps": [],
        "cksum": "8a648e87a02fa31d9d9a3b7c76dbfee469402fbb4af3ae98b36c099d8a82bb18",
        "features": {},
        "yanked": false,
        "links": null
      })
      .to_string(),
    )
    .unwrap();
  }
  // Return the generated TempDir in the event that `mock_dir` was not provided
  if mock_dir.is_none() {
    Some(index_url_mock_dir)
  } else {
    None
  }
}
pub fn mock_crate_index ( crates : & HashMap < String , String > , mock_dir : Option < & Path > , ) -> Option < TempDir > { let index_url_mock_dir = TempDir :: new ( ) . unwrap ( ) ; // If an existing directory is provided, use that instead let index_dir = match mock_dir { Some ( dir ) => dir , None => index_url_mock_dir . as_ref ( ) , } ; for ( name , version ) in crates { let crate_index_path = if name . len ( ) < 4 { index_dir . join ( name . len ( ) . to_string ( ) ) . join ( name ) } else { index_dir . join ( & name . as_str ( ) [ 0 .. 2 ] ) . join ( & name . as_str ( ) [ 2 .. 4 ] ) . join ( name ) } ; create_dir_all ( crate_index_path . parent ( ) . unwrap ( ) ) . unwrap ( ) ; write ( crate_index_path , json ! ( { " " name " " version " " [ ] " " " " " " { } " " false " " null } ) . to_string ( ) , ) . unwrap ( ) ; } // Return the generated TempDir in the event that `mock_dir` was not provided if mock_dir . is_none ( ) { Some ( index_url_mock_dir ) } else { None } }
Create a mock cache in a temporary directory that contains a set of given crates
Create a mock cache in a temporary directory that contains a set of given crates
crates
&HashMap<String, String>
mock_dir
Option<&Path>
crates
&HashMap<String, String>
mock_dir
Option<&Path>