From 9a800b3f59878b9c01b7e27beadd7e2575cdb984 Mon Sep 17 00:00:00 2001 From: rcourtman Date: Thu, 5 Feb 2026 12:12:02 +0000 Subject: [PATCH] Add client storage and interface coverage --- .../client_container_interfaces_test.go | 34 +++++++++++++++ pkg/proxmox/client_storage_content_test.go | 42 +++++++++++++++++++ 2 files changed, 76 insertions(+) create mode 100644 pkg/proxmox/client_storage_content_test.go diff --git a/pkg/proxmox/client_container_interfaces_test.go b/pkg/proxmox/client_container_interfaces_test.go index e293aa28a..8d140f043 100644 --- a/pkg/proxmox/client_container_interfaces_test.go +++ b/pkg/proxmox/client_container_interfaces_test.go @@ -2,6 +2,7 @@ package proxmox import ( "context" + "fmt" "net/http" "net/http/httptest" "strings" @@ -37,3 +38,36 @@ func TestClient_GetContainerInterfaces_NonOKStatus(t *testing.T) { t.Fatalf("unexpected error: %v", err) } } + +func TestClient_GetContainerInterfaces_Success(t *testing.T) { + server := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) { + w.Header().Set("Content-Type", "application/json") + if r.URL.Path == "/api2/json/nodes/node1/lxc/101/interfaces" { + fmt.Fprint(w, `{"data":[{"name":"eth0","ip-addresses":[{"ip-address":"10.0.0.2","ip-address-type":"ipv4"}]}]}`) + return + } + w.WriteHeader(http.StatusNotFound) + })) + defer server.Close() + + client, err := NewClient(ClientConfig{ + Host: server.URL, + TokenName: "user@pve!token", + TokenValue: "secret", + VerifySSL: false, + }) + if err != nil { + t.Fatalf("NewClient failed: %v", err) + } + + ifaces, err := client.GetContainerInterfaces(context.Background(), "node1", 101) + if err != nil { + t.Fatalf("GetContainerInterfaces failed: %v", err) + } + if len(ifaces) != 1 || ifaces[0].Name != "eth0" { + t.Fatalf("unexpected interfaces: %+v", ifaces) + } + if len(ifaces[0].IPAddresses) != 1 || ifaces[0].IPAddresses[0].Address != "10.0.0.2" { + t.Fatalf("unexpected ip addresses: %+v", ifaces[0].IPAddresses) + } +} diff --git a/pkg/proxmox/client_storage_content_test.go b/pkg/proxmox/client_storage_content_test.go new file mode 100644 index 000000000..4a1c93c56 --- /dev/null +++ b/pkg/proxmox/client_storage_content_test.go @@ -0,0 +1,42 @@ +package proxmox + +import ( + "context" + "fmt" + "net/http" + "net/http/httptest" + "testing" +) + +func TestClient_GetStorageContentFiltersBackupsAndTemplates(t *testing.T) { + server := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) { + w.Header().Set("Content-Type", "application/json") + if r.URL.Path == "/api2/json/nodes/node1/storage/local/content" { + fmt.Fprint(w, `{"data":[{"volid":"local:backup/ct-100.tar","content":"backup"},{"volid":"local:vztmpl/debian.tar","content":"vztmpl"},{"volid":"local:iso/ubuntu.iso","content":"iso"}]}`) + return + } + w.WriteHeader(http.StatusNotFound) + })) + defer server.Close() + + client, err := NewClient(ClientConfig{ + Host: server.URL, + TokenName: "user@pve!token", + TokenValue: "secret", + VerifySSL: false, + }) + if err != nil { + t.Fatalf("NewClient failed: %v", err) + } + + content, err := client.GetStorageContent(context.Background(), "node1", "local") + if err != nil { + t.Fatalf("GetStorageContent failed: %v", err) + } + if len(content) != 2 { + t.Fatalf("expected 2 content entries, got %d", len(content)) + } + if content[0].Content != "backup" || content[1].Content != "vztmpl" { + t.Fatalf("unexpected content list: %+v", content) + } +}