Skip to content

Commit

Permalink
tests/publish: Add has_lib and bin_names test case
Browse files Browse the repository at this point in the history
  • Loading branch information
Turbo87 committed Jul 3, 2024
1 parent 3dcd216 commit 4d3342d
Show file tree
Hide file tree
Showing 3 changed files with 119 additions and 0 deletions.
28 changes: 28 additions & 0 deletions src/tests/krate/publish/manifest.rs
Original file line number Diff line number Diff line change
Expand Up @@ -144,3 +144,31 @@ async fn invalid_rust_version() {
assert_eq!(response.status(), StatusCode::BAD_REQUEST);
assert_json_snapshot!(response.json());
}

#[tokio::test(flavor = "multi_thread")]
async fn test_lib_and_bin_crate() {
let (_app, _anon, _cookie, token) = TestApp::full().with_token();

let publish_builder = PublishBuilder::new("foo", "1.0.0")
.add_file("foo-1.0.0/src/lib.rs", "pub fn foo() {}")
.add_file("foo-1.0.0/src/main.rs", "fn main() {}")
.add_file("foo-1.0.0/src/bin/bar.rs", "fn main() {}");

let response = token.publish_crate(publish_builder).await;
assert_eq!(response.status(), StatusCode::OK);
assert_json_snapshot!(response.json(), {
".crate.created_at" => "[datetime]",
".crate.updated_at" => "[datetime]",
});

let response = token.get::<()>("/api/v1/crates/foo/1.0.0").await;
assert_eq!(response.status(), StatusCode::OK);
assert_json_snapshot!(response.json(), {
".version.id" => any_id_redaction(),
".version.created_at" => "[datetime]",
".version.updated_at" => "[datetime]",
".version.published_by.id" => id_redaction(token.as_model().user_id),
".version.audit_actions[].time" => "[datetime]",
".version.audit_actions[].user.id" => id_redaction(token.as_model().user_id),
});
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
---
source: src/tests/krate/publish/manifest.rs
expression: response.json()
---
{
"version": {
"audit_actions": [
{
"action": "publish",
"time": "[datetime]",
"user": {
"avatar": null,
"id": "[id]",
"login": "foo",
"name": null,
"url": "https://github.com/foo"
}
}
],
"bin_names": [
"bar",
"foo"
],
"checksum": "ed125a8d83193391762787872f6363ef11d472fe9e963b984a761f970d63a7a8",
"crate": "foo",
"crate_size": 241,
"created_at": "[datetime]",
"dl_path": "/api/v1/crates/foo/1.0.0/download",
"downloads": 0,
"features": {},
"has_lib": true,
"id": "[id]",
"license": "MIT",
"links": {
"authors": "/api/v1/crates/foo/1.0.0/authors",
"dependencies": "/api/v1/crates/foo/1.0.0/dependencies",
"version_downloads": "/api/v1/crates/foo/1.0.0/downloads"
},
"num": "1.0.0",
"published_by": {
"avatar": null,
"id": "[id]",
"login": "foo",
"name": null,
"url": "https://github.com/foo"
},
"readme_path": "/api/v1/crates/foo/1.0.0/readme",
"rust_version": null,
"updated_at": "[datetime]",
"yanked": false
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
---
source: src/tests/krate/publish/manifest.rs
expression: response.json()
---
{
"crate": {
"badges": null,
"categories": null,
"created_at": "[datetime]",
"description": "description",
"documentation": null,
"downloads": 0,
"exact_match": false,
"homepage": null,
"id": "foo",
"keywords": null,
"links": {
"owner_team": "/api/v1/crates/foo/owner_team",
"owner_user": "/api/v1/crates/foo/owner_user",
"owners": "/api/v1/crates/foo/owners",
"reverse_dependencies": "/api/v1/crates/foo/reverse_dependencies",
"version_downloads": "/api/v1/crates/foo/downloads",
"versions": "/api/v1/crates/foo/versions"
},
"max_stable_version": "1.0.0",
"max_version": "1.0.0",
"name": "foo",
"newest_version": "1.0.0",
"recent_downloads": null,
"repository": null,
"updated_at": "[datetime]",
"versions": null
},
"warnings": {
"invalid_badges": [],
"invalid_categories": [],
"other": []
}
}

0 comments on commit 4d3342d

Please sign in to comment.