Skip to content

Commit

Permalink
Make some blocking tests non-blocking
Browse files Browse the repository at this point in the history
  • Loading branch information
hi-rustin committed Feb 15, 2023
1 parent 82c3bb7 commit 0c513e4
Show file tree
Hide file tree
Showing 3 changed files with 57 additions and 96 deletions.
123 changes: 48 additions & 75 deletions tests/testsuite/alt_registry.rs
Original file line number Diff line number Diff line change
Expand Up @@ -287,7 +287,12 @@ fn cannot_publish_to_crates_io_with_registry_dependency() {

#[cargo_test]
fn publish_with_registry_dependency() {
registry::alt_init();
let _reg = RegistryBuilder::new()
.http_api()
.http_index()
.alternative_named("alternative")
.build();

let p = project()
.file(
"Cargo.toml",
Expand All @@ -307,46 +312,26 @@ fn publish_with_registry_dependency() {

Package::new("bar", "0.0.1").alternative(true).publish();

// Login so that we have the token available
p.cargo("login --registry alternative TOKEN").run();

p.cargo("publish --registry alternative").run();

validate_alt_upload(
r#"{
"authors": [],
"badges": {},
"categories": [],
"deps": [
{
"default_features": true,
"features": [],
"kind": "normal",
"name": "bar",
"optional": false,
"target": null,
"version_req": "^0.0.1"
}
],
"description": null,
"documentation": null,
"features": {},
"homepage": null,
"keywords": [],
"license": null,
"license_file": null,
"links": null,
"name": "foo",
"readme": null,
"readme_file": null,
"repository": null,
"homepage": null,
"documentation": null,
"vers": "0.0.1"
}"#,
"foo-0.0.1.crate",
&["Cargo.lock", "Cargo.toml", "Cargo.toml.orig", "src/main.rs"],
);
p.cargo("publish --registry alternative")
.with_stderr(
"\
[UPDATING] `alternative` index
[WARNING] [..]
[..]
[PACKAGING] foo v0.0.1 [..]
[UPDATING] `alternative` index
[VERIFYING] foo v0.0.1 [..]
[DOWNLOADING] [..]
[DOWNLOADED] bar v0.0.1 (registry `alternative`)
[COMPILING] bar v0.0.1 (registry `alternative`)
[COMPILING] foo v0.0.1 [..]
[FINISHED] [..]
[PACKAGED] [..]
[UPLOADING] foo v0.0.1 [..]
[UPDATING] `alternative` index
",
)
.run();
}

#[cargo_test]
Expand Down Expand Up @@ -415,43 +400,31 @@ or use environment variable CARGO_REGISTRIES_ALTERNATIVE_TOKEN",

#[cargo_test]
fn publish_to_alt_registry() {
registry::alt_init();
let p = project().file("src/main.rs", "fn main() {}").build();

// Setup the registry by publishing a package
Package::new("bar", "0.0.1").alternative(true).publish();
let _reg = RegistryBuilder::new()
.http_api()
.http_index()
.alternative_named("alternative")
.build();

// Login so that we have the token available
p.cargo("login --registry alternative TOKEN").run();
let p = project().file("src/main.rs", "fn main() {}").build();

// Now perform the actual publish
p.cargo("publish --registry alternative").run();

validate_alt_upload(
r#"{
"authors": [],
"badges": {},
"categories": [],
"deps": [],
"description": null,
"documentation": null,
"features": {},
"homepage": null,
"keywords": [],
"license": null,
"license_file": null,
"links": null,
"name": "foo",
"readme": null,
"readme_file": null,
"repository": null,
"homepage": null,
"documentation": null,
"vers": "0.0.1"
}"#,
"foo-0.0.1.crate",
&["Cargo.lock", "Cargo.toml", "Cargo.toml.orig", "src/main.rs"],
);
p.cargo("publish --registry alternative")
.with_stderr(
"\
[UPDATING] `alternative` index
[WARNING] [..]
[..]
[PACKAGING] foo v0.0.1 [..]
[VERIFYING] foo v0.0.1 [..]
[COMPILING] foo v0.0.1 [..]
[FINISHED] [..]
[PACKAGED] [..]
[UPLOADING] foo v0.0.1 [..]
[UPDATING] `alternative` index
",
)
.run();
}

#[cargo_test]
Expand Down
12 changes: 4 additions & 8 deletions tests/testsuite/cargo_features.rs
Original file line number Diff line number Diff line change
Expand Up @@ -610,7 +610,10 @@ fn z_flags_rejected() {

#[cargo_test]
fn publish_allowed() {
let registry = registry::init();
let registry = registry::RegistryBuilder::new()
.http_api()
.http_index()
.build();

let p = project()
.file(
Expand All @@ -627,13 +630,6 @@ fn publish_allowed() {
.file("src/lib.rs", "")
.build();

// HACK: Inject `a` directly into the index so `publish` won't block for it to be in
// the index.
//
// This is to ensure we can verify the Summary we post to the registry as doing so precludes
// the registry from processing the publish.
Package::new("a", "0.0.1").file("src/lib.rs", "").publish();

p.cargo("publish")
.replace_crates_io(registry.index_url())
.masquerade_as_nightly_cargo(&["test-dummy-unstable"])
Expand Down
18 changes: 5 additions & 13 deletions tests/testsuite/credential_process.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
//! Tests for credential-process.

use cargo_test_support::registry::{Package, TestRegistry};
use cargo_test_support::registry::TestRegistry;
use cargo_test_support::{basic_manifest, cargo_process, paths, project, registry, Project};
use std::fs::{self, read_to_string};

Expand Down Expand Up @@ -69,6 +69,8 @@ or use environment variable CARGO_REGISTRIES_ALTERNATIVE_TOKEN
fn warn_both_token_and_process() {
// Specifying both credential-process and a token in config should issue a warning.
let _server = registry::RegistryBuilder::new()
.http_api()
.http_index()
.alternative()
.no_configure_token()
.build();
Expand All @@ -77,7 +79,7 @@ fn warn_both_token_and_process() {
".cargo/config",
r#"
[registries.alternative]
token = "sekrit"
token = "alternative-sekrit"
credential-process = "false"
"#,
)
Expand All @@ -96,16 +98,6 @@ fn warn_both_token_and_process() {
.file("src/lib.rs", "")
.build();

// HACK: Inject `foo` directly into the index so `publish` won't block for it to be in
// the index.
//
// This is to ensure we can verify the Summary we post to the registry as doing so precludes
// the registry from processing the publish.
Package::new("foo", "0.1.0")
.file("src/lib.rs", "")
.alternative(true)
.publish();

p.cargo("publish --no-verify --registry alternative -Z credential-process")
.masquerade_as_nightly_cargo(&["credential-process"])
.with_status(101)
Expand All @@ -127,7 +119,7 @@ Only one of these values may be set, remove one or the other to proceed.
credential-process = "false"
[registries.alternative]
token = "sekrit"
token = "alternative-sekrit"
"#,
);
p.cargo("publish --no-verify --registry alternative -Z credential-process")
Expand Down

0 comments on commit 0c513e4

Please sign in to comment.