Skip to content

Commit 20cf719

Browse files
committed
Update tests
1 parent 5c02bae commit 20cf719

40 files changed

+2833
-20
lines changed

cargo-registry-index/lib.rs

+23-6
Original file line numberDiff line numberDiff line change
@@ -359,18 +359,35 @@ impl Repository {
359359
}
360360

361361
/// Gets a list of files that have been modified since a given commit (or None for all files).
362-
pub fn get_files_modified_since(&self, starting_commit: Option<&str>) -> anyhow::Result<Vec<PathBuf>>{
362+
pub fn get_files_modified_since(
363+
&self,
364+
starting_commit: Option<&str>,
365+
) -> anyhow::Result<Vec<PathBuf>> {
363366
let starting_commit = match starting_commit {
364367
Some(starting_commit) => {
365-
let oid = git2::Oid::from_str(starting_commit).context("failed to parse commit into Oid")?;
366-
let commit = self.repository.find_commit(oid).context("failed to find commit")?;
367-
Some(commit.as_object().peel_to_tree().context("failed to find tree for commit")?)
368+
let oid = git2::Oid::from_str(starting_commit)
369+
.context("failed to parse commit into Oid")?;
370+
let commit = self
371+
.repository
372+
.find_commit(oid)
373+
.context("failed to find commit")?;
374+
Some(
375+
commit
376+
.as_object()
377+
.peel_to_tree()
378+
.context("failed to find tree for commit")?,
379+
)
368380
}
369381
None => None,
370382
};
371383

372-
let head = self.repository.find_commit(self.head_oid()?)?.as_object().peel_to_tree()?;
373-
let diff = self.repository
384+
let head = self
385+
.repository
386+
.find_commit(self.head_oid()?)?
387+
.as_object()
388+
.peel_to_tree()?;
389+
let diff = self
390+
.repository
374391
.diff_tree_to_tree(starting_commit.as_ref(), Some(&head), None)
375392
.context("failed to run diff")?;
376393
let mut files = Vec::new();

src/admin/mod.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -7,5 +7,5 @@ pub mod populate;
77
pub mod render_readmes;
88
pub mod test_pagerduty;
99
pub mod transfer_crates;
10-
pub mod verify_token;
1110
pub mod upload_index;
11+
pub mod verify_token;

src/admin/render_readmes.rs

+1-6
Original file line numberDiff line numberDiff line change
@@ -113,12 +113,7 @@ pub fn run(opts: Opts) -> anyhow::Result<()> {
113113

114114
base_config
115115
.uploader()
116-
.upload_readme(
117-
&client,
118-
&krate_name,
119-
&version.num,
120-
readme,
121-
)
116+
.upload_readme(&client, &krate_name, &version.num, readme)
122117
.context("Failed to upload rendered README file to S3")?;
123118

124119
Ok(())

src/admin/upload_index.rs

+50
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,50 @@
1+
use crate::admin::dialoguer;
2+
use cargo_registry_index::{Repository, RepositoryConfig};
3+
use reqwest::blocking::Client;
4+
5+
use crate::config;
6+
7+
#[derive(clap::Parser, Debug)]
8+
#[clap(
9+
name = "upload-index",
10+
about = "Upload index from git to S3 (http-based index)"
11+
)]
12+
pub struct Opts {
13+
/// Incremental commit. Any changed files made after this commit will be uploaded.
14+
incremental_commit: Option<String>,
15+
}
16+
17+
pub fn run(opts: Opts) -> anyhow::Result<()> {
18+
let config = config::Base::from_environment();
19+
let uploader = config.uploader();
20+
let client = Client::new();
21+
22+
println!("fetching git repo");
23+
let config = RepositoryConfig::from_environment();
24+
let repo = Repository::open(&config)?;
25+
repo.reset_head()?;
26+
println!("HEAD is at {}", repo.head_oid()?);
27+
28+
let files = repo.get_files_modified_since(opts.incremental_commit.as_deref())?;
29+
println!("found {} files to upload", files.len());
30+
if !dialoguer::confirm("continue with upload?") {
31+
return Ok(());
32+
}
33+
34+
for file in files {
35+
let crate_name = file.file_name().unwrap().to_str().unwrap();
36+
let path = repo.index_file(crate_name);
37+
if !path.exists() {
38+
println!("skipping file `{}`", crate_name);
39+
continue;
40+
}
41+
let contents = std::fs::read_to_string(&path)?;
42+
uploader.upload_index(&client, crate_name, contents)?;
43+
}
44+
45+
println!(
46+
"uploading completed; use `upload-index {}` for an incremental run",
47+
repo.head_oid()?
48+
);
49+
Ok(())
50+
}

src/bin/crates-admin.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22

33
use cargo_registry::admin::{
44
delete_crate, delete_version, migrate, populate, render_readmes, test_pagerduty,
5-
transfer_crates, verify_token, upload_index,
5+
transfer_crates, upload_index, verify_token,
66
};
77

88
#[derive(clap::Parser, Debug)]

src/tests/http-data/krate_publish_features_version_2

+67
Original file line numberDiff line numberDiff line change
@@ -65,5 +65,72 @@
6565
],
6666
"body": ""
6767
}
68+
},
69+
{
70+
"request": {
71+
"uri": "http://alexcrichton-test.s3.amazonaws.com/index/3/f/foo",
72+
"method": "PUT",
73+
"headers": [
74+
[
75+
"accept-encoding",
76+
"gzip"
77+
],
78+
[
79+
"accept",
80+
"*/*"
81+
],
82+
[
83+
"content-length",
84+
"336"
85+
],
86+
[
87+
"date",
88+
"Fri, 15 Sep 2017 07:53:06 -0700"
89+
],
90+
[
91+
"authorization",
92+
"AWS AKIAICL5IWUZYWWKA7JA:uDc39eNdF6CcwB+q+JwKsoDLQc4="
93+
],
94+
[
95+
"content-type",
96+
"text/plain"
97+
],
98+
[
99+
"host",
100+
"alexcrichton-test.s3.amazonaws.com"
101+
]
102+
],
103+
"body": "eyJuYW1lIjoiZm9vIiwidmVycyI6IjEuMC4wIiwiZGVwcyI6W3sibmFtZSI6ImJhciIsInJlcSI6Ij4gMCIsImZlYXR1cmVzIjpbXSwib3B0aW9uYWwiOmZhbHNlLCJkZWZhdWx0X2ZlYXR1cmVzIjp0cnVlLCJ0YXJnZXQiOm51bGwsImtpbmQiOiJub3JtYWwifV0sImNrc3VtIjoiYWNiNTYwNGIxMjZhYzg5NGMxZWIxMWM0NTc1YmYyMDcyZmVhNjEyMzJhODg4ZTQ1Mzc3MGM3OWQ3ZWQ1NjQxOSIsImZlYXR1cmVzIjp7Im9sZF9mZWF0IjpbXX0sImZlYXR1cmVzMiI6eyJuZXdfZmVhdCI6WyJkZXA6YmFyIiwiYmFyPy9mZWF0Il19LCJ5YW5rZWQiOmZhbHNlLCJsaW5rcyI6bnVsbCwidiI6Mn0K"
104+
},
105+
"response": {
106+
"status": 200,
107+
"headers": [
108+
[
109+
"x-amz-request-id",
110+
"26589A5E52F8395C"
111+
],
112+
[
113+
"x-amz-id-2",
114+
"JdIvnNTw53aqXjBIqBLNuN4kxf/w1XWX+xuIiGBDYy7yzOSDuAMtBSrTW4ZWetcCIdqCUHuQ51A="
115+
],
116+
[
117+
"content-length",
118+
"0"
119+
],
120+
[
121+
"Server",
122+
"AmazonS3"
123+
],
124+
[
125+
"date",
126+
"Fri,15 Sep 2017 14:53:07 GMT"
127+
],
128+
[
129+
"ETag",
130+
"\"f9016ad360cebb4fe2e6e96e5949f022\""
131+
]
132+
],
133+
"body": ""
134+
}
68135
}
69136
]

