Skip to content

Commit

Permalink
refactor: move QemuNetworkInterfaceID to seperate file
Browse files Browse the repository at this point in the history
  • Loading branch information
Tinyblargon committed Oct 11, 2024
1 parent 74f3db4 commit 4ee1619
Show file tree
Hide file tree
Showing 4 changed files with 78 additions and 65 deletions.
46 changes: 0 additions & 46 deletions proxmox/config_qemu.go
Original file line number Diff line number Diff line change
Expand Up @@ -1330,49 +1330,3 @@ func (c ConfigQemu) String() string {
jsConf, _ := json.Marshal(c)
return string(jsConf)
}

type QemuNetworkInterfaceID uint8

const (
QemuNetworkInterfaceID_Error_Invalid string = "network interface ID must be in the range 0-31"

QemuNetworkInterfaceID0 QemuNetworkInterfaceID = 0
QemuNetworkInterfaceID1 QemuNetworkInterfaceID = 1
QemuNetworkInterfaceID2 QemuNetworkInterfaceID = 2
QemuNetworkInterfaceID3 QemuNetworkInterfaceID = 3
QemuNetworkInterfaceID4 QemuNetworkInterfaceID = 4
QemuNetworkInterfaceID5 QemuNetworkInterfaceID = 5
QemuNetworkInterfaceID6 QemuNetworkInterfaceID = 6
QemuNetworkInterfaceID7 QemuNetworkInterfaceID = 7
QemuNetworkInterfaceID8 QemuNetworkInterfaceID = 8
QemuNetworkInterfaceID9 QemuNetworkInterfaceID = 9
QemuNetworkInterfaceID10 QemuNetworkInterfaceID = 10
QemuNetworkInterfaceID11 QemuNetworkInterfaceID = 11
QemuNetworkInterfaceID12 QemuNetworkInterfaceID = 12
QemuNetworkInterfaceID13 QemuNetworkInterfaceID = 13
QemuNetworkInterfaceID14 QemuNetworkInterfaceID = 14
QemuNetworkInterfaceID15 QemuNetworkInterfaceID = 15
QemuNetworkInterfaceID16 QemuNetworkInterfaceID = 16
QemuNetworkInterfaceID17 QemuNetworkInterfaceID = 17
QemuNetworkInterfaceID18 QemuNetworkInterfaceID = 18
QemuNetworkInterfaceID19 QemuNetworkInterfaceID = 19
QemuNetworkInterfaceID20 QemuNetworkInterfaceID = 20
QemuNetworkInterfaceID21 QemuNetworkInterfaceID = 21
QemuNetworkInterfaceID22 QemuNetworkInterfaceID = 22
QemuNetworkInterfaceID23 QemuNetworkInterfaceID = 23
QemuNetworkInterfaceID24 QemuNetworkInterfaceID = 24
QemuNetworkInterfaceID25 QemuNetworkInterfaceID = 25
QemuNetworkInterfaceID26 QemuNetworkInterfaceID = 26
QemuNetworkInterfaceID27 QemuNetworkInterfaceID = 27
QemuNetworkInterfaceID28 QemuNetworkInterfaceID = 28
QemuNetworkInterfaceID29 QemuNetworkInterfaceID = 29
QemuNetworkInterfaceID30 QemuNetworkInterfaceID = 30
QemuNetworkInterfaceID31 QemuNetworkInterfaceID = 31
)

func (id QemuNetworkInterfaceID) Validate() error {
if id > 31 {
return errors.New(QemuNetworkInterfaceID_Error_Invalid)
}
return nil
}
51 changes: 51 additions & 0 deletions proxmox/config_qemu_network.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
package proxmox

import "errors"

type QemuNetworkInterfaceID uint8

