Skip to content

Commit 62f66dc

Browse files
authored
Remove tests mod (#55)
* Randomize test params * Refactor tests location
1 parent 4c858d4 commit 62f66dc

File tree

68 files changed

+344
-190
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

68 files changed

+344
-190
lines changed

Cargo.lock

+240-22
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

docusign/Cargo.toml

+2
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,8 @@ tokio = { version = "1.25.0", features = ["full"] }
4848
base64 = "^0.13"
4949
dirs = "^3.0.2"
5050
nom_pem = "4"
51+
rand = "0.8.5"
52+
rsa = "0.8.1"
5153
tokio = { version = "1.25.0", features = ["test-util"] }
5254
wiremock = "0.5.17"
5355

docusign/src/lib.rs

-2
Original file line numberDiff line numberDiff line change
@@ -2132,8 +2132,6 @@ pub mod template_views;
21322132
///
21332133
///The resource also includes a number of methods that allow you to retrieve and set the initials and signature for certain types of recipients on the document.
21342134
pub mod templates;
2135-
#[cfg(test)]
2136-
mod tests;
21372135
pub mod types;
21382136
/// The UserCustomSettings resource provides methods that allow you to manage the custom settings for a user.
21392137
///
File renamed without changes.

generator/src/main.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -2301,8 +2301,6 @@ fn gen(
23012301
{
23022302
a("pub mod traits;");
23032303
}
2304-
a("#[cfg(test)]");
2305-
a("mod tests;");
23062304
// Hopefully there is never a "tag" named after these reserved libs.
23072305
a("pub mod types;");
23082306
a("#[doc(hidden)]");
@@ -3290,6 +3288,8 @@ tokio = {{ version = "1.25.0", features = ["full"] }}
32903288
base64 = "^0.13"
32913289
dirs = "^3.0.2"
32923290
nom_pem = "4"
3291+
rand = "0.8.5"
3292+
rsa = "0.8.1"
32933293
tokio = {{ version = "1.25.0", features = ["test-util"] }}
32943294
wiremock = "0.5.17"
32953295

giphy/Cargo.toml

+2
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,8 @@ tokio = { version = "1.25.0", features = ["full"] }
4848
base64 = "^0.13"
4949
dirs = "^3.0.2"
5050
nom_pem = "4"
51+
rand = "0.8.5"
52+
rsa = "0.8.1"
5153
tokio = { version = "1.25.0", features = ["test-util"] }
5254
wiremock = "0.5.17"
5355

giphy/src/lib.rs

-2
Original file line numberDiff line numberDiff line change
@@ -68,8 +68,6 @@
6868

6969
pub mod gifs;
7070
pub mod stickers;
71-
#[cfg(test)]
72-
mod tests;
7371
pub mod types;
7472
#[doc(hidden)]
7573
pub mod utils;
File renamed without changes.

github/Cargo.toml

+2
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,8 @@ tokio = { version = "1.25.0", features = ["full"] }
4545
base64 = "^0.13"
4646
dirs = "^3.0.2"
4747
nom_pem = "4"
48+
rand = "0.8.5"
49+
rsa = "0.8.1"
4850
tokio = { version = "1.25.0", features = ["test-util"] }
4951
wiremock = "0.5.17"
5052

github/src/auth.rs

+24-7
Original file line numberDiff line numberDiff line change
@@ -231,17 +231,34 @@ impl PartialEq for InstallationTokenGenerator {
231231

232232
#[cfg(test)]
233233
mod tests {
234+
use super::*;
235+
use rand::RngCore;
236+
use rsa::{pkcs1::EncodeRsaPrivateKey, RsaPrivateKey};
234237
use std::time::Duration;
235238

236-
use super::*;
239+
fn app_id() -> u64 {
240+
let mut rng = rand::thread_rng();
241+
rng.next_u64()
242+
}
237243

238-
const APP_ID: u64 = 162665041;
239-
const INSTALLATION_ID: u64 = 1780480419;
240-
const PRIVATE_KEY: &[u8] = include_bytes!("dummy-rsa.der");
244+
fn installation_id() -> u64 {
245+
let mut rng = rand::thread_rng();
246+
rng.next_u64()
247+
}
248+
249+
fn private_key() -> Vec<u8> {
250+
let mut rng = rand::thread_rng();
251+
let private_key = RsaPrivateKey::new(&mut rng, 2048)
252+
.unwrap()
253+
.to_pkcs1_der()
254+
.unwrap()
255+
.to_bytes();
256+
private_key.to_vec()
257+
}
241258

242259
#[tokio::test(start_paused = true)]
243260
async fn jwt_credentials_refreshes_when_necessary() {
244-
let credentials = JWTCredentials::new(APP_ID, Vec::from(PRIVATE_KEY))
261+
let credentials = JWTCredentials::new(app_id(), private_key())
245262
.expect("Should be able to create credentials");
246263

247264
assert!(
@@ -266,10 +283,10 @@ mod tests {
266283

267284
#[tokio::test(start_paused = true)]
268285
async fn installation_token_generator_expires_after_token_interval() {
269-
let jwt_credentials = JWTCredentials::new(APP_ID, Vec::from(PRIVATE_KEY))
286+
let jwt_credentials = JWTCredentials::new(app_id(), private_key())
270287
.expect("Should be able to create JWT credentials");
271288

272-
let generator = InstallationTokenGenerator::new(INSTALLATION_ID, jwt_credentials.clone());
289+
let generator = InstallationTokenGenerator::new(installation_id(), jwt_credentials.clone());
273290

274291
assert_eq!(
275292
None,

github/src/dummy-rsa.der

-1.16 KB
Binary file not shown.

github/src/lib.rs

-2
Original file line numberDiff line numberDiff line change
@@ -236,8 +236,6 @@ pub mod search;
236236
pub mod secret_scanning;
237237
/// Interact with GitHub Teams.
238238
pub mod teams;
239-
#[cfg(test)]
240-
mod tests;
241239
pub mod types;
242240
/// Interact with and view information about users and also current user.
243241
pub mod users;

github/src/tests.rs renamed to github/tests/tests.rs

+27-8
Original file line numberDiff line numberDiff line change
@@ -1,26 +1,45 @@
1+
use rand::RngCore;
2+
use rsa::{pkcs1::EncodeRsaPrivateKey, RsaPrivateKey};
13
use std::{mem, time::Duration};
24

35
use wiremock::{
46
matchers::{bearer_token, header, method, path},
57
Mock, MockServer, ResponseTemplate,
68
};
79

8-
use crate::{
10+
use octorust::{
911
auth::{Credentials, InstallationTokenGenerator, JWTCredentials},
1012
types::InstallationToken,
1113
Client,
1214
};
1315

14-
const APP_ID: u64 = 432376605;
15-
const INSTALLATION_ID: u64 = 260162224;
16-
const PRIVATE_KEY: &[u8] = include_bytes!("dummy-rsa.der");
16+
fn app_id() -> u64 {
17+
let mut rng = rand::thread_rng();
18+
rng.next_u64()
19+
}
20+
21+
fn installation_id() -> u64 {
22+
let mut rng = rand::thread_rng();
23+
rng.next_u64()
24+
}
25+
26+
fn private_key() -> Vec<u8> {
27+
let mut rng = rand::thread_rng();
28+
let private_key = RsaPrivateKey::new(&mut rng, 2048)
29+
.unwrap()
30+
.to_pkcs1_der()
31+
.unwrap()
32+
.to_bytes();
33+
private_key.to_vec()
34+
}
1735

1836
#[tokio::test]
1937
async fn refreshes_installation_token_once() {
38+
let installation_id = installation_id();
39+
2040
let server = MockServer::start().await;
2141

22-
let jwt =
23-
JWTCredentials::new(APP_ID, Vec::from(PRIVATE_KEY)).expect("JWT creation should succeed");
42+
let jwt = JWTCredentials::new(app_id(), private_key()).expect("JWT creation should succeed");
2443

2544
// The JWT should be used to retrieve an installation token only once, even if requesting the
2645
// the token takes long enough for a second task to ask for one.
@@ -38,7 +57,7 @@ async fn refreshes_installation_token_once() {
3857
});
3958
Mock::given(method("POST"))
4059
.and(path(format!(
41-
"/app/installations/{INSTALLATION_ID}/access_tokens"
60+
"/app/installations/{installation_id}/access_tokens"
4261
)))
4362
.and(bearer_token(jwt.token()))
4463
.respond_with(auth_response)
@@ -54,7 +73,7 @@ async fn refreshes_installation_token_once() {
5473
.mount(&server)
5574
.await;
5675

57-
let token_generator = InstallationTokenGenerator::new(INSTALLATION_ID, jwt);
76+
let token_generator = InstallationTokenGenerator::new(installation_id, jwt);
5877
let mut client = Client::new(
5978
concat!(env!("CARGO_PKG_NAME"), "/", env!("CARGO_PKG_VERSION")),
6079
Credentials::InstallationToken(token_generator),

google/admin/Cargo.toml

+2
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,8 @@ tokio = { version = "1.25.0", features = ["full"] }
5050
base64 = "^0.13"
5151
dirs = "^3.0.2"
5252
nom_pem = "4"
53+
rand = "0.8.5"
54+
rsa = "0.8.1"
5355
tokio = { version = "1.25.0", features = ["test-util"] }
5456
wiremock = "0.5.17"
5557

google/admin/src/lib.rs

-2
Original file line numberDiff line numberDiff line change
@@ -125,8 +125,6 @@ pub mod resources;
125125
pub mod role_assignments;
126126
pub mod roles;
127127
pub mod schemas;
128-
#[cfg(test)]
129-
mod tests;
130128
pub mod tokens;
131129
pub mod two_step_verification;
132130
pub mod types;
File renamed without changes.

google/calendar/Cargo.toml

+2
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,8 @@ tokio = { version = "1.25.0", features = ["full"] }
5050
base64 = "^0.13"
5151
dirs = "^3.0.2"
5252
nom_pem = "4"
53+
rand = "0.8.5"
54+
rsa = "0.8.1"
5355
tokio = { version = "1.25.0", features = ["test-util"] }
5456
wiremock = "0.5.17"
5557

google/calendar/src/lib.rs

-2
Original file line numberDiff line numberDiff line change
@@ -117,8 +117,6 @@ pub mod colors;
117117
pub mod events;
118118
pub mod freebusy;
119119
pub mod settings;
120-
#[cfg(test)]
121-
mod tests;
122120
pub mod types;
123121
#[doc(hidden)]
124122
pub mod utils;

google/calendar/src/tests.rs

-101
This file was deleted.

google/cloud-resource-manager/Cargo.toml

+2
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,8 @@ tokio = { version = "1.25.0", features = ["full"] }
5050
base64 = "^0.13"
5151
dirs = "^3.0.2"
5252
nom_pem = "4"
53+
rand = "0.8.5"
54+
rsa = "0.8.1"
5355
tokio = { version = "1.25.0", features = ["test-util"] }
5456
wiremock = "0.5.17"
5557

google/cloud-resource-manager/src/lib.rs

-2
Original file line numberDiff line numberDiff line change
@@ -111,8 +111,6 @@
111111

112112
pub mod folders;
113113
pub mod operations;
114-
#[cfg(test)]
115-
mod tests;
116114
pub mod types;
117115
#[doc(hidden)]
118116
pub mod utils;

google/drive/Cargo.toml

+2
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,8 @@ tokio = { version = "1.25.0", features = ["full"] }
5050
base64 = "^0.13"
5151
dirs = "^3.0.2"
5252
nom_pem = "4"
53+
rand = "0.8.5"
54+
rsa = "0.8.1"
5355
tokio = { version = "1.25.0", features = ["test-util"] }
5456
wiremock = "0.5.17"
5557

google/drive/src/lib.rs

-2
Original file line numberDiff line numberDiff line change
@@ -119,8 +119,6 @@ pub mod permissions;
119119
pub mod replies;
120120
pub mod revisions;
121121
pub mod teamdrives;
122-
#[cfg(test)]
123-
mod tests;
124122
pub mod traits;
125123
pub mod types;
126124
#[doc(hidden)]
File renamed without changes.

google/groups-settings/Cargo.toml

+2
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,8 @@ tokio = { version = "1.25.0", features = ["full"] }
5050
base64 = "^0.13"
5151
dirs = "^3.0.2"
5252
nom_pem = "4"
53+
rand = "0.8.5"
54+
rsa = "0.8.1"
5355
tokio = { version = "1.25.0", features = ["test-util"] }
5456
wiremock = "0.5.17"
5557

google/groups-settings/src/lib.rs

-2
Original file line numberDiff line numberDiff line change
@@ -110,8 +110,6 @@
110110
#![cfg_attr(docsrs, feature(doc_cfg))]
111111

112112
pub mod groups;
113-
#[cfg(test)]
114-
mod tests;
115113
pub mod types;
116114
#[doc(hidden)]
117115
pub mod utils;
File renamed without changes.

google/sheets/Cargo.toml

+2
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,8 @@ tokio = { version = "1.25.0", features = ["full"] }
5050
base64 = "^0.13"
5151
dirs = "^3.0.2"
5252
nom_pem = "4"
53+
rand = "0.8.5"
54+
rsa = "0.8.1"
5355
tokio = { version = "1.25.0", features = ["test-util"] }
5456
wiremock = "0.5.17"
5557

0 commit comments

Comments
 (0)