Skip to content

Commit

Permalink
chore(code): fix code inspection warnings (#1375)
Browse files Browse the repository at this point in the history
Signed-off-by: Pavel Boldyrev <[email protected]>
  • Loading branch information
bpg authored Jun 10, 2024
1 parent f3ac15a commit e647b21
Show file tree
Hide file tree
Showing 6 changed files with 11 additions and 18 deletions.
2 changes: 1 addition & 1 deletion fwprovider/ha/resource_hagroup.go
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ func (r *hagroupResource) Schema(
Required: true,
Validators: []validator.String{
stringvalidator.RegexMatches(
regexp.MustCompile(`^[a-zA-Z][a-zA-Z0-9\-_\.]*[a-zA-Z0-9]$`),
regexp.MustCompile(`^[a-zA-Z][a-zA-Z0-9\-_.]*[a-zA-Z0-9]$`),
"must start with a letter, end with a letter or number, be composed of "+
"letters, numbers, '-', '_' and '.', and must be at least 2 characters long",
),
Expand Down
2 changes: 1 addition & 1 deletion fwprovider/ha/resource_haresource.go
Original file line number Diff line number Diff line change
Expand Up @@ -110,7 +110,7 @@ func (r *haResourceResource) Schema(
Optional: true,
Validators: []validator.String{
stringvalidator.RegexMatches(
regexp.MustCompile(`^[a-zA-Z][a-zA-Z0-9\-_\.]*[a-zA-Z0-9]$`),
regexp.MustCompile(`^[a-zA-Z][a-zA-Z0-9\-_.]*[a-zA-Z0-9]$`),
"must start with a letter, end with a letter or number, be composed of "+
"letters, numbers, '-', '_' and '.', and must be at least 2 characters long",
),
Expand Down
8 changes: 6 additions & 2 deletions fwprovider/test/resource_file_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -248,7 +248,9 @@ func uploadSnippetFile(t *testing.T, fileName string) {
f, err := os.Open(fileName)
require.NoError(t, err)

defer f.Close()
defer func(f *os.File) {
_ = f.Close()
}(f)

fname := filepath.Base(fileName)
err = sshClient.NodeStreamUpload(context.Background(), "pve", "/var/lib/vz/",
Expand All @@ -269,7 +271,9 @@ func createFile(t *testing.T, namePattern string, content string) *os.File {
_, err = f.WriteString(content)
require.NoError(t, err)

defer f.Close()
defer func(f *os.File) {
_ = f.Close()
}(f)

t.Cleanup(func() {
_ = os.Remove(f.Name())
Expand Down
2 changes: 1 addition & 1 deletion proxmox/nodes/vms/custom_vga_device.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ type CustomVGADevice struct {
}

// EncodeValues converts a CustomVGADevice struct to a URL value.
func (r CustomVGADevice) EncodeValues(key string, v *url.Values) error {
func (r *CustomVGADevice) EncodeValues(key string, v *url.Values) error {
var values []string

if r.Clipboard != nil {
Expand Down
2 changes: 1 addition & 1 deletion proxmoxtf/resource/validators/file.go
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ func FileID() schema.SchemaValidateDiagFunc {
}

if v != "" {
r := regexp.MustCompile(`^(?i)[a-z\d\-_\.]+:([a-z\d\-_]+/)?.+$`)
r := regexp.MustCompile(`^(?i)[a-z\d\-_.]+:([a-z\d\-_]+/)?.+$`)
ok := r.MatchString(v)

if !ok {
Expand Down
13 changes: 1 addition & 12 deletions proxmoxtf/resource/vm/vm.go
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,6 @@ const (
dvInitializationNetworkDataFileID = ""
dvInitializationMetaDataFileID = ""
dvInitializationType = ""
dvInitializationUpgrade = true
dvKeyboardLayout = "en-us"
dvKVMArguments = ""
dvMachineType = ""
Expand Down Expand Up @@ -1513,16 +1512,6 @@ func VM() *schema.Resource {
}
}

// ConvertToStringSlice helps convert interface slice to string slice.
func ConvertToStringSlice(interfaceSlice []interface{}) []string {
resultSlice := []string{}
for _, val := range interfaceSlice {
resultSlice = append(resultSlice, val.(string))
}

return resultSlice
}

func vmCreate(ctx context.Context, d *schema.ResourceData, m interface{}) diag.Diagnostics {
clone := d.Get(mkClone).([]interface{})

Expand Down Expand Up @@ -2873,7 +2862,7 @@ func vmGetCloudInitConfig(d *schema.ResourceData) *vms.CustomCloudInitConfig {
deprecatedServer := initializationDNSBlock[mkInitializationDNSServer].(string)

if len(servers) > 0 {
nameserver := strings.Join(ConvertToStringSlice(servers), " ")
nameserver := strings.Join(utils.ConvertToStringSlice(servers), " ")

initializationConfig.Nameserver = &nameserver
} else if deprecatedServer != "" {
Expand Down

0 comments on commit e647b21

Please sign in to comment.