const (
QemuNetworkInterfaceID_Error_Invalid string = "network interface ID must be in the range 0-31"

QemuNetworkInterfaceID0 QemuNetworkInterfaceID = 0
QemuNetworkInterfaceID1 QemuNetworkInterfaceID = 1
QemuNetworkInterfaceID2 QemuNetworkInterfaceID = 2
QemuNetworkInterfaceID3 QemuNetworkInterfaceID = 3
QemuNetworkInterfaceID4 QemuNetworkInterfaceID = 4
QemuNetworkInterfaceID5 QemuNetworkInterfaceID = 5
QemuNetworkInterfaceID6 QemuNetworkInterfaceID = 6
QemuNetworkInterfaceID7 QemuNetworkInterfaceID = 7
QemuNetworkInterfaceID8 QemuNetworkInterfaceID = 8
QemuNetworkInterfaceID9 QemuNetworkInterfaceID = 9
QemuNetworkInterfaceID10 QemuNetworkInterfaceID = 10
QemuNetworkInterfaceID11 QemuNetworkInterfaceID = 11
QemuNetworkInterfaceID12 QemuNetworkInterfaceID = 12
QemuNetworkInterfaceID13 QemuNetworkInterfaceID = 13
QemuNetworkInterfaceID14 QemuNetworkInterfaceID = 14
QemuNetworkInterfaceID15 QemuNetworkInterfaceID = 15
QemuNetworkInterfaceID16 QemuNetworkInterfaceID = 16
QemuNetworkInterfaceID17 QemuNetworkInterfaceID = 17
QemuNetworkInterfaceID18 QemuNetworkInterfaceID = 18
QemuNetworkInterfaceID19 QemuNetworkInterfaceID = 19
QemuNetworkInterfaceID20 QemuNetworkInterfaceID = 20
QemuNetworkInterfaceID21 QemuNetworkInterfaceID = 21
QemuNetworkInterfaceID22 QemuNetworkInterfaceID = 22
QemuNetworkInterfaceID23 QemuNetworkInterfaceID = 23
QemuNetworkInterfaceID24 QemuNetworkInterfaceID = 24
QemuNetworkInterfaceID25 QemuNetworkInterfaceID = 25
QemuNetworkInterfaceID26 QemuNetworkInterfaceID = 26
QemuNetworkInterfaceID27 QemuNetworkInterfaceID = 27
QemuNetworkInterfaceID28 QemuNetworkInterfaceID = 28
QemuNetworkInterfaceID29 QemuNetworkInterfaceID = 29
QemuNetworkInterfaceID30 QemuNetworkInterfaceID = 30
QemuNetworkInterfaceID31 QemuNetworkInterfaceID = 31

QemuNetworkInterfaceIDMaximum QemuNetworkInterfaceID = QemuNetworkInterfaceID31
)

func (id QemuNetworkInterfaceID) Validate() error {
if id > QemuNetworkInterfaceIDMaximum {
return errors.New(QemuNetworkInterfaceID_Error_Invalid)
}
return nil
}
27 changes: 27 additions & 0 deletions proxmox/config_qemu_network_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
package proxmox

import (
"errors"
"testing"

"github.com/stretchr/testify/require"
)

func Test_QemuNetworkInterfaceID_Validate(t *testing.T) {
tests := []struct {
name string
input QemuNetworkInterfaceID
output error
}{
{name: "Valid",
input: QemuNetworkInterfaceID0},
{name: "Invalid",
input: 32,
output: errors.New(QemuNetworkInterfaceID_Error_Invalid)},
}
for _, test := range tests {
t.Run(test.name, func(t *testing.T) {
require.Equal(t, test.output, test.input.Validate())
})
}
}
19 changes: 0 additions & 19 deletions proxmox/config_qemu_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -7646,22 +7646,3 @@ func Test_ConfigQemu_Validate(t *testing.T) {
}
}
}

func Test_QemuNetworkInterfaceID_Validate(t *testing.T) {
tests := []struct {
name string
input QemuNetworkInterfaceID
output error
}{
{name: "Valid",
input: QemuNetworkInterfaceID0},
{name: "Invalid",
input: 32,
output: errors.New(QemuNetworkInterfaceID_Error_Invalid)},
}
for _, test := range tests {
t.Run(test.name, func(t *testing.T) {
require.Equal(t, test.output, test.input.Validate())
})
}
}

0 comments on commit 4ee1619

Please sign in to comment.