added alias to run tests
This commit is contained in:
parent
0001567b55
commit
cc3d55e5b9
|
@ -3,6 +3,9 @@ name = "mastodon-image-uploader-bot"
|
||||||
version = "0.2.2"
|
version = "0.2.2"
|
||||||
edition = "2021"
|
edition = "2021"
|
||||||
|
|
||||||
|
[alias]
|
||||||
|
test = "cargo test -- --test-threads=1"
|
||||||
|
|
||||||
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
|
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
|
||||||
|
|
||||||
[dependencies]
|
[dependencies]
|
||||||
|
|
45
src/main.rs
45
src/main.rs
|
@ -269,13 +269,11 @@ mod tests {
|
||||||
|
|
||||||
use super::*;
|
use super::*;
|
||||||
const TMPTESTDIR: &str = "/tmp/botimage";
|
const TMPTESTDIR: &str = "/tmp/botimage";
|
||||||
|
const TEST_URL: &str = "https://2.gravatar.com/avatar/be8eb8426d68e4beb50790647eda6f6b";
|
||||||
|
|
||||||
#[tokio::test]
|
#[tokio::test]
|
||||||
async fn fetch_url_should_fetch() {
|
async fn fetch_url_should_fetch() {
|
||||||
fetch_url(
|
fetch_url(&TEST_URL.to_string(), &TMPTESTDIR.to_string())
|
||||||
&"https://2.gravatar.com/avatar/be8eb8426d68e4beb50790647eda6f6b".to_string(),
|
|
||||||
&TMPTESTDIR.to_string(),
|
|
||||||
)
|
|
||||||
.await
|
.await
|
||||||
.unwrap();
|
.unwrap();
|
||||||
std::fs::read(TMPTESTDIR).unwrap();
|
std::fs::read(TMPTESTDIR).unwrap();
|
||||||
|
@ -310,12 +308,7 @@ mod tests {
|
||||||
let config = get_config();
|
let config = get_config();
|
||||||
let account = get_account(&config).await;
|
let account = get_account(&config).await;
|
||||||
|
|
||||||
let status = post_image(
|
let status = post_image(&account, &TEST_URL.to_string(), &config, Visibility::Direct)
|
||||||
&account,
|
|
||||||
&"https://2.gravatar.com/avatar/be8eb8426d68e4beb50790647eda6f6b".to_string(),
|
|
||||||
&config,
|
|
||||||
Visibility::Direct,
|
|
||||||
)
|
|
||||||
.await
|
.await
|
||||||
.unwrap();
|
.unwrap();
|
||||||
|
|
||||||
|
@ -333,4 +326,36 @@ mod tests {
|
||||||
|
|
||||||
assert_eq!(response.status(), StatusCode::OK)
|
assert_eq!(response.status(), StatusCode::OK)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[test]
|
||||||
|
fn set_as_posted_works() {
|
||||||
|
let config = get_config();
|
||||||
|
|
||||||
|
std::fs::write(&config.files.posted, "").unwrap();
|
||||||
|
|
||||||
|
set_url_as_posted(&config, &TEST_URL.to_string()).unwrap();
|
||||||
|
let file = std::fs::read_to_string(&config.files.posted).unwrap();
|
||||||
|
let url = file.lines().next_back().unwrap();
|
||||||
|
assert_eq!(url, TEST_URL)
|
||||||
|
}
|
||||||
|
|
||||||
|
#[test]
|
||||||
|
fn get_next_url_works() {
|
||||||
|
let config = get_config();
|
||||||
|
// Reset file
|
||||||
|
std::fs::write(&config.files.posted, "").unwrap();
|
||||||
|
|
||||||
|
// Get test url
|
||||||
|
let url = get_next_url(&config).unwrap().unwrap();
|
||||||
|
assert_eq!(url, TEST_URL);
|
||||||
|
|
||||||
|
set_url_as_posted(&config, &TEST_URL.to_string()).unwrap();
|
||||||
|
let file = std::fs::read_to_string(&config.files.posted).unwrap();
|
||||||
|
let url = file.lines().next_back().unwrap();
|
||||||
|
assert_eq!(url, TEST_URL);
|
||||||
|
|
||||||
|
// Test that now it does not get it
|
||||||
|
let url = get_next_url(&config).unwrap();
|
||||||
|
assert_eq!(url, None);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue