fix: use dotenv to load test data
All checks were successful
ci/woodpecker/push/woodpecker Pipeline was successful

This commit is contained in:
Aravinth Manivannan 2024-01-02 20:10:06 +05:30
parent b15e9ebe18
commit 0f9caf7777
Signed by: realaravinth
GPG key ID: F8F50389936984FF
4 changed files with 18 additions and 13 deletions

View file

@ -43,4 +43,5 @@ steps:
- PASSWORD=password
- INSTANCE_URL=http://mcaptcha:7000
commands:
- . .env_sample && make test
- mv .env_sample .env.local
- make test

View file

@ -12,3 +12,4 @@ url = "2.5.0"
[dev-dependencies]
actix-rt = "2.9.0"
dotenv = "0.15.0"

View file

@ -9,16 +9,13 @@ test.env:
$(eval WIDGET_URL = $(shell . ./venv/bin/activate && python ./scripts/create_captcha.py widget_url $(INSTANCE_URL) $(SITEKEY)))
$(eval TOKEN = $(shell ./scripts/download-cli.sh gen_pow $(WIDGET_URL)))
@-rm .env.local
echo "export SECRET=$(SECRET)" > .env.local
echo "export SITEKEY=$(SITEKEY)" >> .env.local
echo "export WIDGET_URL=$(WIDGET_URL)" >> .env.local
echo "export TOKEN=$(TOKEN)" >> .env.local
echo "SECRET=$(SECRET)" > .env.local
echo "SITEKEY=$(SITEKEY)" >> .env.local
echo "TOKEN=$(TOKEN)" >> .env.local
test:
SITEKEY=$(SITEKEY) SECRET=$(SECRET) \
INSTANCE_URL=$(INSTANCE_URL) \
TOKEN=$(TOKEN) cargo test
cargo test
lint:
black src/ scripts/

View file

@ -28,11 +28,9 @@ impl MCaptcha {
.post(self.verify_path.clone())
.json(&payload)
.send()
.await
.unwrap()
.await?
.json()
.await
.unwrap();
.await?;
Ok(res.valid)
}
@ -62,16 +60,24 @@ impl<'a> CaptchaVerfiyPayload<'a> {
#[cfg(test)]
mod tests {
use super::*;
use std::env;
use super::*;
#[actix_rt::test]
async fn verify_works() {
dotenv::from_filename(".env.local").ok();
let instance_url = env::var("INSTANCE_URL").expect("instance url not set");
let sitekey = env::var("SITEKEY").expect("sitekey not set");
let secret = env::var("SECRET").expect("secret not set");
let token = env::var("TOKEN").expect("token not set");
println!("token={token}");
println!("sitekey={sitekey}");
println!("secret={secret}");
println!("instance_url={instance_url}");
let mcaptcha = MCaptcha::new(
sitekey,
secret,