Skip to content

PublishBuilder: Provide version upfront #6893

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

Merged
merged 1 commit into from
Jul 27, 2023
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
14 changes: 4 additions & 10 deletions src/tests/builders/publish.rs
Original file line number Diff line number Diff line change
Expand Up @@ -25,9 +25,9 @@ pub struct PublishBuilder {
}

impl PublishBuilder {
/// Create a request to publish a crate with the given name, version 1.0.0, and no files
/// Create a request to publish a crate with the given name and version, and no files
/// in its tarball.
pub fn new(krate_name: &str) -> Self {
pub fn new(krate_name: &str, version: &str) -> Self {
PublishBuilder {
categories: vec![],
deps: vec![],
Expand All @@ -38,18 +38,12 @@ impl PublishBuilder {
license: Some("MIT".to_string()),
license_file: None,
readme: None,
tarball: TarballBuilder::new(krate_name, "1.0.0").build(),
version: semver::Version::parse("1.0.0").unwrap(),
tarball: TarballBuilder::new(krate_name, version).build(),
version: semver::Version::parse(version).unwrap(),
features: BTreeMap::new(),
}
}

/// Set the version of the crate being published to something other than the default of 1.0.0.
pub fn version(mut self, version: &str) -> Self {
self.version = semver::Version::parse(version).unwrap();
self
}

/// Set the files in the crate's tarball.
pub fn files(mut self, files: &[(&str, &[u8])]) -> Self {
let mut tarball = Vec::new();
Expand Down
149 changes: 61 additions & 88 deletions src/tests/krate/publish.rs

Large diffs are not rendered by default.

10 changes: 5 additions & 5 deletions src/tests/krate/yanking.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ fn yank_works_as_intended() {
let (app, anon, cookie, token) = TestApp::full().with_token();

// Upload a new crate, putting it in the git index
let crate_to_publish = PublishBuilder::new("fyk");
let crate_to_publish = PublishBuilder::new("fyk", "1.0.0");
token.publish_crate(crate_to_publish).good();

let crates = app.crates_from_index_head("fyk");
Expand Down Expand Up @@ -65,15 +65,15 @@ fn yank_max_version() {
let (_, anon, _, token) = TestApp::full().with_token();

// Upload a new crate
let crate_to_publish = PublishBuilder::new("fyk_max");
let crate_to_publish = PublishBuilder::new("fyk_max", "1.0.0");
token.publish_crate(crate_to_publish).good();

// double check the max version
let json = anon.show_crate("fyk_max");
assert_eq!(json.krate.max_version, "1.0.0");

// add version 2.0.0
let crate_to_publish = PublishBuilder::new("fyk_max").version("2.0.0");
let crate_to_publish = PublishBuilder::new("fyk_max", "2.0.0");
let json = token.publish_crate(crate_to_publish).good();
assert_eq!(json.krate.max_version, "2.0.0");

Expand Down Expand Up @@ -119,7 +119,7 @@ fn publish_after_yank_max_version() {
let (_, anon, _, token) = TestApp::full().with_token();

// Upload a new crate
let crate_to_publish = PublishBuilder::new("fyk_max");
let crate_to_publish = PublishBuilder::new("fyk_max", "1.0.0");
token.publish_crate(crate_to_publish).good();

// double check the max version
Expand All @@ -133,7 +133,7 @@ fn publish_after_yank_max_version() {
assert_eq!(json.krate.max_version, "0.0.0");

// add version 2.0.0
let crate_to_publish = PublishBuilder::new("fyk_max").version("2.0.0");
let crate_to_publish = PublishBuilder::new("fyk_max", "2.0.0");
let json = token.publish_crate(crate_to_publish).good();
assert_eq!(json.krate.max_version, "2.0.0");

Expand Down
4 changes: 2 additions & 2 deletions src/tests/owners.rs
Original file line number Diff line number Diff line change
Expand Up @@ -136,7 +136,7 @@ fn new_crate_owner() {
let (app, _, _, token) = TestApp::full().with_token();

// Create a crate under one user
let crate_to_publish = PublishBuilder::new("foo_owner").version("1.0.0");
let crate_to_publish = PublishBuilder::new("foo_owner", "1.0.0");
token.publish_crate(crate_to_publish).good();

// Add the second user as an owner (with a different case to make sure that works)
Expand All @@ -152,7 +152,7 @@ fn new_crate_owner() {
assert_eq!(crates.crates.len(), 1);

// And upload a new version as the second user
let crate_to_publish = PublishBuilder::new("foo_owner").version("2.0.0");
let crate_to_publish = PublishBuilder::new("foo_owner", "2.0.0");
user2
.db_new_token("bar_token")
.publish_crate(crate_to_publish)
Expand Down
5 changes: 2 additions & 3 deletions src/tests/routes/crates/new.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,12 +7,11 @@ fn daily_limit() {

let max_daily_versions = app.as_inner().config.new_version_rate_limit.unwrap();
for version in 1..=max_daily_versions {
let crate_to_publish =
PublishBuilder::new("foo_daily_limit").version(&format!("0.0.{version}"));
let crate_to_publish = PublishBuilder::new("foo_daily_limit", &format!("0.0.{version}"));
user.publish_crate(crate_to_publish).good();
}

let crate_to_publish = PublishBuilder::new("foo_daily_limit").version("1.0.0");
let crate_to_publish = PublishBuilder::new("foo_daily_limit", "1.0.0");
let response = user.publish_crate(crate_to_publish);
assert!(response.status().is_success());
let json = response.into_json();
Expand Down
6 changes: 2 additions & 4 deletions src/tests/routes/crates/read.rs
Original file line number Diff line number Diff line change
Expand Up @@ -120,14 +120,12 @@ fn show_minimal() {
fn version_size() {
let (_, _, user) = TestApp::full().with_user();

let crate_to_publish = PublishBuilder::new("foo_version_size").version("1.0.0");
let crate_to_publish = PublishBuilder::new("foo_version_size", "1.0.0");
user.publish_crate(crate_to_publish).good();

// Add a file to version 2 so that it's a different size than version 1
let files = [("foo_version_size-2.0.0/big", &[b'a'; 1] as &[_])];
let crate_to_publish = PublishBuilder::new("foo_version_size")
.version("2.0.0")
.files(&files);
let crate_to_publish = PublishBuilder::new("foo_version_size", "2.0.0").files(&files);
user.publish_crate(crate_to_publish).good();

let crate_json = user.show_crate("foo_version_size");
Expand Down
6 changes: 3 additions & 3 deletions src/tests/routes/crates/versions/yank_unyank.rs
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ fn yank_records_an_audit_action() {
let (_, anon, _, token) = TestApp::full().with_token();

// Upload a new crate, putting it in the git index
let crate_to_publish = PublishBuilder::new("fyk");
let crate_to_publish = PublishBuilder::new("fyk", "1.0.0");
token.publish_crate(crate_to_publish).good();

// Yank it
Expand All @@ -73,7 +73,7 @@ fn unyank_records_an_audit_action() {
let (_, anon, _, token) = TestApp::full().with_token();

// Upload a new crate
let crate_to_publish = PublishBuilder::new("fyk");
let crate_to_publish = PublishBuilder::new("fyk", "1.0.0");
token.publish_crate(crate_to_publish).good();

// Yank version 1.0.0
Expand Down Expand Up @@ -104,7 +104,7 @@ mod auth {
fn prepare() -> (TestApp, MockAnonymousUser, MockCookieUser) {
let (app, anon, cookie) = TestApp::full().with_user();

let pb = PublishBuilder::new(CRATE_NAME).version(CRATE_VERSION);
let pb = PublishBuilder::new(CRATE_NAME, CRATE_VERSION);
cookie.publish_crate(pb).good();

(app, anon, cookie)
Expand Down
8 changes: 4 additions & 4 deletions src/tests/team.rs
Original file line number Diff line number Diff line change
Expand Up @@ -222,7 +222,7 @@ fn remove_team_as_named_owner() {
.good();

let user_on_one_team = app.db_new_user("user-one-team");
let crate_to_publish = PublishBuilder::new("foo_remove_team").version("2.0.0");
let crate_to_publish = PublishBuilder::new("foo_remove_team", "2.0.0");
let response = user_on_one_team.publish_crate(crate_to_publish);
assert_eq!(response.status(), StatusCode::OK);
assert_eq!(
Expand Down Expand Up @@ -285,7 +285,7 @@ fn publish_not_owned() {

let user_on_one_team = app.db_new_user("user-one-team");

let crate_to_publish = PublishBuilder::new("foo_not_owned").version("2.0.0");
let crate_to_publish = PublishBuilder::new("foo_not_owned", "2.0.0");
let response = user_on_one_team.publish_crate(crate_to_publish);
assert_eq!(response.status(), StatusCode::OK);
assert_eq!(
Expand All @@ -310,7 +310,7 @@ fn publish_org_owner_owned() {

let user_org_owner = app.db_new_user("user-org-owner");

let crate_to_publish = PublishBuilder::new("foo_not_owned").version("2.0.0");
let crate_to_publish = PublishBuilder::new("foo_not_owned", "2.0.0");
let response = user_org_owner.publish_crate(crate_to_publish);
assert_eq!(response.status(), StatusCode::OK);
assert_eq!(
Expand All @@ -336,7 +336,7 @@ fn publish_owned() {

let user_on_one_team = app.db_new_user("user-one-team");

let crate_to_publish = PublishBuilder::new("foo_team_owned").version("2.0.0");
let crate_to_publish = PublishBuilder::new("foo_team_owned", "2.0.0");
user_on_one_team.publish_crate(crate_to_publish).good();
}

Expand Down
2 changes: 1 addition & 1 deletion src/tests/worker/git.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ fn index_smoke_test() {

// Add a new crate

let body = PublishBuilder::new("serde").version("1.0.0").body();
let body = PublishBuilder::new("serde", "1.0.0").body();
let response = token.put::<()>("/api/v1/crates/new", &body);
assert_eq!(response.status(), StatusCode::OK);

Expand Down