From 76d49d57b8a81f7a1c7620bf44eeebc529c41462 Mon Sep 17 00:00:00 2001 From: mykola2312 <49044616+mykola2312@users.noreply.github.com> Date: Tue, 21 Jan 2025 17:30:27 +0200 Subject: [PATCH] begin implementing rpc --- rpc/lux_rpc.go | 17 +++++++++++++++++ tests/lux_rpc_test.go | 42 ++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 59 insertions(+) create mode 100644 rpc/lux_rpc.go create mode 100644 tests/lux_rpc_test.go diff --git a/rpc/lux_rpc.go b/rpc/lux_rpc.go new file mode 100644 index 0000000..92e9c4a --- /dev/null +++ b/rpc/lux_rpc.go @@ -0,0 +1,17 @@ +package rpc + +import "encoding/xml" + +type LuxRpcRequest struct { + XMLName xml.Name `xml:"request"` + RequestID int `xml:"id,attr"` + Controller string `xml:"controller,attr"` + Command string `xml:"command,attr"` + + // Commands specific fields + Hosts []struct { + XMLName xml.Name `xml:"host"` + HostID string `xml:"id,attr"` + Hostname string `xml:"hostname,attr"` + } `xml:"host"` +} diff --git a/tests/lux_rpc_test.go b/tests/lux_rpc_test.go new file mode 100644 index 0000000..5fee861 --- /dev/null +++ b/tests/lux_rpc_test.go @@ -0,0 +1,42 @@ +package tests + +import ( + "encoding/xml" + "lux/rpc" + "testing" +) + +func TestRequestDecoding(t *testing.T) { + var request rpc.LuxRpcRequest + + err := xml.Unmarshal([]byte(``), &request) + if err != nil { + t.Fatal(err) + } + t.Log(request) + + err = xml.Unmarshal([]byte(``), &request) + if err != nil { + t.Fatal(err) + } + t.Log(request) + + err = xml.Unmarshal([]byte(` + + + + `), &request) + if err != nil { + t.Fatal(err) + } + t.Log(request) + + err = xml.Unmarshal([]byte(` + + + `), &request) + if err != nil { + t.Fatal(err) + } + t.Log(request) +}