MCPcopy Create free account
hub / github.com/devnullvoid/pvetui / TestApplyIPFallback

Function TestApplyIPFallback

pkg/api/client_refresh_vm_test.go:5–51  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

3import "testing"
4
5func TestApplyIPFallback(t *testing.T) {
6 tests := []struct {
7 name string
8 vm *VM
9 originalIP string
10 wantIP string
11 }{
12 {
13 name: "sets original IP when refreshed VM has no IP",
14 vm: &VM{IP: ""},
15 originalIP: "192.168.10.25",
16 wantIP: "192.168.10.25",
17 },
18 {
19 name: "keeps refreshed runtime IP",
20 vm: &VM{IP: "10.20.30.40"},
21 originalIP: "192.168.10.25",
22 wantIP: "10.20.30.40",
23 },
24 {
25 name: "keeps empty when no original IP exists",
26 vm: &VM{IP: ""},
27 originalIP: "",
28 wantIP: "",
29 },
30 {
31 name: "nil VM is a no-op",
32 vm: nil,
33 originalIP: "192.168.10.25",
34 wantIP: "",
35 },
36 }
37
38 for _, tt := range tests {
39 t.Run(tt.name, func(t *testing.T) {
40 applyIPFallback(tt.vm, tt.originalIP)
41
42 if tt.vm == nil {
43 return
44 }
45
46 if tt.vm.IP != tt.wantIP {
47 t.Fatalf("unexpected IP: got %q want %q", tt.vm.IP, tt.wantIP)
48 }
49 })
50 }
51}

Callers

nothing calls this directly

Calls 2

applyIPFallbackFunction · 0.85
RunMethod · 0.80

Tested by

no test coverage detected