Skip to content

Commit efeb18a

Browse files
committed
modify test
1 parent b85d861 commit efeb18a

6 files changed

Lines changed: 21 additions & 15 deletions

File tree

examples/oauth-web/Cargo.toml

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -10,11 +10,9 @@ axum = "0.8"
1010
serde = { version = "1", features = ["derive"] }
1111
tokio = { version = "1", features = ["full"] }
1212
tower-cookies = "0.11.0"
13-
twapi-v2 = { path="../..", features = ["retry"] }
13+
twapi-v2 = { path="../.." }
1414
twapi-oauth2 = "0.1.0"
1515

1616
[features]
17-
retry = []
1817
oauth10a = []
1918
models = []
20-
upload = []

examples/post-media/Cargo.toml

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,5 @@ tracing-subscriber = "0.3"
1414
twapi-v2 = { path="../..", features = [] }
1515

1616
[features]
17-
retry = []
1817
oauth10a = []
1918
models = []
20-
upload = []

examples/streaming/Cargo.toml

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -11,11 +11,9 @@ futures-util = "0.3"
1111
reqwest = { version = "0.12", features = ["stream"] }
1212
serde_json = "1"
1313
tokio = { version = "1", features = ["full"] }
14-
twapi-v2 = { path="../..", features = ["retry", "oauth10a"] }
14+
twapi-v2 = { path="../..", features = ["oauth10a"] }
1515
wasm-bindgen = "0.2.92"
1616

1717
[features]
18-
retry = []
1918
oauth10a = []
2019
models = []
21-
upload = []

src/api.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -226,7 +226,7 @@ where
226226
});
227227
}
228228

229-
if count
229+
if count + 1
230230
>= twapi_options
231231
.as_ref()
232232
.and_then(|options| options.try_count)

tests/get_2_tweets.rs

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,23 @@
1+
use std::time::Duration;
2+
13
use anyhow::Result;
2-
use twapi_v2::api::{BearerAuthentication, execute_twitter, get_2_tweets};
4+
use twapi_v2::api::{BearerAuthentication, TwapiOptions, execute_twitter, get_2_tweets};
35

46
//BEARER_CODE=XXXXX cargo test --test get_2_tweets --all-features -- --nocapture --test-threads=1
57

68
#[tokio::test]
79
async fn test_get_2_tweets_tweets() -> Result<()> {
810
let bearer_code = std::env::var("BEARER_CODE").unwrap_or_default();
911
let bearer_auth = BearerAuthentication::new(bearer_code);
12+
let twapi_option = TwapiOptions {
13+
try_count: Some(4),
14+
retryable_status_codes: Some(vec![500, 502, 503, 504, 401]),
15+
retry_interval_duration: Some(Duration::from_millis(1000)),
16+
..Default::default()
17+
};
1018
let (res, rate_limit) = execute_twitter::<serde_json::Value>(
11-
|| get_2_tweets::Api::all("1648835862149619712,1653186227338874881").build(&bearer_auth),
12-
&None,
19+
|| get_2_tweets::Api::all("1,2").build(&bearer_auth),
20+
&Some(twapi_option),
1321
)
1422
.await?;
1523
println!("{}", serde_json::to_string(&res).unwrap());

tests/get_2_users_id.rs

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
use anyhow::Result;
22
use twapi_v2::{
3-
api::{BearerAuthentication, execute_twitter, get_2_users_id},
3+
api::{BearerAuthentication, TwapiOptions, execute_twitter, get_2_users_id},
44
fields::user_fields::UserFields,
55
};
66

@@ -10,13 +10,17 @@ use twapi_v2::{
1010
async fn test_get_2_users_id() -> Result<()> {
1111
let bearer_code = std::env::var("BEARER_CODE").unwrap_or_default();
1212
let bearer_auth = BearerAuthentication::new(bearer_code);
13+
let twapi_option = TwapiOptions {
14+
try_count: Some(4),
15+
..Default::default()
16+
};
1317
let (res, _rate_limit) = execute_twitter::<serde_json::Value>(
1418
|| {
15-
get_2_users_id::Api::open("1660518823991336966")
19+
get_2_users_id::Api::open("1")
1620
.user_fields(UserFields::all())
1721
.build(&bearer_auth)
1822
},
19-
&None,
23+
&Some(twapi_option),
2024
)
2125
.await?;
2226
println!("{}", serde_json::to_string(&res).unwrap());

0 commit comments

Comments
 (0)