Skip to content

Commit

Permalink
rename testdata to fixtures
Browse files Browse the repository at this point in the history
  • Loading branch information
Byron committed Jul 29, 2023
1 parent 0096b92 commit aba9606
Show file tree
Hide file tree
Showing 10 changed files with 44 additions and 48 deletions.
4 changes: 2 additions & 2 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -3,5 +3,5 @@ Cargo.lock
_test

# May be created during tests, but should not be present
tests/testdata/sparse_registry_cache/cargo_home/registry/index/index.crates.io-6f17d22bba15001f/.cache/cr/at/crates-index
/tests/testdata/git-registry/
tests/fixtures/sparse_registry_cache/cargo_home/registry/index/index.crates.io-6f17d22bba15001f/.cache/cr/at/crates-index
/tests/fixtures/git-registry/
2 changes: 1 addition & 1 deletion src/bare_index.rs
Original file line number Diff line number Diff line change
Expand Up @@ -538,7 +538,7 @@ mod test {
}

fn shared_index() -> Index {
let index_path = "tests/testdata/git-registry";
let index_path = "tests/fixtures/git-registry";
if is_ci::cached() {
Index::new_cargo_default()
.expect("CI has just cloned this index and its ours and valid")
Expand Down
39 changes: 0 additions & 39 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -739,42 +739,3 @@ fn path_max_byte_len(path: &Path) -> usize {
fn path_max_byte_len(path: &Path) -> usize {
path.to_str().map_or(0, |p| p.len())
}

#[cfg(test)]
mod test {
use super::*;

#[test]
fn sizes() {
assert!(std::mem::size_of::<Version>() <= 152);
assert!(std::mem::size_of::<Crate>() <= 16);
assert!(std::mem::size_of::<Dependency>() <= 80);
}

#[test]
fn semver() {
let c = Crate::from_slice(r#"{"vers":"1.0.0", "name":"test", "deps":[], "features":{}, "cksum":"1234567890123456789012345678901234567890123456789012345678901234", "yanked":false}
{"vers":"1.2.0-alpha.1", "name":"test", "deps":[], "features":{}, "cksum":"1234567890123456789012345678901234567890123456789012345678901234", "yanked":false}
{"vers":"1.0.1", "name":"test", "deps":[], "features":{}, "cksum":"1234567890123456789012345678901234567890123456789012345678901234", "yanked":false}"#.as_bytes()).unwrap();
assert_eq!(c.most_recent_version().version(), "1.0.1");
assert_eq!(c.highest_version().version(), "1.2.0-alpha.1");
assert_eq!(c.highest_normal_version().unwrap().version(), "1.0.1");
}

#[test]
fn features2() {
let c = Crate::from_slice(br#"{"vers":"1.0.0", "name":"test", "deps":[], "features":{"a":["one"], "b":["x"]},"features2":{"a":["two"], "c":["y"]}, "cksum":"1234567890123456789012345678901234567890123456789012345678901234"}"#).unwrap();
let f2 = c.most_recent_version().features();

assert_eq!(3, f2.len());
assert_eq!(["one", "two"], &f2["a"][..]);
assert_eq!(["x"], &f2["b"][..]);
assert_eq!(["y"], &f2["c"][..]);
}

#[test]
fn rust_version() {
let c = Crate::from_slice(br#"{"vers":"1.0.0", "name":"test", "deps":[], "features":{},"features2":{}, "cksum":"1234567890123456789012345678901234567890123456789012345678901234", "rust_version":"1.64.0"}"#).unwrap();
assert_eq!(c.most_recent_version().rust_version(), Some("1.64.0"));
}
}
4 changes: 2 additions & 2 deletions src/sparse_index.rs
Original file line number Diff line number Diff line change
Expand Up @@ -286,13 +286,13 @@ mod tests {
#[inline]
fn crates_io() -> SparseIndex {
SparseIndex::with_path(
std::path::Path::new(&std::env::var_os("CARGO_MANIFEST_DIR").unwrap()).join("tests/testdata/sparse_registry_cache/cargo_home"),
std::path::Path::new(&std::env::var_os("CARGO_MANIFEST_DIR").unwrap()).join("tests/fixtures/sparse_registry_cache/cargo_home"),
crate::CRATES_IO_HTTP_INDEX
).unwrap()
}

// curl -v -H 'accept-encoding: gzip,identity' https://index.crates.io/cr/at/crates-index
const CRATES_INDEX_INDEX_ENTRY: &[u8] = include_bytes!("../tests/testdata/crates-index.txt");
const CRATES_INDEX_INDEX_ENTRY: &[u8] = include_bytes!("../tests/fixtures/crates-index.txt");

// Validates that a valid cache entry is written if the index entry has been
// modified
Expand Down
2 changes: 1 addition & 1 deletion tests/bare_index/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -180,7 +180,7 @@ pub(crate) mod with_https {
}

pub(crate) fn shared_index() -> Index {
let index_path = "tests/testdata/git-registry";
let index_path = "tests/fixtures/git-registry";
if is_ci::cached() {
Index::new_cargo_default()
.expect("CI has just cloned this index and its ours and valid")
Expand Down
35 changes: 35 additions & 0 deletions tests/crates_index.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,3 +8,38 @@ mod error {
}
}

use crates_index::{Crate, Dependency, Version};

#[test]
fn sizes() {
assert!(std::mem::size_of::<Version>() <= 152);
assert!(std::mem::size_of::<Crate>() <= 16);
assert!(std::mem::size_of::<Dependency>() <= 80);
}

#[test]
fn semver() {
let c = Crate::from_slice(r#"{"vers":"1.0.0", "name":"test", "deps":[], "features":{}, "cksum":"1234567890123456789012345678901234567890123456789012345678901234", "yanked":false}
{"vers":"1.2.0-alpha.1", "name":"test", "deps":[], "features":{}, "cksum":"1234567890123456789012345678901234567890123456789012345678901234", "yanked":false}
{"vers":"1.0.1", "name":"test", "deps":[], "features":{}, "cksum":"1234567890123456789012345678901234567890123456789012345678901234", "yanked":false}"#.as_bytes()).unwrap();
assert_eq!(c.most_recent_version().version(), "1.0.1");
assert_eq!(c.highest_version().version(), "1.2.0-alpha.1");
assert_eq!(c.highest_normal_version().unwrap().version(), "1.0.1");
}

#[test]
fn features2() {
let c = Crate::from_slice(br#"{"vers":"1.0.0", "name":"test", "deps":[], "features":{"a":["one"], "b":["x"]},"features2":{"a":["two"], "c":["y"]}, "cksum":"1234567890123456789012345678901234567890123456789012345678901234"}"#).unwrap();
let f2 = c.most_recent_version().features();

assert_eq!(3, f2.len());
assert_eq!(["one", "two"], &f2["a"][..]);
assert_eq!(["x"], &f2["b"][..]);
assert_eq!(["y"], &f2["c"][..]);
}

#[test]
fn rust_version() {
let c = Crate::from_slice(br#"{"vers":"1.0.0", "name":"test", "deps":[], "features":{},"features2":{}, "cksum":"1234567890123456789012345678901234567890123456789012345678901234", "rust_version":"1.64.0"}"#).unwrap();
assert_eq!(c.most_recent_version().rust_version(), Some("1.64.0"));
}
File renamed without changes.
File renamed without changes.
6 changes: 3 additions & 3 deletions tests/sparse_index/mod.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
#[test]
fn crate_from_cache() {
let index = crates_index::SparseIndex::with_path(
std::path::Path::new(&std::env::var_os("CARGO_MANIFEST_DIR").unwrap()).join("tests/testdata/sparse_registry_cache/cargo_home"),
std::path::Path::new(&std::env::var_os("CARGO_MANIFEST_DIR").unwrap()).join("tests/fixtures/sparse_registry_cache/cargo_home"),
crates_index::CRATES_IO_HTTP_INDEX
).unwrap();

Expand All @@ -20,7 +20,7 @@ mod with_sparse_http_feature {
#[inline]
fn crates_io() -> SparseIndex {
SparseIndex::with_path(
std::path::Path::new(&std::env::var_os("CARGO_MANIFEST_DIR").unwrap()).join("tests/testdata/sparse_registry_cache/cargo_home"),
std::path::Path::new(&std::env::var_os("CARGO_MANIFEST_DIR").unwrap()).join("tests/fixtures/sparse_registry_cache/cargo_home"),
crates_index::CRATES_IO_HTTP_INDEX
).unwrap()
}
Expand Down Expand Up @@ -65,7 +65,7 @@ mod with_sparse_http_feature {

// curl -v -H 'accept-encoding: gzip,identity' -H 'if-none-match: W/"aa975a09419f9c8f61762a3d06fdb67d"' https://index.crates.io/au/to/autocfg
// as of 2023-06-15
const AUTOCFG_INDEX_ENTRY: &[u8] = include_bytes!("../../tests/testdata/autocfg.txt");
const AUTOCFG_INDEX_ENTRY: &[u8] = include_bytes!("../../tests/fixtures/autocfg.txt");

// Validates that a response with the full index contents are properly parsed
#[test]
Expand Down

0 comments on commit aba9606

Please sign in to comment.