1
+ //! Helpers for testing `cargo package` / `cargo publish`
2
+ //!
3
+ //! # Example
4
+ //!
5
+ //! ```no_run
6
+ //! # use cargo_test_support::registry::RegistryBuilder;
7
+ //! # use cargo_test_support::publish::validate_upload;
8
+ //! # use cargo_test_support::project;
9
+ //! // This replaces `registry::init()` and must be called before `Package::new().publish()`
10
+ //! let registry = RegistryBuilder::new().http_api().http_index().build();
11
+ //!
12
+ //! let p = project()
13
+ //! .file(
14
+ //! "Cargo.toml",
15
+ //! r#"
16
+ //! [package]
17
+ //! name = "foo"
18
+ //! version = "0.0.1"
19
+ //! edition = "2015"
20
+ //! authors = []
21
+ //! license = "MIT"
22
+ //! description = "foo"
23
+ //! "#,
24
+ //! )
25
+ //! .file("src/main.rs", "fn main() {}")
26
+ //! .build();
27
+ //!
28
+ //! p.cargo("publish --no-verify")
29
+ //! .replace_crates_io(registry.index_url())
30
+ //! .run();
31
+ //!
32
+ //! validate_upload(
33
+ //! r#"
34
+ //! {
35
+ //! "authors": [],
36
+ //! "badges": {},
37
+ //! "categories": [],
38
+ //! "deps": [],
39
+ //! "description": "foo",
40
+ //! "documentation": null,
41
+ //! "features": {},
42
+ //! "homepage": null,
43
+ //! "keywords": [],
44
+ //! "license": "MIT",
45
+ //! "license_file": null,
46
+ //! "links": null,
47
+ //! "name": "foo",
48
+ //! "readme": null,
49
+ //! "readme_file": null,
50
+ //! "repository": null,
51
+ //! "rust_version": null,
52
+ //! "vers": "0.0.1"
53
+ //! }
54
+ //! "#,
55
+ //! "foo-0.0.1.crate",
56
+ //! &["Cargo.lock", "Cargo.toml", "Cargo.toml.orig", "src/main.rs"],
57
+ //! );
58
+ //! ```
59
+
1
60
use crate :: compare:: { assert_match_exact, find_json_mismatch} ;
2
61
use crate :: registry:: { self , alt_api_path, FeatureMap } ;
3
62
use flate2:: read:: GzDecoder ;
17
76
Ok ( u32:: from_le_bytes ( buf) )
18
77
}
19
78
20
- /// Checks the result of a crate publish.
79
+ /// Check the `cargo publish` API call
21
80
pub fn validate_upload ( expected_json : & str , expected_crate_name : & str , expected_files : & [ & str ] ) {
22
81
let new_path = registry:: api_path ( ) . join ( "api/v1/crates/new" ) ;
23
82
_validate_upload (
@@ -29,7 +88,7 @@ pub fn validate_upload(expected_json: &str, expected_crate_name: &str, expected_
29
88
) ;
30
89
}
31
90
32
- /// Checks the result of a crate publish, along with the contents of the files.
91
+ /// Check the `cargo publish` API call, with file contents
33
92
pub fn validate_upload_with_contents (
34
93
expected_json : & str ,
35
94
expected_crate_name : & str ,
@@ -46,7 +105,7 @@ pub fn validate_upload_with_contents(
46
105
) ;
47
106
}
48
107
49
- /// Checks the result of a crate publish to an alternative registry.
108
+ /// Check the `cargo publish` API call to the alternative test registry
50
109
pub fn validate_alt_upload (
51
110
expected_json : & str ,
52
111
expected_crate_name : & str ,
0 commit comments