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

Function TestParseVMID

pkg/api/utils_test.go:117–180  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

115}
116
117func TestParseVMID(t *testing.T) {
118 tests := []struct {
119 name string
120 input interface{}
121 expected int
122 expectError bool
123 }{
124 {
125 name: "valid integer",
126 input: 123,
127 expected: 123,
128 expectError: false,
129 },
130 {
131 name: "valid float64",
132 input: float64(456),
133 expected: 456,
134 expectError: false,
135 },
136 {
137 name: "valid string number",
138 input: "789",
139 expected: 789,
140 expectError: false,
141 },
142 {
143 name: "invalid string",
144 input: "not-a-number",
145 expected: 0,
146 expectError: true,
147 },
148 {
149 name: "nil input",
150 input: nil,
151 expected: 0,
152 expectError: true,
153 },
154 {
155 name: "negative number",
156 input: -123,
157 expected: -123,
158 expectError: false,
159 },
160 {
161 name: "zero",
162 input: 0,
163 expected: 0,
164 expectError: false,
165 },
166 }
167
168 for _, tt := range tests {
169 t.Run(tt.name, func(t *testing.T) {
170 result, err := ParseVMID(tt.input)
171
172 if tt.expectError {
173 assert.Error(t, err)
174 } else {

Callers

nothing calls this directly

Calls 3

ParseVMIDFunction · 0.85
RunMethod · 0.80
ErrorMethod · 0.65

Tested by

no test coverage detected