Add client storage and interface coverage

This commit is contained in:
rcourtman
2026-02-05 12:12:02 +00:00
parent 070bc82f65
commit 9a800b3f59
2 changed files with 76 additions and 0 deletions

View File

@@ -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)
}
}

View File

@@ -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)
}
}