1pub const COMMANDS_ALL: &str = "commands.all";
2
3pub fn commands_group(name: &str) -> String {
4 format!("commands.group.{name}")
5}
6
7pub fn commands_pc(pc_id: &str) -> String {
8 format!("commands.pc.{pc_id}")
9}
10
11pub fn commands_deploy(job_id: &str) -> String {
12 format!("commands.deploy.{job_id}")
13}
14
15pub fn results(request_id: &str) -> String {
16 format!("results.{request_id}")
17}
18
19pub fn heartbeat(pc_id: &str) -> String {
20 format!("heartbeat.{pc_id}")
21}
22
23pub fn kill(job_id: &str) -> String {
24 format!("kill.{job_id}")
25}
26
27pub fn inventory(pc_id: &str, category: &str) -> String {
28 format!("inventory.{pc_id}.{category}")
29}
30
31pub const INVENTORY_HW: &str = "hw";
32pub const INVENTORY_SW: &str = "sw";
33pub const INVENTORY_NET: &str = "net";
34
35#[cfg(test)]
36mod tests {
37 use super::*;
38
39 #[test]
40 fn commands_all_constant() {
41 assert_eq!(COMMANDS_ALL, "commands.all");
42 }
43
44 #[test]
45 fn commands_group_formats_name() {
46 assert_eq!(commands_group("canary"), "commands.group.canary");
47 assert_eq!(commands_group("wave1"), "commands.group.wave1");
48 }
49
50 #[test]
51 fn commands_pc_formats_id() {
52 assert_eq!(commands_pc("minipc"), "commands.pc.minipc");
53 assert_eq!(commands_pc("PC1234"), "commands.pc.PC1234");
54 }
55
56 #[test]
57 fn commands_deploy_formats_job_id() {
58 let job = "3c3c56b3-c83e-4c27-9fa9-4a75e1f5da6f";
59 assert_eq!(
60 commands_deploy(job),
61 "commands.deploy.3c3c56b3-c83e-4c27-9fa9-4a75e1f5da6f"
62 );
63 }
64
65 #[test]
66 fn results_formats_request_id() {
67 assert_eq!(results("req-1"), "results.req-1");
68 }
69
70 #[test]
71 fn heartbeat_formats_pc_id() {
72 assert_eq!(heartbeat("minipc"), "heartbeat.minipc");
73 }
74
75 #[test]
76 fn kill_formats_job_id() {
77 assert_eq!(kill("testjob1"), "kill.testjob1");
78 }
79
80 #[test]
81 fn inventory_formats_pc_id_and_category() {
82 assert_eq!(inventory("minipc", "hw"), "inventory.minipc.hw");
83 assert_eq!(inventory("minipc", INVENTORY_HW), "inventory.minipc.hw");
84 assert_eq!(inventory("minipc", INVENTORY_SW), "inventory.minipc.sw");
85 assert_eq!(inventory("minipc", INVENTORY_NET), "inventory.minipc.net");
86 }
87}