Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

13 changes: 6 additions & 7 deletions src/flexible/subscriptions.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1072,13 +1072,12 @@ impl SubscriptionHandler {
subscription_id: i32,
request: &ActiveActiveRegionDeleteRequest,
) -> Result<TaskStateUpdate> {
// TODO: DELETE with body not yet supported by client
let _ = request; // Suppress unused variable warning
let response = self
.client
.delete_raw(&format!("/subscriptions/{subscription_id}/regions"))
.await?;
serde_json::from_value(response).map_err(Into::into)
self.client
.delete_with_body(
&format!("/subscriptions/{subscription_id}/regions"),
serde_json::to_value(request)?,
)
.await
}

/// Get regions in an Active-Active subscription
Expand Down
57 changes: 54 additions & 3 deletions tests/subscriptions_tests.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
use redis_cloud::{CloudClient, SubscriptionsHandler};
use serde_json::json;
use wiremock::matchers::{header, method, path, query_param};
use wiremock::matchers::{body_json, header, method, path, query_param};
use wiremock::{Mock, MockServer, ResponseTemplate};

#[tokio::test]
Expand Down Expand Up @@ -424,8 +424,59 @@ async fn test_get_subscription_pricing() {
assert_eq!(pricing[0].r#type, Some("Shards".to_string()));
}

// Skipping test_delete_regions_from_active_active_subscription
// as the client doesn't yet support DELETE with body
#[tokio::test]
async fn test_delete_regions_from_active_active_subscription() {
let mock_server = MockServer::start().await;

Mock::given(method("DELETE"))
.and(path("/subscriptions/123/regions"))
.and(header("x-api-key", "test-key"))
.and(header("x-api-secret-key", "test-secret"))
.and(body_json(json!({
"regions": [
{
"region": "us-east-1"
}
],
"dryRun": false,
"commandType": "DELETE_REGION"
})))
.respond_with(ResponseTemplate::new(202).set_body_json(json!({
"taskId": "task-delete-region",
"commandType": "DELETE_REGION",
"status": "processing"
})))
.mount(&mock_server)
.await;

let client = CloudClient::builder()
.api_key("test-key".to_string())
.api_secret("test-secret".to_string())
.base_url(mock_server.uri())
.build()
.unwrap();

let handler = SubscriptionsHandler::new(client);
let request = redis_cloud::subscriptions::ActiveActiveRegionDeleteRequest {
subscription_id: None,
regions: Some(vec![
redis_cloud::subscriptions::ActiveActiveRegionToDelete {
region: Some("us-east-1".to_string()),
},
]),
dry_run: Some(false),
command_type: Some("DELETE_REGION".to_string()),
};

let result = handler
.delete_regions_from_active_active_subscription(123, &request)
.await
.unwrap();

assert_eq!(result.task_id.as_deref(), Some("task-delete-region"));
assert_eq!(result.command_type.as_deref(), Some("DELETE_REGION"));
assert_eq!(result.status.as_deref(), Some("processing"));
}

#[tokio::test]
async fn test_get_regions_from_active_active_subscription() {
Expand Down
Loading