Skip to content

Commit

Permalink
Refactor to FeatureFlagStability
Browse files Browse the repository at this point in the history
  • Loading branch information
michaelklishin committed Dec 28, 2024
1 parent c0f1a86 commit ab2f70e
Show file tree
Hide file tree
Showing 2 changed files with 58 additions and 4 deletions.
55 changes: 53 additions & 2 deletions src/responses.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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<String> for FeatureFlagStability {
fn from(value: String) -> Self {
match value.as_ref() {
"required" => FeatureFlagStability::Required,
"stable" => FeatureFlagStability::Stable,
"experimental" => FeatureFlagStability::Experimental,
_ => FeatureFlagStability::Stable,
}
}
}

impl From<FeatureFlagStability> 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)]
Expand All @@ -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,
}

Expand Down
7 changes: 5 additions & 2 deletions tests/feature_flag_tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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};
Expand All @@ -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));
}

0 comments on commit ab2f70e

Please sign in to comment.