add tests for tailscale api client

Signed-off-by: Christine Dodrill <me@christine.website>
This commit is contained in:
Cadey Ratio 2021-09-09 10:21:22 -04:00
parent 5b2c73ba1f
commit c223853267
1 changed files with 30 additions and 2 deletions

View File

@ -1,5 +1,6 @@
use chrono::prelude::*;
use serde::{Deserialize, Serialize};
use std::env::VarError;
#[derive(thiserror::Error, Debug)]
pub enum Error {
@ -8,6 +9,9 @@ pub enum Error {
#[error("http error: {0}")]
Reqwest(#[from] reqwest::Error),
#[error("no such envvar: {0}")]
NoSuchEnvvar(#[from] VarError),
}
pub type Result<T = ()> = std::result::Result<T, Error>;
@ -147,8 +151,32 @@ pub struct Device {
#[cfg(test)]
mod tests {
use super::*;
use std::env::var as envvar;
fn client() -> Result<Client> {
Client::new(
envvar("TAILSCALE_TAILNET")?,
envvar("TAILSCALE_API_KEY")?,
"tailscale_api::test".into(),
)
}
#[tokio::test]
async fn it_works() {
assert_eq!(2 + 2, 4);
async fn basic_tests() {
async fn inner() -> Result {
let cli = client()?;
cli.devices().await?;
cli.get_nameservers().await?;
//cli.set_nameservers(ns).await?;
cli.get_acl().await?;
Ok(())
}
if let Err(why) = inner().await {
println!("error running tests: {}", why)
}
}
}