src/tests/http-data/krate_publish_good_badges

+67
Original file line numberDiff line numberDiff line change
@@ -65,5 +65,72 @@
6565
],
6666
"body": ""
6767
}
68+
},
69+
{
70+
"request": {
71+
"uri": "http://alexcrichton-test.s3.amazonaws.com/index/fo/ob/foobadger",
72+
"method": "PUT",
73+
"headers": [
74+
[
75+
"accept-encoding",
76+
"gzip"
77+
],
78+
[
79+
"accept",
80+
"*/*"
81+
],
82+
[
83+
"content-length",
84+
"163"
85+
],
86+
[
87+
"date",
88+
"Fri, 15 Sep 2017 07:53:06 -0700"
89+
],
90+
[
91+
"authorization",
92+
"AWS AKIAICL5IWUZYWWKA7JA:uDc39eNdF6CcwB+q+JwKsoDLQc4="
93+
],
94+
[
95+
"content-type",
96+
"text/plain"
97+
],
98+
[
99+
"host",
100+
"alexcrichton-test.s3.amazonaws.com"
101+
]
102+
],
103+
"body": "eyJuYW1lIjoiZm9vYmFkZ2VyIiwidmVycyI6IjEuMC4wIiwiZGVwcyI6W10sImNrc3VtIjoiYWNiNTYwNGIxMjZhYzg5NGMxZWIxMWM0NTc1YmYyMDcyZmVhNjEyMzJhODg4ZTQ1Mzc3MGM3OWQ3ZWQ1NjQxOSIsImZlYXR1cmVzIjp7fSwieWFua2VkIjpmYWxzZSwibGlua3MiOm51bGx9Cg=="
104+
},
105+
"response": {
106+
"status": 200,
107+
"headers": [
108+
[
109+
"x-amz-request-id",
110+
"26589A5E52F8395C"
111+
],
112+
[
113+
"x-amz-id-2",
114+
"JdIvnNTw53aqXjBIqBLNuN4kxf/w1XWX+xuIiGBDYy7yzOSDuAMtBSrTW4ZWetcCIdqCUHuQ51A="
115+
],
116+
[
117+
"content-length",
118+
"0"
119+
],
120+
[
121+
"Server",
122+
"AmazonS3"
123+
],
124+
[
125+
"date",
126+
"Fri,15 Sep 2017 14:53:07 GMT"
127+
],
128+
[
129+
"ETag",
130+
"\"f9016ad360cebb4fe2e6e96e5949f022\""
131+
]
132+
],
133+
"body": ""
134+
}
68135
}
69136
]

