Skip to content

Commit

Permalink
Refactor: Rename imports (#1218)
Browse files Browse the repository at this point in the history
* refactor: import `pxapi` as `pveSDK`

* refactor: rename folder
  • Loading branch information
Tinyblargon authored Dec 30, 2024
1 parent 21d0e9e commit d2d69cd
Show file tree
Hide file tree
Showing 13 changed files with 262 additions and 262 deletions.
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
82 changes: 82 additions & 0 deletions proxmox/Internal/pve/guest/tags/tags_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,82 @@
package tags

import (
"testing"

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

func Test_RemoveDuplicates(t *testing.T) {
tests := []struct {
name string
input *[]pveSDK.Tag
output *[]pveSDK.Tag
}{
{name: `nil`},
{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) {
require.Equal(t, test.output, sortArray(RemoveDuplicates(test.input)))
})
}
}

func Test_sort(t *testing.T) {
tests := []struct {
name string
input *[]pveSDK.Tag
output *[]pveSDK.Tag
}{
{name: `nil`},
{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) {
require.Equal(t, test.output, sortArray(test.input))
})
}
}

func Test_Split(t *testing.T) {
tests := []struct {
name string
input string
output *[]pveSDK.Tag
}{
{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) {
require.Equal(t, test.output, Split(test.input))
})
}
}

func Test_String(t *testing.T) {
tests := []struct {
name string
input *[]pveSDK.Tag
output string
}{
{name: `nil`},
{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) {
require.Equal(t, test.output, String(test.input))
})
}
}
82 changes: 0 additions & 82 deletions proxmox/Internal/pxapi/guest/tags/tags_test.go

This file was deleted.

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 d2d69cd

Please sign in to comment.