nolint:dupl // Test structure similarity is acceptable
(t *testing.T)
| 10 | |
| 11 | //nolint:dupl // Test structure similarity is acceptable |
| 12 | func TestGetNodeUpdates(t *testing.T) { |
| 13 | mockResponse := `{ |
| 14 | "data": [ |
| 15 | { |
| 16 | "Package": "pve-manager", |
| 17 | "Title": "Proxmox VE Manager", |
| 18 | "Version": "7.4-3", |
| 19 | "OldVersion": "7.3-6", |
| 20 | "Arch": "amd64", |
| 21 | "Description": "The Proxmox Virtual Environment Manager", |
| 22 | "Origin": "Proxmox" |
| 23 | } |
| 24 | ] |
| 25 | }` |
| 26 | |
| 27 | server := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) { |
| 28 | if r.URL.Path == testAPITicketPath { |
| 29 | _, _ = w.Write([]byte(`{"data":{"ticket":"ticket","CSRFPreventionToken":"token","username":"user@pam"}}`)) |
| 30 | return |
| 31 | } |
| 32 | if r.URL.Path != "/api2/json/nodes/pve1/apt/update" { |
| 33 | t.Errorf("Expected path /api2/json/nodes/pve1/apt/update, got %s", r.URL.Path) |
| 34 | } |
| 35 | _, _ = w.Write([]byte(mockResponse)) |
| 36 | })) |
| 37 | defer server.Close() |
| 38 | |
| 39 | mockConfig := &MockConfig{ |
| 40 | Addr: server.URL, |
| 41 | User: "user", |
| 42 | Password: "password", |
| 43 | Realm: "pam", |
| 44 | Insecure: true, |
| 45 | } |
| 46 | client, err := NewClient(mockConfig, WithCache(&interfaces.NoOpCache{})) |
| 47 | if err != nil { |
| 48 | t.Fatalf("NewClient failed: %v", err) |
| 49 | } |
| 50 | |
| 51 | updates, err := client.GetNodeUpdates("pve1") |
| 52 | if err != nil { |
| 53 | t.Fatalf("GetNodeUpdates failed: %v", err) |
| 54 | } |
| 55 | |
| 56 | if len(updates) != 1 { |
| 57 | t.Fatalf("Expected 1 update, got %d", len(updates)) |
| 58 | } |
| 59 | |
| 60 | if updates[0].Package != "pve-manager" { |
| 61 | t.Errorf("Expected package 'pve-manager', got '%s'", updates[0].Package) |
| 62 | } |
| 63 | |
| 64 | if updates[0].OldVersion != "7.3-6" { |
| 65 | t.Errorf("Expected old version '7.3-6', got '%s'", updates[0].OldVersion) |
| 66 | } |
| 67 | } |
nothing calls this directly
no test coverage detected