Skip to content

Commit

Permalink
refactor: import pxapi as pveSDK
Browse files Browse the repository at this point in the history
  • Loading branch information
Tinyblargon committed Dec 30, 2024
1 parent 21d0e9e commit 371b1df
Show file tree
Hide file tree
Showing 10 changed files with 198 additions and 198 deletions.
22 changes: 11 additions & 11 deletions proxmox/Internal/pxapi/guest/tags/tags.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,22 +4,22 @@ import (
"sort"
"strings"

pxapi "github.com/Telmate/proxmox-api-go/proxmox"
pveSDK "github.com/Telmate/proxmox-api-go/proxmox"
"github.com/hashicorp/go-cty/cty"
"github.com/hashicorp/terraform-plugin-sdk/v2/diag"
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema"
)

// Returns an unordered list of unique tags
func RemoveDuplicates(tags *[]pxapi.Tag) *[]pxapi.Tag {
func RemoveDuplicates(tags *[]pveSDK.Tag) *[]pveSDK.Tag {
if tags == nil || len(*tags) == 0 {
return nil
}
tagMap := make(map[pxapi.Tag]struct{})
tagMap := make(map[pveSDK.Tag]struct{})
for _, tag := range *tags {
tagMap[tag] = struct{}{}
}
uniqueTags := make([]pxapi.Tag, len(tagMap))
uniqueTags := make([]pveSDK.Tag, len(tagMap))
var index uint
for tag := range tagMap {
uniqueTags[index] = tag
Expand Down Expand Up @@ -51,7 +51,7 @@ func Schema() *schema.Schema {
}
}

func sortArray(tags *[]pxapi.Tag) *[]pxapi.Tag {
func sortArray(tags *[]pveSDK.Tag) *[]pveSDK.Tag {
if tags == nil || len(*tags) == 0 {
return nil
}
Expand All @@ -61,28 +61,28 @@ func sortArray(tags *[]pxapi.Tag) *[]pxapi.Tag {
return tags
}

func Split(rawTags string) *[]pxapi.Tag {
tags := make([]pxapi.Tag, 0)
func Split(rawTags string) *[]pveSDK.Tag {
tags := make([]pveSDK.Tag, 0)
if rawTags == "" {
return &tags
}
tagArrays := strings.Split(rawTags, ";")
for _, tag := range tagArrays {
tagSubArrays := strings.Split(tag, ",")
if len(tagSubArrays) > 1 {
tmpTags := make([]pxapi.Tag, len(tagSubArrays))
tmpTags := make([]pveSDK.Tag, len(tagSubArrays))
for i, e := range tagSubArrays {
tmpTags[i] = pxapi.Tag(e)
tmpTags[i] = pveSDK.Tag(e)
}
tags = append(tags, tmpTags...)
} else {
tags = append(tags, pxapi.Tag(tag))
tags = append(tags, pveSDK.Tag(tag))
}
}
return &tags
}

func String(tags *[]pxapi.Tag) (tagList string) {
func String(tags *[]pveSDK.Tag) (tagList string) {
if tags == nil || len(*tags) == 0 {
return ""
}
Expand Down
44 changes: 22 additions & 22 deletions proxmox/Internal/pxapi/guest/tags/tags_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,21 +3,21 @@ package tags
import (
"testing"

pxapi "github.com/Telmate/proxmox-api-go/proxmox"
pveSDK "github.com/Telmate/proxmox-api-go/proxmox"
"github.com/stretchr/testify/require"
)

func Test_RemoveDuplicates(t *testing.T) {
tests := []struct {
name string
input *[]pxapi.Tag
output *[]pxapi.Tag
input *[]pveSDK.Tag
output *[]pveSDK.Tag
}{
{name: `nil`},
{name: `empty`, input: &[]pxapi.Tag{}},
{name: `single`, input: &[]pxapi.Tag{"a"}, output: &[]pxapi.Tag{"a"}},
{name: `multiple`, input: &[]pxapi.Tag{"b", "a", "c"}, output: &[]pxapi.Tag{"a", "b", "c"}},
{name: `duplicate`, input: &[]pxapi.Tag{"b", "a", "c", "b", "a"}, output: &[]pxapi.Tag{"a", "b", "c"}},
{name: `empty`, input: &[]pveSDK.Tag{}},
{name: `single`, input: &[]pveSDK.Tag{"a"}, output: &[]pveSDK.Tag{"a"}},
{name: `multiple`, input: &[]pveSDK.Tag{"b", "a", "c"}, output: &[]pveSDK.Tag{"a", "b", "c"}},
{name: `duplicate`, input: &[]pveSDK.Tag{"b", "a", "c", "b", "a"}, output: &[]pveSDK.Tag{"a", "b", "c"}},
}
for _, test := range tests {
t.Run(test.name, func(t *testing.T) {
Expand All @@ -29,13 +29,13 @@ func Test_RemoveDuplicates(t *testing.T) {
func Test_sort(t *testing.T) {
tests := []struct {
name string
input *[]pxapi.Tag
output *[]pxapi.Tag
input *[]pveSDK.Tag
output *[]pveSDK.Tag
}{
{name: `nil`},
{name: `empty`, input: &[]pxapi.Tag{}},
{name: `single`, input: &[]pxapi.Tag{"a"}, output: &[]pxapi.Tag{"a"}},
{name: `multiple`, input: &[]pxapi.Tag{"b", "a", "c"}, output: &[]pxapi.Tag{"a", "b", "c"}},
{name: `empty`, input: &[]pveSDK.Tag{}},
{name: `single`, input: &[]pveSDK.Tag{"a"}, output: &[]pveSDK.Tag{"a"}},
{name: `multiple`, input: &[]pveSDK.Tag{"b", "a", "c"}, output: &[]pveSDK.Tag{"a", "b", "c"}},
}
for _, test := range tests {
t.Run(test.name, func(t *testing.T) {
Expand All @@ -48,13 +48,13 @@ func Test_Split(t *testing.T) {
tests := []struct {
name string
input string
output *[]pxapi.Tag
output *[]pveSDK.Tag
}{
{name: `empty`, output: &[]pxapi.Tag{}},
{name: `single`, input: "a", output: &[]pxapi.Tag{"a"}},
{name: `multiple ,`, input: "b,a,c", output: &[]pxapi.Tag{"b", "a", "c"}},
{name: `multiple ;`, input: "b;a;c", output: &[]pxapi.Tag{"b", "a", "c"}},
{name: `multiple mixed`, input: "b,a;c,d;e", output: &[]pxapi.Tag{"b", "a", "c", "d", "e"}},
{name: `empty`, output: &[]pveSDK.Tag{}},
{name: `single`, input: "a", output: &[]pveSDK.Tag{"a"}},
{name: `multiple ,`, input: "b,a,c", output: &[]pveSDK.Tag{"b", "a", "c"}},
{name: `multiple ;`, input: "b;a;c", output: &[]pveSDK.Tag{"b", "a", "c"}},
{name: `multiple mixed`, input: "b,a;c,d;e", output: &[]pveSDK.Tag{"b", "a", "c", "d", "e"}},
}
for _, test := range tests {
t.Run(test.name, func(t *testing.T) {
Expand All @@ -66,13 +66,13 @@ func Test_Split(t *testing.T) {
func Test_String(t *testing.T) {
tests := []struct {
name string
input *[]pxapi.Tag
input *[]pveSDK.Tag
output string
}{
{name: `nil`},
{name: `empty`, input: &[]pxapi.Tag{}},
{name: `single`, input: &[]pxapi.Tag{"a"}, output: "a"},
{name: `multiple`, input: &[]pxapi.Tag{"b", "a", "c"}, output: "b;a;c"},
{name: `empty`, input: &[]pveSDK.Tag{}},
{name: `single`, input: &[]pveSDK.Tag{"a"}, output: "a"},
{name: `multiple`, input: &[]pveSDK.Tag{"b", "a", "c"}, output: "b;a;c"},
}
for _, test := range tests {
t.Run(test.name, func(t *testing.T) {
Expand Down
6 changes: 3 additions & 3 deletions proxmox/heper_qemu.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import (
"net"
"strings"

pxapi "github.com/Telmate/proxmox-api-go/proxmox"
pveSDK "github.com/Telmate/proxmox-api-go/proxmox"
"github.com/hashicorp/terraform-plugin-sdk/v2/diag"
)

Expand All @@ -15,7 +15,7 @@ const (
errorGuestAgentNoIPv6Summary string = "Qemu Guest Agent is enabled but no IPv6 address is found"
)

func parseCloudInitInterface(ipConfig pxapi.CloudInitNetworkConfig, ciCustom, skipIPv4, skipIPv6 bool) (conn connectionInfo) {
func parseCloudInitInterface(ipConfig pveSDK.CloudInitNetworkConfig, ciCustom, skipIPv4, skipIPv6 bool) (conn connectionInfo) {
conn.SkipIPv4 = skipIPv4
conn.SkipIPv6 = skipIPv6
if ipConfig.IPv4 != nil {
Expand Down Expand Up @@ -80,7 +80,7 @@ func (conn connectionInfo) hasRequiredIP() bool {
return true
}

func (conn connectionInfo) parsePrimaryIPs(interfaces []pxapi.AgentNetworkInterface, mac net.HardwareAddr) connectionInfo {
func (conn connectionInfo) parsePrimaryIPs(interfaces []pveSDK.AgentNetworkInterface, mac net.HardwareAddr) connectionInfo {
macString := mac.String()
for _, iFace := range interfaces {
if iFace.MacAddress.String() == macString {
Expand Down
Loading

0 comments on commit 371b1df

Please sign in to comment.