#![allow(deprecated)]
use assert_cmd::Command;
use predicates::prelude::PredicateBooleanExt;
use std::env;
use std::sync::Once;
static INIT: Once = Once::new();
fn init_env() {
INIT.call_once(|| {
let _ = dotenvy::from_filename("../.env");
let _ = dotenvy::dotenv();
});
}
fn has_credentials() -> bool {
init_env();
env::var("APS_CLIENT_ID").is_ok() && env::var("APS_CLIENT_SECRET").is_ok()
}
fn raps() -> Command {
Command::cargo_bin("raps").unwrap()
}
#[test]
#[ignore]
fn test_live_auth_test() {
if !has_credentials() {
eprintln!("Skipping: APS_CLIENT_ID and APS_CLIENT_SECRET not set");
return;
}
raps()
.args(["auth", "test"])
.assert()
.success()
.stdout(predicates::str::contains("success").or(predicates::str::contains("valid")));
}
#[test]
#[ignore]
fn test_live_auth_status() {
if !has_credentials() {
eprintln!("Skipping: APS_CLIENT_ID and APS_CLIENT_SECRET not set");
return;
}
raps()
.args(["auth", "status", "--output", "json"])
.assert()
.success();
}
#[test]
#[ignore]
fn test_live_bucket_list() {
if !has_credentials() {
eprintln!("Skipping: APS_CLIENT_ID and APS_CLIENT_SECRET not set");
return;
}
raps()
.args(["bucket", "list", "--output", "json"])
.assert()
.success();
}
#[test]
#[ignore]
fn test_live_bucket_list_table() {
if !has_credentials() {
eprintln!("Skipping: APS_CLIENT_ID and APS_CLIENT_SECRET not set");
return;
}
raps()
.args(["bucket", "list", "--output", "table"])
.assert()
.success();
}
#[test]
#[ignore]
fn test_live_bucket_info_not_found() {
if !has_credentials() {
eprintln!("Skipping: APS_CLIENT_ID and APS_CLIENT_SECRET not set");
return;
}
raps()
.args(["bucket", "info", "nonexistent-bucket-12345xyz"])
.assert()
.failure();
}
#[test]
#[ignore]
fn test_live_object_list_bucket_not_found() {
if !has_credentials() {
eprintln!("Skipping: APS_CLIENT_ID and APS_CLIENT_SECRET not set");
return;
}
raps()
.args(["object", "list", "nonexistent-bucket-12345xyz"])
.assert()
.failure();
}
#[test]
#[ignore]
fn test_live_webhook_events() {
if !has_credentials() {
eprintln!("Skipping: APS_CLIENT_ID and APS_CLIENT_SECRET not set");
return;
}
raps()
.args(["webhook", "events"])
.assert()
.success()
.stdout(predicates::str::contains("dm."));
}
#[test]
#[ignore]
fn test_live_webhook_list() {
if !has_credentials() {
eprintln!("Skipping: APS_CLIENT_ID and APS_CLIENT_SECRET not set");
return;
}
raps()
.args(["webhook", "list", "--output", "json"])
.assert()
.success();
}
#[test]
#[ignore]
fn test_live_da_engines() {
if !has_credentials() {
eprintln!("Skipping: APS_CLIENT_ID and APS_CLIENT_SECRET not set");
return;
}
raps()
.args(["da", "engines", "--output", "json"])
.assert()
.success()
.stdout(predicates::str::contains("Autodesk"));
}
#[test]
#[ignore]
fn test_live_da_appbundles() {
if !has_credentials() {
eprintln!("Skipping: APS_CLIENT_ID and APS_CLIENT_SECRET not set");
return;
}
raps()
.args(["da", "appbundles", "--output", "json"])
.assert()
.success();
}
#[test]
#[ignore]
fn test_live_da_activities() {
if !has_credentials() {
eprintln!("Skipping: APS_CLIENT_ID and APS_CLIENT_SECRET not set");
return;
}
raps()
.args(["da", "activities", "--output", "json"])
.assert()
.success();
}
#[test]
#[ignore]
fn test_live_translate_status_invalid_urn() {
if !has_credentials() {
eprintln!("Skipping: APS_CLIENT_ID and APS_CLIENT_SECRET not set");
return;
}
raps()
.args(["translate", "status", "invalid-urn"])
.assert()
.failure();
}
#[test]
#[ignore]
fn test_live_output_json() {
if !has_credentials() {
eprintln!("Skipping: APS_CLIENT_ID and APS_CLIENT_SECRET not set");
return;
}
let output = raps()
.args(["bucket", "list", "--output", "json"])
.output()
.unwrap();
if output.status.success() {
let stdout = String::from_utf8_lossy(&output.stdout);
assert!(stdout.contains("[") || stdout.contains("{"));
}
}
#[test]
#[ignore]
fn test_live_output_yaml() {
if !has_credentials() {
eprintln!("Skipping: APS_CLIENT_ID and APS_CLIENT_SECRET not set");
return;
}
let output = raps()
.args(["bucket", "list", "--output", "yaml"])
.output()
.unwrap();
assert!(
output.status.success()
|| !String::from_utf8_lossy(&output.stderr).contains("invalid value 'yaml'")
);
}
#[test]
#[ignore]
fn test_live_verbose_flag() {
if !has_credentials() {
eprintln!("Skipping: APS_CLIENT_ID and APS_CLIENT_SECRET not set");
return;
}
let output = raps()
.args(["--verbose", "bucket", "list"])
.output()
.unwrap();
let stderr = String::from_utf8_lossy(&output.stderr);
assert!(
output.status.success() || stderr.contains("GET") || stderr.contains("POST"),
"Verbose should show request info"
);
}
#[test]
#[ignore]
fn test_live_debug_flag() {
if !has_credentials() {
eprintln!("Skipping: APS_CLIENT_ID and APS_CLIENT_SECRET not set");
return;
}
let output = raps().args(["--debug", "auth", "test"]).output().unwrap();
assert!(output.status.success());
}
#[test]
#[ignore]
fn test_live_custom_timeout() {
if !has_credentials() {
eprintln!("Skipping: APS_CLIENT_ID and APS_CLIENT_SECRET not set");
return;
}
raps()
.args(["--timeout", "60", "bucket", "list"])
.assert()
.success();
}
#[test]
#[ignore]
fn test_live_bucket_workflow() {
if !has_credentials() {
eprintln!("Skipping: APS_CLIENT_ID and APS_CLIENT_SECRET not set");
return;
}
let bucket_key = format!(
"raps-test-{}",
std::time::SystemTime::now()
.duration_since(std::time::UNIX_EPOCH)
.unwrap()
.as_millis()
% 100000000
);
let create_result = raps()
.args([
"bucket",
"create",
"--key",
&bucket_key,
"--policy",
"transient",
"--output",
"json",
"--yes",
])
.output()
.unwrap();
if !create_result.status.success() {
eprintln!(
"Bucket create failed (may already exist): {}",
String::from_utf8_lossy(&create_result.stderr)
);
return;
}
println!("Created bucket: {}", bucket_key);
let list_result = raps()
.args(["bucket", "list", "--output", "json"])
.output()
.unwrap();
assert!(list_result.status.success());
let stdout = String::from_utf8_lossy(&list_result.stdout);
assert!(
stdout.contains(&bucket_key),
"Created bucket should appear in list"
);
raps()
.args(["bucket", "info", &bucket_key, "--output", "json"])
.assert()
.success();
raps()
.args(["bucket", "delete", &bucket_key, "--yes"])
.assert()
.success();
println!("Deleted bucket: {}", bucket_key);
}