feat(protocol): ServerState enum
This commit is contained in:
@@ -1 +1,5 @@
|
|||||||
//! Wire types and config schema shared between the xy daemon and CLI.
|
//! Wire types and config schema shared between the xy daemon and CLI.
|
||||||
|
|
||||||
|
pub mod state;
|
||||||
|
|
||||||
|
pub use state::ServerState;
|
||||||
|
|||||||
@@ -0,0 +1,31 @@
|
|||||||
|
use serde::{Deserialize, Serialize};
|
||||||
|
|
||||||
|
#[derive(Debug, Clone, Copy, PartialEq, Eq, Serialize, Deserialize)]
|
||||||
|
#[serde(rename_all = "kebab-case")]
|
||||||
|
pub enum ServerState {
|
||||||
|
Stopped,
|
||||||
|
Starting,
|
||||||
|
Running,
|
||||||
|
Restarting,
|
||||||
|
Failed,
|
||||||
|
Stopping,
|
||||||
|
}
|
||||||
|
|
||||||
|
#[cfg(test)]
|
||||||
|
mod tests {
|
||||||
|
use super::*;
|
||||||
|
|
||||||
|
#[test]
|
||||||
|
fn serializes_to_kebab_case() {
|
||||||
|
assert_eq!(
|
||||||
|
serde_json::to_string(&ServerState::Restarting).unwrap(),
|
||||||
|
"\"restarting\""
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
#[test]
|
||||||
|
fn deserializes_from_kebab_case() {
|
||||||
|
let s: ServerState = serde_json::from_str("\"failed\"").unwrap();
|
||||||
|
assert_eq!(s, ServerState::Failed);
|
||||||
|
}
|
||||||
|
}
|
||||||
Reference in New Issue
Block a user