Skip to content

Commit b068a80

Browse files
committed
Add test for generating index files from the database
1 parent fa98cff commit b068a80

File tree

3 files changed

+88
-0
lines changed

3 files changed

+88
-0
lines changed
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,62 @@
1+
[
2+
{
3+
"request": {
4+
"uri": "http://alexcrichton-test.s3.amazonaws.com/crates/foo_new/foo_new-1.0.0.crate",
5+
"method": "PUT",
6+
"headers": [
7+
[
8+
"accept",
9+
"*/*"
10+
],
11+
[
12+
"accept-encoding",
13+
"gzip"
14+
],
15+
[
16+
"content-length",
17+
"35"
18+
],
19+
[
20+
"content-type",
21+
"application/gzip"
22+
]
23+
],
24+
"body": "H4sIAAAAAAAA/+3AAQEAAACCIP+vbkhQwKsBLq+17wAEAAA="
25+
},
26+
"response": {
27+
"status": 200,
28+
"headers": [],
29+
"body": ""
30+
}
31+
},
32+
{
33+
"request": {
34+
"uri": "http://alexcrichton-test.s3.amazonaws.com/fo/o_/foo_new",
35+
"method": "PUT",
36+
"headers": [
37+
[
38+
"accept",
39+
"*/*"
40+
],
41+
[
42+
"accept-encoding",
43+
"gzip"
44+
],
45+
[
46+
"content-length",
47+
"161"
48+
],
49+
[
50+
"content-type",
51+
"text/plain"
52+
]
53+
],
54+
"body": "eyJuYW1lIjoiZm9vX25ldyIsInZlcnMiOiIxLjAuMCIsImRlcHMiOltdLCJja3N1bSI6ImFjYjU2MDRiMTI2YWM4OTRjMWViMTFjNDU3NWJmMjA3MmZlYTYxMjMyYTg4OGU0NTM3NzBjNzlkN2VkNTY0MTkiLCJmZWF0dXJlcyI6e30sInlhbmtlZCI6ZmFsc2UsImxpbmtzIjpudWxsfQo="
55+
},
56+
"response": {
57+
"status": 200,
58+
"headers": [],
59+
"body": ""
60+
}
61+
}
62+
]

src/tests/krate/publish.rs

+18
Original file line numberDiff line numberDiff line change
@@ -123,6 +123,24 @@ fn new_krate() {
123123
assert_eq!(json.krate.max_version, "1.0.0");
124124
}
125125

126+
#[test]
127+
fn sparse_index() {
128+
let (_, _, user) = TestApp::full().with_user();
129+
130+
let crate_to_publish = PublishBuilder::new("foo_new").version("1.0.0");
131+
user.publish_crate(crate_to_publish).good();
132+
133+
let response: crate::util::Response<String> = user.get("/api/private/index/fo/o_/foo_new");
134+
assert_eq!(response.status(), StatusCode::OK);
135+
let body = std::str::from_utf8(response.body()).unwrap();
136+
137+
assert_eq!(
138+
body,
139+
r#"{"name":"foo_new","vers":"1.0.0","deps":[],"cksum":"acb5604b126ac894c1eb11c4575bf2072fea61232a888e453770c79d7ed56419","features":{},"yanked":false,"links":null}
140+
"#
141+
);
142+
}
143+
126144
#[test]
127145
fn new_krate_with_token() {
128146
let (_, _, _, token) = TestApp::full().with_token();

src/tests/util/response.rs

+8
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,14 @@ impl<T> Response<T> {
4646
self.response.status()
4747
}
4848

49+
pub fn body(&self) -> &[u8] {
50+
match self.response.body() {
51+
Body::Static(v) => v,
52+
Body::Owned(v) => v,
53+
Body::File(_) => unimplemented!(),
54+
}
55+
}
56+
4957
#[track_caller]
5058
pub fn assert_redirect_ends_with(&self, target: &str) -> &Self {
5159
assert!(self

0 commit comments

Comments
 (0)