Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 738a482

Browse files
authored
Merge pull request #7123 from Turbo87/publish-tests
Add more tests for the publish workflow
2 parents f0c8f5e + fa6e30b commit 738a482

15 files changed

+244
-0
lines changed

src/tests/krate/publish/categories.rs

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
use crate::builders::PublishBuilder;
22
use crate::new_category;
33
use crate::util::{RequestHelper, TestApp};
4+
use http::StatusCode;
5+
use insta::assert_json_snapshot;
46

57
#[test]
68
fn good_categories() {
@@ -31,3 +33,21 @@ fn ignored_categories() {
3133
assert_eq!(json.krate.max_version, "1.0.0");
3234
assert_eq!(json.warnings.invalid_categories, vec!["bar"]);
3335
}
36+
37+
#[test]
38+
fn too_many_categories() {
39+
let (app, _, _, token) = TestApp::full().with_token();
40+
41+
let response = token.publish_crate(
42+
PublishBuilder::new("foo", "1.0.0")
43+
.category("one")
44+
.category("two")
45+
.category("three")
46+
.category("four")
47+
.category("five")
48+
.category("six"),
49+
);
50+
assert_eq!(response.status(), StatusCode::OK);
51+
assert_json_snapshot!(response.into_json());
52+
assert!(app.stored_files().is_empty());
53+
}

src/tests/krate/publish/dependencies.rs

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
use crate::builders::{CrateBuilder, DependencyBuilder, PublishBuilder};
22
use crate::util::{RequestHelper, TestApp};
33
use http::StatusCode;
4+
use insta::assert_json_snapshot;
45

56
#[test]
67
fn new_with_renamed_dependency() {
@@ -25,6 +26,24 @@ fn new_with_renamed_dependency() {
2526
assert_eq!(crates[0].deps[0].package.as_ref().unwrap(), "package-name");
2627
}
2728

29+
#[test]
30+
fn invalid_dependency_rename() {
31+
let (app, _, user, token) = TestApp::full().with_token();
32+
33+
app.db(|conn| {
34+
// Insert a crate directly into the database so that new-krate can depend on it
35+
CrateBuilder::new("package-name", user.as_model().id).expect_build(conn);
36+
});
37+
38+
let response = token.publish_crate(
39+
PublishBuilder::new("new-krate", "1.0.0")
40+
.dependency(DependencyBuilder::new("package-name").rename("💩")),
41+
);
42+
assert_eq!(response.status(), StatusCode::OK);
43+
assert_json_snapshot!(response.into_json());
44+
assert!(app.stored_files().is_empty());
45+
}
46+
2847
#[test]
2948
fn new_with_underscore_renamed_dependency() {
3049
let (app, _, user, token) = TestApp::full().with_token();

src/tests/krate/publish/features.rs

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
use crate::builders::{CrateBuilder, DependencyBuilder, PublishBuilder};
22
use crate::util::{RequestHelper, TestApp};
3+
use http::StatusCode;
4+
use insta::assert_json_snapshot;
35
use std::collections::BTreeMap;
46

57
#[test]
@@ -32,3 +34,25 @@ fn features_version_2() {
3234
)]);
3335
assert_eq!(crates[0].features2, Some(features2));
3436
}
37+
38+
#[test]
39+
fn invalid_feature_name() {
40+
let (app, _, _, token) = TestApp::full().with_token();
41+
42+
let crate_to_publish = PublishBuilder::new("foo", "1.0.0").feature("~foo", &[]);
43+
let response = token.publish_crate(crate_to_publish);
44+
assert_eq!(response.status(), StatusCode::OK);
45+
assert_json_snapshot!(response.into_json());
46+
assert!(app.stored_files().is_empty());
47+
}
48+
49+
#[test]
50+
fn invalid_feature() {
51+
let (app, _, _, token) = TestApp::full().with_token();
52+
53+
let crate_to_publish = PublishBuilder::new("foo", "1.0.0").feature("foo", &["!bar"]);
54+
let response = token.publish_crate(crate_to_publish);
55+
assert_eq!(response.status(), StatusCode::OK);
56+
assert_json_snapshot!(response.into_json());
57+
assert!(app.stored_files().is_empty());
58+
}

src/tests/krate/publish/keywords.rs

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
use crate::builders::PublishBuilder;
22
use crate::util::{RequestHelper, TestApp};
33
use http::StatusCode;
4+
use insta::assert_json_snapshot;
45

