Skip to content

Commit

Permalink
Closes #39 #40
Browse files Browse the repository at this point in the history
  • Loading branch information
michaelklishin committed Dec 29, 2024
1 parent 8c7057c commit 068e637
Show file tree
Hide file tree
Showing 4 changed files with 94 additions and 1 deletion.
14 changes: 13 additions & 1 deletion src/cli.rs
Original file line number Diff line number Diff line change
Expand Up @@ -253,7 +253,7 @@ pub fn parser() -> Command {
])
}

fn list_subcommands() -> [Command; 15] {
fn list_subcommands() -> [Command; 17] {
// duplicate this very common global argument so that
// it can be passed as the end of argument list
let vhost_arg = Arg::new("vhost")
Expand Down Expand Up @@ -360,6 +360,18 @@ fn list_subcommands() -> [Command; 15] {
"<bold>Doc guide</bold>: {}",
USER_LIMIT_GUIDE_URL
)),
Command::new("deprecated_features")
.long_about("Lists all deprecated features")
.after_long_help(color_print::cformat!(
"<bold>Doc guide</bold>: {}",
DEPRECATED_FEATURE_GUIDE_URL
)),
Command::new("deprecated_features_in_use")
.long_about("Lists the deprecated features that are in used in the cluster")
.after_long_help(color_print::cformat!(
"<bold>Doc guide</bold>: {}",
DEPRECATED_FEATURE_GUIDE_URL
)),
]
}

Expand Down
12 changes: 12 additions & 0 deletions src/commands.rs
Original file line number Diff line number Diff line change
Expand Up @@ -122,6 +122,18 @@ pub fn list_parameters(
}
}

pub fn list_deprecated_features(
client: APIClient,
) -> ClientResult<responses::DeprecatedFeatureList> {
client.list_all_deprecated_features()
}

pub fn list_deprecated_features_in_use(
client: APIClient,
) -> ClientResult<responses::DeprecatedFeatureList> {
client.list_deprecated_features_in_use()
}

pub fn declare_vhost(client: APIClient, command_args: &ArgMatches) -> ClientResult<()> {
// the flag is required
let name = command_args.get_one::<String>("name").unwrap();
Expand Down
8 changes: 8 additions & 0 deletions src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -232,6 +232,14 @@ fn dispatch_subcommand(
let result = commands::list_exchanges(client, &vhost);
res_handler.tabular_result(result)
}
("list", "deprecated_features") => {
let result = commands::list_deprecated_features(client);
res_handler.tabular_result(result.map(|val| val.0))
}
("list", "deprecated_features_in_use") => {
let result = commands::list_deprecated_features_in_use(client);
res_handler.tabular_result(result.map(|val| val.0))
}
("declare", "vhost") => {
let result = commands::declare_vhost(client, command_args);
res_handler.no_output_on_success(result);
Expand Down
61 changes: 61 additions & 0 deletions tests/list_deprecated_feature_tests.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
// Copyright (C) 2023-2024 RabbitMQ Core Team (teamrabbitmq@gmail.com)
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.

use predicates::prelude::*;

mod test_helpers;
use crate::test_helpers::*;

#[test]
fn test_list_all_deprecated_features() -> Result<(), Box<dyn std::error::Error>> {
run_succeeds(["list", "deprecated_features"]).stdout(predicate::str::contains("ram_node_type"));

Ok(())
}

#[test]
fn test_list_deprecated_features_in_use() -> Result<(), Box<dyn std::error::Error>> {
let vh = "test_list_deprecated_features_in_use";
let q = "test_list_deprecated_features_in_use.cq.transient.1";

delete_vhost(vh).expect("failed to delete a virtual host");

// there are no deprecated features in use at this point
run_succeeds(["list", "deprecated_features_in_use"])
.stdout(predicate::str::contains("transient_nonexcl_queues").not());

run_succeeds(["declare", "vhost", "--name", vh]);
run_succeeds([
"-V",
vh,
"declare",
"queue",
"--name",
q,
"--type",
"classic",
"--durable",
"false",
]);

await_queue_metric_emission();

// now there is: a non-exclusive transient queue
run_succeeds(["list", "deprecated_features_in_use"])
.stdout(predicate::str::contains("transient_nonexcl_queues"));

delete_vhost(vh).expect("failed to delete a virtual host");

Ok(())
}

0 comments on commit 068e637

Please sign in to comment.