Skip to content

Commit 5331677

Browse files
test: Test serialization and deserialization of NodeRole
1 parent dcb7f80 commit 5331677

1 file changed

Lines changed: 27 additions & 9 deletions

File tree

  • rust/operator-binary/src/crd

rust/operator-binary/src/crd/mod.rs

Lines changed: 27 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -91,27 +91,19 @@ pub mod versioned {
9191
// The OpenSearch configuration uses snake_case. To make it easier to match the log output of
9292
// OpenSearch with this cluster configuration, snake_case is also used here.
9393
#[serde(rename_all = "snake_case")]
94+
#[strum(serialize_all = "snake_case")]
9495
pub enum NodeRole {
9596
// Built-in node roles
9697
// see https://github.com/opensearch-project/OpenSearch/blob/3.0.0/server/src/main/java/org/opensearch/cluster/node/DiscoveryNodeRole.java#L341-L346
97-
98-
// TODO https://github.com/Peternator7/strum/issues/113
99-
#[strum(serialize = "cluster_manager")]
10098
ClusterManager,
101-
#[strum(serialize = "coordinating_only")]
10299
CoordinatingOnly,
103-
#[strum(serialize = "data")]
104100
Data,
105-
#[strum(serialize = "ingest")]
106101
Ingest,
107-
#[strum(serialize = "remote_cluster_client")]
108102
RemoteClusterClient,
109-
#[strum(serialize = "warm")]
110103
Warm,
111104

112105
// Search node role
113106
// see https://github.com/opensearch-project/OpenSearch/blob/3.0.0/server/src/main/java/org/opensearch/cluster/node/DiscoveryNodeRole.java#L313-L339
114-
#[strum(serialize = "search")]
115107
Search,
116108
}
117109

@@ -267,3 +259,29 @@ impl NodeRoles {
267259
}
268260

269261
impl Atomic for NodeRoles {}
262+
263+
#[cfg(test)]
264+
mod tests {
265+
use crate::crd::v1alpha1;
266+
267+
#[test]
268+
fn test_node_role() {
269+
assert_eq!(
270+
String::from("cluster_manager"),
271+
v1alpha1::NodeRole::ClusterManager.to_string()
272+
);
273+
assert_eq!(
274+
String::from("cluster_manager"),
275+
format!("{}", v1alpha1::NodeRole::ClusterManager)
276+
);
277+
assert_eq!(
278+
"\"cluster_manager\"",
279+
serde_json::to_string(&v1alpha1::NodeRole::ClusterManager)
280+
.expect("should be serializable")
281+
);
282+
assert_eq!(
283+
v1alpha1::NodeRole::ClusterManager,
284+
serde_json::from_str("\"cluster_manager\"").expect("should be deserializable")
285+
);
286+
}
287+
}

0 commit comments

Comments
 (0)