Skip to content

Commit

Permalink
Use BTreeMap for features to ensure stable sorting
Browse files Browse the repository at this point in the history
  • Loading branch information
arlosi committed Aug 18, 2022
1 parent 981ac9b commit a7da4a1
Show file tree
Hide file tree
Showing 6 changed files with 15 additions and 15 deletions.
4 changes: 2 additions & 2 deletions src/downloads_counter.rs
Original file line number Diff line number Diff line change
Expand Up @@ -247,7 +247,7 @@ mod tests {
use crate::models::{Crate, NewCrate, NewUser, NewVersion, User};
use diesel::PgConnection;
use semver::Version;
use std::collections::HashMap;
use std::collections::BTreeMap;

#[test]
fn test_increment_and_persist_all() {
Expand Down Expand Up @@ -452,7 +452,7 @@ mod tests {
let version = NewVersion::new(
self.krate.id,
&Version::parse(&format!("{}.0.0", self.next_version)).unwrap(),
&HashMap::new(),
&BTreeMap::new(),
None,
None,
0,
Expand Down
4 changes: 2 additions & 2 deletions src/models/version.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
use std::collections::HashMap;
use std::collections::BTreeMap;

use chrono::NaiveDateTime;
use diesel::prelude::*;
Expand Down Expand Up @@ -129,7 +129,7 @@ impl NewVersion {
pub fn new(
crate_id: i32,
num: &semver::Version,
features: &HashMap<String, Vec<String>>,
features: &BTreeMap<String, Vec<String>>,
license: Option<String>,
license_file: Option<&str>,
crate_size: i32,
Expand Down
6 changes: 3 additions & 3 deletions src/tests/builders/publish.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
use cargo_registry::views::krate_publish as u;
use std::{collections::HashMap, io::Read};
use std::{collections::BTreeMap, collections::HashMap, io::Read};

use flate2::{write::GzEncoder, Compression};
use once_cell::sync::Lazy;
Expand Down Expand Up @@ -36,7 +36,7 @@ pub struct PublishBuilder {
readme: Option<String>,
tarball: Vec<u8>,
version: semver::Version,
features: HashMap<u::EncodableFeatureName, Vec<u::EncodableFeature>>,
features: BTreeMap<u::EncodableFeatureName, Vec<u::EncodableFeature>>,
}

impl PublishBuilder {
Expand All @@ -56,7 +56,7 @@ impl PublishBuilder {
readme: None,
tarball: EMPTY_TARBALL_BYTES.to_vec(),
version: semver::Version::parse("1.0.0").unwrap(),
features: HashMap::new(),
features: BTreeMap::new(),
}
}

Expand Down
6 changes: 3 additions & 3 deletions src/tests/builders/version.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ use cargo_registry::{
schema::{dependencies, versions},
util::errors::AppResult,
};
use std::collections::HashMap;
use std::collections::BTreeMap;

use chrono::NaiveDateTime;
use diesel::prelude::*;
Expand All @@ -12,7 +12,7 @@ use diesel::prelude::*;
pub struct VersionBuilder<'a> {
created_at: Option<NaiveDateTime>,
dependencies: Vec<(i32, Option<&'static str>)>,
features: HashMap<String, Vec<String>>,
features: BTreeMap<String, Vec<String>>,
license: Option<&'a str>,
license_file: Option<&'a str>,
num: semver::Version,
Expand All @@ -37,7 +37,7 @@ impl<'a> VersionBuilder<'a> {
VersionBuilder {
created_at: None,
dependencies: Vec::new(),
features: HashMap::new(),
features: BTreeMap::new(),
license: None,
license_file: None,
num,
Expand Down
6 changes: 3 additions & 3 deletions src/views/krate_publish.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
//! and manages the serialising and deserialising of this information
//! to and from structs. The serlializing is only utilised in
//! integration tests.
use std::collections::HashMap;
use std::collections::{BTreeMap, HashMap};

use serde::{de, Deserialize, Deserializer, Serialize, Serializer};

Expand All @@ -17,7 +17,7 @@ pub struct EncodableCrateUpload {
pub name: EncodableCrateName,
pub vers: EncodableCrateVersion,
pub deps: Vec<EncodableCrateDependency>,
pub features: HashMap<EncodableFeatureName, Vec<EncodableFeature>>,
pub features: BTreeMap<EncodableFeatureName, Vec<EncodableFeature>>,
pub description: Option<String>,
pub homepage: Option<String>,
pub documentation: Option<String>,
Expand Down Expand Up @@ -53,7 +53,7 @@ pub struct EncodableCategoryList(pub Vec<EncodableCategory>);
pub struct EncodableCategory(pub String);
#[derive(Serialize, Debug, Deref)]
pub struct EncodableFeature(pub String);
#[derive(PartialEq, Eq, Hash, Serialize, Debug, Deref)]
#[derive(PartialEq, Eq, PartialOrd, Ord, Hash, Serialize, Debug, Deref)]
pub struct EncodableFeatureName(pub String);

#[derive(Serialize, Deserialize, Debug)]
Expand Down
4 changes: 2 additions & 2 deletions src/worker/update_downloads.rs
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,7 @@ mod test {
use super::*;
use crate::email::Emails;
use crate::models::{Crate, NewCrate, NewUser, NewVersion, User, Version};
use std::collections::HashMap;
use std::collections::BTreeMap;

fn user(conn: &PgConnection) -> User {
NewUser::new(2, "login", None, None, "access_token")
Expand All @@ -103,7 +103,7 @@ mod test {
let version = NewVersion::new(
krate.id,
&semver::Version::parse("1.0.0").unwrap(),
&HashMap::new(),
&BTreeMap::new(),
None,
None,
0,
Expand Down

0 comments on commit a7da4a1

Please sign in to comment.