Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

EncodableCrateUpload: Remove obsolete badges field #5431

Merged
merged 1 commit into from
Nov 6, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 1 addition & 10 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::BTreeMap, collections::HashMap, io::Read};
use std::{collections::BTreeMap, io::Read};

use flate2::{write::GzEncoder, Compression};
use once_cell::sync::Lazy;
Expand All @@ -24,7 +24,6 @@ fn generate_empty_tarball() -> Vec<u8> {
/// a crate to exist and don't need to test behavior caused by the publish request, inserting
/// a crate into the database directly by using CrateBuilder will be faster.
pub struct PublishBuilder {
badges: HashMap<String, HashMap<String, String>>,
categories: Vec<String>,
deps: Vec<u::EncodableCrateDependency>,
desc: Option<String>,
Expand All @@ -44,7 +43,6 @@ impl PublishBuilder {
/// in its tarball.
pub fn new(krate_name: &str) -> Self {
PublishBuilder {
badges: HashMap::new(),
categories: vec![],
deps: vec![],
desc: Some("description".to_string()),
Expand Down Expand Up @@ -150,12 +148,6 @@ impl PublishBuilder {
self
}

/// Add badges to this crate.
pub fn badges(mut self, badges: HashMap<String, HashMap<String, String>>) -> Self {
self.badges = badges;
self
}

/// Remove the license from this crate. Publish will fail unless license or license file is set.
pub fn unset_license(mut self) -> Self {
self.license = None;
Expand Down Expand Up @@ -202,7 +194,6 @@ impl PublishBuilder {
license: self.license,
license_file: self.license_file,
repository: None,
badges: Some(self.badges),
links: None,
};

Expand Down
53 changes: 1 addition & 52 deletions src/tests/krate/publish.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ use diesel::{delete, update, ExpressionMethods, QueryDsl, RunQueryDsl};
use flate2::write::GzEncoder;
use flate2::Compression;
use http::StatusCode;
use std::collections::{BTreeMap, HashMap};
use std::collections::BTreeMap;
use std::io::Read;
use std::iter::FromIterator;
use std::time::Duration;
Expand Down Expand Up @@ -781,57 +781,6 @@ fn ignored_categories() {
assert_eq!(json.warnings.invalid_categories, vec!["bar"]);
}

#[test]
fn good_badges() {
let (_, anon, _, token) = TestApp::full().with_token();

let mut badges = HashMap::new();
let mut badge_attributes = HashMap::new();
badge_attributes.insert(
String::from("repository"),
String::from("rust-lang/crates.io"),
);
badges.insert(String::from("travis-ci"), badge_attributes);

let crate_to_publish = PublishBuilder::new("foobadger").badges(badges);

let json = token.publish_crate(crate_to_publish).good();
assert_eq!(json.krate.name, "foobadger");
assert_eq!(json.krate.max_version, "1.0.0");

let json = anon.show_crate("foobadger");
let badges = json.krate.badges.unwrap();
assert_eq!(badges.len(), 0);
}

#[test]
fn ignored_badges() {
let (_, anon, _, token) = TestApp::full().with_token();

let mut badges = HashMap::new();

// Known badge type, missing required repository attribute
let mut badge_attributes = HashMap::new();
badge_attributes.insert(String::from("branch"), String::from("master"));
badges.insert(String::from("travis-ci"), badge_attributes);

// Unknown badge type
let mut unknown_badge_attributes = HashMap::new();
unknown_badge_attributes.insert(String::from("repository"), String::from("rust-lang/rust"));
badges.insert(String::from("not-a-badge"), unknown_badge_attributes);

let crate_to_publish = PublishBuilder::new("foo_ignored_badge").badges(badges);

let json = token.publish_crate(crate_to_publish).good();
assert_eq!(json.krate.name, "foo_ignored_badge");
assert_eq!(json.krate.max_version, "1.0.0");
assert_eq!(json.warnings.invalid_badges.len(), 0);

let json = anon.show_crate("foo_ignored_badge");
let badges = json.krate.badges.unwrap();
assert_eq!(badges.len(), 0);
}

#[test]
fn license_and_description_required() {
let (_, _, _, token) = TestApp::full().with_token();
Expand Down
3 changes: 1 addition & 2 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::{BTreeMap, HashMap};
use std::collections::BTreeMap;

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

Expand Down Expand Up @@ -30,7 +30,6 @@ pub struct EncodableCrateUpload {
pub license: Option<String>,
pub license_file: Option<String>,
pub repository: Option<String>,
pub badges: Option<HashMap<String, HashMap<String, String>>>,
#[serde(default)]
pub links: Option<String>,
}
Expand Down