56
#[test]
67
fn good_keywords() {
@@ -42,3 +43,20 @@ fn bad_keywords() {
4243
json!({ "errors": [{ "detail": "invalid upload request: invalid value: string \"áccênts\", expected a valid keyword specifier at line 1 column 183" }] })
4344
);
4445
}
46+
47+
#[test]
48+
fn too_many_keywords() {
49+
let (app, _, _, token) = TestApp::full().with_token();
50+
let response = token.publish_crate(
51+
PublishBuilder::new("foo", "1.0.0")
52+
.keyword("one")
53+
.keyword("two")
54+
.keyword("three")
55+
.keyword("four")
56+
.keyword("five")
57+
.keyword("six"),
58+
);
59+
assert_eq!(response.status(), StatusCode::OK);
60+
assert_json_snapshot!(response.into_json());
61+
assert!(app.stored_files().is_empty());
62+
}

src/tests/krate/publish/manifest.rs

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ use crate::builders::PublishBuilder;
22
use crate::util::{RequestHelper, TestApp};
33
use crates_io_tarball::TarballBuilder;
44
use http::StatusCode;
5+
use insta::assert_json_snapshot;
56

67
#[test]
78
fn boolean_readme() {
@@ -42,6 +43,42 @@ fn missing_manifest() {
4243
);
4344
}
4445

46+
#[test]
47+
fn manifest_casing() {
48+
let (_app, _anon, _cookie, token) = TestApp::full().with_token();
49+
50+
let tarball = TarballBuilder::new("foo", "1.0.0")
51+
.add_file(
52+
"foo-1.0.0/CARGO.TOML",
53+
b"[package]\nname = \"foo\"\nversion = \"1.0.0\"\n",
54+
)
55+
.build();
56+
57+
let response = token.publish_crate(PublishBuilder::new("foo", "1.0.0").tarball(tarball));
58+
assert_eq!(response.status(), StatusCode::OK);
59+
assert_json_snapshot!(response.into_json());
60+
}
61+
62+
#[test]
63+
fn multiple_manifests() {
64+
let (_app, _anon, _cookie, token) = TestApp::full().with_token();
65+
66+
let tarball = TarballBuilder::new("foo", "1.0.0")
67+
.add_file(
68+
"foo-1.0.0/Cargo.toml",
69+
b"[package]\nname = \"foo\"\nversion = \"1.0.0\"\n",
70+
)
71+
.add_file(
72+
"foo-1.0.0/cargo.toml",
73+
b"[package]\nname = \"foo\"\nversion = \"1.0.0\"\n",
74+
)
75+
.build();
76+
77+
let response = token.publish_crate(PublishBuilder::new("foo", "1.0.0").tarball(tarball));
78+
assert_eq!(response.status(), StatusCode::OK);
79+
assert_json_snapshot!(response.into_json());
80+
}
81+
4582
#[test]
4683
fn invalid_manifest() {
4784
let (_app, _anon, _cookie, token) = TestApp::full().with_token();
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
---
2+
source: src/tests/krate/publish/categories.rs
3+
expression: response.into_json()
4+
---
5+
{
6+
"errors": [
7+
{
8+
"detail": "invalid upload request: invalid length 6, expected at most 5 categories per crate at line 1 column 219"
9+
}
10+
]
11+
}
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
---
2+
source: src/tests/krate/publish/dependencies.rs
3+
expression: response.into_json()
4+
---
5+
{
6+
"errors": [
7+
{
8+
"detail": "invalid upload request: invalid value: string \"💩\", expected a valid dependency name to start with a letter or underscore, contain only letters, numbers, hyphens, or underscores and have at most 64 characters at line 1 column 197"
9+
}
10+
]
11+
}
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
---
2+
source: src/tests/krate/publish/features.rs
3+
expression: response.into_json()
4+
---
5+
{
6+
"errors": [
7+
{
8+
"detail": "invalid upload request: invalid value: string \"!bar\", expected a valid feature name at line 1 column 65"
9+
}
10+
]
11+
}
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
---
2+
source: src/tests/krate/publish/features.rs
3+
expression: response.into_json()
4+
---
5+
{
6+
"errors": [
7+
{
8+
"detail": "invalid upload request: invalid value: string \"~foo\", expected a valid feature name containing only letters, numbers, '-', '+', or '_' at line 1 column 57"
9+
}
10+
]
11+
}
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
---
2+
source: src/tests/krate/publish/keywords.rs
3+
expression: response.into_json()
4+
---
5+
{
6+
"errors": [
7+
{
8+
"detail": "invalid upload request: invalid length 6, expected at most 5 keywords per crate at line 1 column 203"
9+
}
10+
]
11+
}

0 commit comments

Comments
 (0)