src/tests/http-data/krate_publish_good_categories

+67
Original file line numberDiff line numberDiff line change
@@ -65,5 +65,72 @@
6565
],
6666
"body": ""
6767
}
68+
},
69+
{
70+
"request": {
71+
"uri": "http://alexcrichton-test.s3.amazonaws.com/index/fo/o_/foo_good_cat",
72+
"method": "PUT",
73+
"headers": [
74+
[
75+
"accept-encoding",
76+
"gzip"
77+
],
78+
[
79+
"accept",
80+
"*/*"
81+
],
82+
[
83+
"content-length",
84+
"166"
85+
],
86+
[
87+
"date",
88+
"Fri, 15 Sep 2017 07:53:06 -0700"
89+
],
90+
[
91+
"authorization",
92+
"AWS AKIAICL5IWUZYWWKA7JA:uDc39eNdF6CcwB+q+JwKsoDLQc4="
93+
],
94+
[
95+
"content-type",
96+
"text/plain"
97+
],
98+
[
99+
"host",
100+
"alexcrichton-test.s3.amazonaws.com"
101+
]
102+
],
103+
"body": "eyJuYW1lIjoiZm9vX2dvb2RfY2F0IiwidmVycyI6IjEuMC4wIiwiZGVwcyI6W10sImNrc3VtIjoiYWNiNTYwNGIxMjZhYzg5NGMxZWIxMWM0NTc1YmYyMDcyZmVhNjEyMzJhODg4ZTQ1Mzc3MGM3OWQ3ZWQ1NjQxOSIsImZlYXR1cmVzIjp7fSwieWFua2VkIjpmYWxzZSwibGlua3MiOm51bGx9Cg=="
104+
},
105+
"response": {
106+
"status": 200,
107+
"headers": [
108+
[
109+
"x-amz-request-id",
110+
"26589A5E52F8395C"
111+
],
112+
[
113+
"x-amz-id-2",
114+
"JdIvnNTw53aqXjBIqBLNuN4kxf/w1XWX+xuIiGBDYy7yzOSDuAMtBSrTW4ZWetcCIdqCUHuQ51A="
115+
],
116+
[
117+
"content-length",
118+
"0"
119+
],
120+
[
121+
"Server",
122+
"AmazonS3"
123+
],
124+
[
125+
"date",
126+
"Fri,15 Sep 2017 14:53:07 GMT"
127+
],
128+
[
129+
"ETag",
130+
"\"f9016ad360cebb4fe2e6e96e5949f022\""
131+
]
132+
],
133+
"body": ""
134+
}
68135
}
69136
]

0 commit comments

Comments
 (0)