Skip to content

Commit

Permalink
Remove byteorder-dependency
Browse files Browse the repository at this point in the history
  • Loading branch information
lukaslueg committed Jul 8, 2019
1 parent 644c808 commit 91186e8
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 5 deletions.
1 change: 0 additions & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@ path = "src/cargo/lib.rs"

[dependencies]
atty = "0.2"
byteorder = "1.2"
bytesize = "1.0"
crates-io = { path = "crates/crates-io", version = "0.27" }
crossbeam-utils = "0.6"
Expand Down
16 changes: 12 additions & 4 deletions tests/testsuite/support/publish.rs
Original file line number Diff line number Diff line change
@@ -1,15 +1,23 @@
use std::collections::{HashMap, HashSet};
use std::fs::File;
use std::io::{prelude::*, SeekFrom};
use std::io::{self, prelude::*, SeekFrom};
use std::path::{Path, PathBuf};

use crate::support::find_json_mismatch;
use crate::support::registry::{self, alt_api_path};

use byteorder::{LittleEndian, ReadBytesExt};
use flate2::read::GzDecoder;
use tar::Archive;

fn read_le_u32<R>(mut reader: R) -> io::Result<u32>
where
R: Read,
{
let mut buf = [0; 4];
reader.read_exact(&mut buf)?;
Ok(u32::from_le_bytes(buf))
}

/// Checks the result of a crate publish.
pub fn validate_upload(expected_json: &str, expected_crate_name: &str, expected_files: &[&str]) {
let new_path = registry::api_path().join("api/v1/crates/new");
Expand Down Expand Up @@ -44,7 +52,7 @@ fn _validate_upload(
) {
let mut f = File::open(new_path).unwrap();
// 32-bit little-endian integer of length of JSON data.
let json_sz = f.read_u32::<LittleEndian>().expect("read json length");
let json_sz = read_le_u32(&mut f).expect("read json length");
let mut json_bytes = vec![0; json_sz as usize];
f.read_exact(&mut json_bytes).expect("read JSON data");
let actual_json = serde_json::from_slice(&json_bytes).expect("uploaded JSON should be valid");
Expand All @@ -53,7 +61,7 @@ fn _validate_upload(
.expect("uploaded JSON did not match expected JSON");

// 32-bit little-endian integer of length of crate file.
let crate_sz = f.read_u32::<LittleEndian>().expect("read crate length");
let crate_sz = read_le_u32(&mut f).expect("read crate length");
let mut krate_bytes = vec![0; crate_sz as usize];
f.read_exact(&mut krate_bytes).expect("read crate data");
// Check at end.
Expand Down

0 comments on commit 91186e8

Please sign in to comment.