dynk8s-provisioner/tests/integration/sns.rs

58 lines
2.0 KiB
Rust

use rocket::http::Status;
use rocket::local::asynchronous::Client;
use dynk8s_provisioner::rocket;
use crate::{setup, WIREGUARD_CONFIG};
#[rocket::async_test]
async fn test_sns_ec2_lifecycle() {
setup().await;
let client = Client::tracked(rocket()).await.unwrap();
// Simulate an instance state-change event indicating an instance has
// started. This should generate a bootstrap token and assign the WireGuard
// config to the instance.
let data =
std::fs::read_to_string("tests/data/sns/notification-running.json")
.unwrap();
let res = client.post("/sns/notify").body(&data).dispatch().await;
assert_eq!(res.status(), Status::NoContent);
// Ensure the bootstrap token was generated
let res = client
.get("/kubeadm/kubeconfig/i-0e50d560c8bf9f0f8")
.dispatch()
.await;
assert_eq!(res.status(), Status::Ok);
// Ensure the WireGuard config was assigned
let res = client
.get("/wireguard/config/i-0e50d560c8bf9f0f8")
.dispatch()
.await;
assert_eq!(res.status(), Status::Ok);
assert_eq!(res.into_string().await, Some(WIREGUARD_CONFIG.into()));
// Simulate an instance state-change event indicating the instance has
// terminated. This should delete the bootstrap token and unassing the
// WireGuard config.
let data =
std::fs::read_to_string("tests/data/sns/notification-terminated.json")
.unwrap();
let res = client.post("/sns/notify").body(&data).dispatch().await;
assert_eq!(res.status(), Status::NoContent);
// Ensure the bootstrap token was deleted
let res = client
.get("/kubeadm/kubeconfig/i-0e50d560c8bf9f0f8")
.dispatch()
.await;
assert_eq!(res.status(), Status::NotFound);
// Ensure the WireGuard config was deleted
let res = client
.get("/wireguard/config/i-0e50d560c8bf9f0f8")
.dispatch()
.await;
assert_eq!(res.status(), Status::NotFound);
}