diff --git a/src/responses.rs b/src/responses.rs index 5d35bab..99baff4 100644 --- a/src/responses.rs +++ b/src/responses.rs @@ -981,6 +981,58 @@ impl fmt::Display for FeatureFlagState { } } +#[derive(Serialize, Deserialize, Debug, PartialEq, Eq, Clone)] +#[serde(rename_all = "snake_case")] +pub enum FeatureFlagStability { + Required, + Stable, + Experimental, +} + +impl From<&str> for FeatureFlagStability { + fn from(value: &str) -> Self { + match value { + "required" => FeatureFlagStability::Required, + "stable" => FeatureFlagStability::Stable, + "experimental" => FeatureFlagStability::Experimental, + _ => FeatureFlagStability::Stable, + } + } +} + +impl From for FeatureFlagStability { + fn from(value: String) -> Self { + match value.as_ref() { + "required" => FeatureFlagStability::Required, + "stable" => FeatureFlagStability::Stable, + "experimental" => FeatureFlagStability::Experimental, + _ => FeatureFlagStability::Stable, + } + } +} + +impl From for String { + fn from(value: FeatureFlagStability) -> Self { + match value { + FeatureFlagStability::Required => "required".to_owned(), + FeatureFlagStability::Stable => "stable".to_owned(), + FeatureFlagStability::Experimental => "experimental".to_owned(), + } + } +} + +impl fmt::Display for FeatureFlagStability { + fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { + match self { + FeatureFlagStability::Required => writeln!(f, "required")?, + FeatureFlagStability::Stable => writeln!(f, "stable")?, + FeatureFlagStability::Experimental => writeln!(f, "experimental")?, + } + + Ok(()) + } +} + #[derive(Debug, Serialize, Deserialize, Clone, Eq, PartialEq)] #[cfg_attr(feature = "tabled", derive(Tabled))] #[allow(dead_code)] @@ -990,8 +1042,7 @@ pub struct FeatureFlag { #[serde(rename = "desc")] pub description: String, pub doc_url: String, - // TODO: required | stable | experimental - pub stability: String, + pub stability: FeatureFlagStability, pub provided_by: String, } diff --git a/tests/feature_flag_tests.rs b/tests/feature_flag_tests.rs index caeb0d5..1942315 100644 --- a/tests/feature_flag_tests.rs +++ b/tests/feature_flag_tests.rs @@ -11,7 +11,7 @@ // 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 rabbitmq_http_client::blocking_api::Client; +use rabbitmq_http_client::{blocking_api::Client, responses::FeatureFlagStability}; mod test_helpers; use crate::test_helpers::{endpoint, PASSWORD, USERNAME}; @@ -24,5 +24,8 @@ fn test_list_feature_flags() { assert!(result.is_ok()); let vec = result.unwrap(); - assert!(vec.0.into_iter().any(|ff| ff.name == "rabbitmq_4.0.0")); + assert!(vec + .0 + .into_iter() + .any(|ff| ff.name == "rabbitmq_4.0.0" && ff.stability == FeatureFlagStability::Stable)); }