Skip to content

Commit

Permalink
Merge pull request #13111 from hashicorp/backport/cleanup_lint_codeba…
Browse files Browse the repository at this point in the history
…se/happily-gentle-ant

This pull request was automerged via backport-assistant
  • Loading branch information
hc-github-team-packer authored Jul 18, 2024
2 parents 0f15855 + f7f7265 commit a8bcc23
Show file tree
Hide file tree
Showing 32 changed files with 86 additions and 237 deletions.
3 changes: 3 additions & 0 deletions .golangci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,9 @@ issues:
- linters:
- lll
source: "^//go:generate "
- linters:
- errcheck
path: ".*_test.go"

# Maximum issues count per one linter. Set to 0 to disable. Default is 50.
max-issues-per-linter: 0
Expand Down
2 changes: 0 additions & 2 deletions builder/file/builder.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,15 +16,13 @@ import (
"path/filepath"

"github.com/hashicorp/hcl/v2/hcldec"
"github.com/hashicorp/packer-plugin-sdk/multistep"
packersdk "github.com/hashicorp/packer-plugin-sdk/packer"
)

const BuilderId = "packer.file"

type Builder struct {
config Config
runner multistep.Runner
}

func (b *Builder) ConfigSpec() hcldec.ObjectSpec { return b.config.FlatMapstructure().HCL2Spec() }
Expand Down
13 changes: 0 additions & 13 deletions builder/null/config_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,19 +18,6 @@ func testConfig() map[string]interface{} {
}
}

func testConfigStruct(t *testing.T) *Config {
var c Config
warns, errs := c.Prepare(testConfig())
if len(warns) > 0 {
t.Fatalf("bad: %#v", len(warns))
}
if errs != nil {
t.Fatalf("bad: %#v", errs)
}

return &c
}

func testConfigErr(t *testing.T, warns []string, err error) {
if len(warns) > 0 {
t.Fatalf("bad: %#v", warns)
Expand Down
11 changes: 0 additions & 11 deletions command/config_file_unix.go

This file was deleted.

11 changes: 0 additions & 11 deletions command/config_file_windows.go

This file was deleted.

2 changes: 1 addition & 1 deletion command/fmt_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -166,7 +166,7 @@ func Test_fmt_pipe(t *testing.T) {
p := helperCommand(t, tc.command...)
p.Stdin = strings.NewReader(tc.piped)
p.Env = append(p.Env, tc.env...)
fmt.Println(fmt.Sprintf("Path: %s", p.Path))
t.Logf("Path: %s", p.Path)
bs, err := p.Output()
if err != nil {
t.Fatalf("Error occurred running command %v: %s", err, bs)
Expand Down
13 changes: 0 additions & 13 deletions command/init_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@
package command

import (
"context"
"fmt"
"log"
"os"
Expand All @@ -16,7 +15,6 @@ import (
"testing"

"github.com/google/go-cmp/cmp"
"github.com/hashicorp/go-getter/v2"
"github.com/hashicorp/packer-plugin-sdk/acctest"
"golang.org/x/mod/sumdb/dirhash"
)
Expand Down Expand Up @@ -312,17 +310,6 @@ func (key skipInitTestUnlessEnVar) fn(t *testing.T, tc testCaseInit) {
// }
}

type initTestGoGetPlugin struct {
Src string
Dst string
}

func (opts initTestGoGetPlugin) fn(t *testing.T, _ testCaseInit) {
if _, err := getter.Get(context.Background(), opts.Dst, opts.Src); err != nil {
t.Fatalf("get: %v", err)
}
}

// TestInitCmd aims to test the init command, with output validation
func TestInitCmd(t *testing.T) {
tests := []struct {
Expand Down
2 changes: 1 addition & 1 deletion datasource/hcp-packer-image/data.go
Original file line number Diff line number Diff line change
Expand Up @@ -188,7 +188,7 @@ func (d *Datasource) Execute() (cty.Value, error) {
iteration.ID)
}

output := DatasourceOutput{}
var output DatasourceOutput

cloudAndRegions := map[string][]string{}
for _, build := range iteration.Builds {
Expand Down
7 changes: 3 additions & 4 deletions datasource/http/data.go
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,7 @@ func isContentTypeText(contentType string) bool {
allowedContentTypes := []*regexp.Regexp{
regexp.MustCompile("^text/.+"),
regexp.MustCompile("^application/json$"),
regexp.MustCompile("^application/samlmetadata\\+xml"),
regexp.MustCompile(`^application/samlmetadata\+xml`),
}

for _, r := range allowedContentTypes {
Expand Down Expand Up @@ -131,9 +131,8 @@ func (d *Datasource) Execute() (cty.Value, error) {

contentType := resp.Header.Get("Content-Type")
if contentType == "" || isContentTypeText(contentType) == false {
fmt.Println(fmt.Sprintf(
"Content-Type is not recognized as a text type, got %q",
contentType))
fmt.Printf("Content-Type is not recognized as a text type, got %q\n",
contentType)
fmt.Println("If the content is binary data, Packer may not properly handle the contents of the response.")
}

Expand Down
24 changes: 4 additions & 20 deletions fix/fixer_comm_config.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ type FixerCommConfig struct{}

func (FixerCommConfig) DeprecatedOptions() map[string][]string {
return map[string][]string{
"*": []string{"ssh_host_port_min", "ssh_host_port_max",
"*": {"ssh_host_port_min", "ssh_host_port_max",
"ssh_skip_nat_mapping"},
}
}
Expand Down Expand Up @@ -46,14 +46,9 @@ func (FixerCommConfig) Fix(input map[string]interface{}) (map[string]interface{}

// ssh_host_port_min to host_port_min
if _, ok := builders["host_port_min"]; ok {

// drop ssh_host_port_min if it is also included
if _, sshHostPortMinIncluded := builders["ssh_host_port_min"]; sshHostPortMinIncluded {
delete(builders, "ssh_host_port_min")
}

delete(builders, "ssh_host_port_min")
} else if _, ok := builders["ssh_host_port_min"]; ok {

// replace ssh_host_port_min with host_port_min
sshHostPortMinRaw := builders["ssh_host_port_min"]
delete(builders, "ssh_host_port_min")
Expand All @@ -62,31 +57,20 @@ func (FixerCommConfig) Fix(input map[string]interface{}) (map[string]interface{}

// ssh_host_port_max to host_port_max
if _, ok := builders["host_port_max"]; ok {

// drop ssh_host_port_max if it is also included
if _, sshHostPortMaxIncluded := builders["ssh_host_port_max"]; sshHostPortMaxIncluded {
delete(builders, "ssh_host_port_max")
}

delete(builders, "ssh_host_port_max")
} else if _, ok := builders["ssh_host_port_max"]; ok {

// replace ssh_host_port_max with host_port_max
sshHostPortMaxRaw := builders["ssh_host_port_max"]
delete(builders, "ssh_host_port_max")
builders["host_port_max"] = sshHostPortMaxRaw

}

// ssh_skip_nat_mapping to skip_nat_mapping
if _, ok := builders["skip_nat_mapping"]; ok {

// drop ssh_skip_nat_mapping if it is also included
if _, sshSkipNatMappingIncluded := builders["ssh_skip_nat_mapping"]; sshSkipNatMappingIncluded {
delete(builders, "ssh_skip_nat_mapping")
}

delete(builders, "ssh_skip_nat_mapping")
} else if _, ok := builders["ssh_skip_nat_mapping"]; ok {

// replace ssh_skip_nat_mapping with skip_nat_mapping
sshSkipNatMappingRaw := builders["ssh_skip_nat_mapping"]
sshSkipNatMappingBool, ok := sshSkipNatMappingRaw.(bool)
Expand Down
8 changes: 2 additions & 6 deletions fix/fixer_galaxy_command.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ type FixerGalaxyCommand struct{}

func (FixerGalaxyCommand) DeprecatedOptions() map[string][]string {
return map[string][]string{
"ansible": []string{"galaxycommand"},
"ansible": {"galaxycommand"},
}
}

Expand All @@ -40,12 +40,8 @@ func (FixerGalaxyCommand) Fix(input map[string]interface{}) (map[string]interfac
}

if _, ok := provisioners["galaxy_command"]; ok {

// drop galaxycommand if it is also included
if _, galaxyCommandIncluded := provisioners["galaxycommand"]; galaxyCommandIncluded {
delete(provisioners, "galaxycommand")
}

delete(provisioners, "galaxycommand")
} else {

// replace galaxycommand with galaxy_command if it exists
Expand Down
8 changes: 2 additions & 6 deletions fix/fixer_ssh_timeout.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ type FixerSSHTimout struct{}

func (FixerSSHTimout) DeprecatedOptions() map[string][]string {
return map[string][]string{
"*": []string{"ssh_wait_timeout"},
"*": {"ssh_wait_timeout"},
}
}

Expand All @@ -35,12 +35,8 @@ func (FixerSSHTimout) Fix(input map[string]interface{}) (map[string]interface{},
}

if _, ok := builders["ssh_timeout"]; ok {

// drop ssh_wait_timeout if it is also included
if _, sshWaitTimeoutIncluded := builders["ssh_wait_timeout"]; sshWaitTimeoutIncluded {
delete(builders, "ssh_wait_timeout")
}

delete(builders, "ssh_wait_timeout")
} else {

// replace ssh_wait_timeout with ssh_timeout if it exists
Expand Down
29 changes: 0 additions & 29 deletions hcl2template/common_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -205,17 +205,6 @@ var (
Datasource: "string",
}

basicMockBuilder = &MockBuilder{
Config: MockConfig{
NestedMockConfig: builderBasicNestedMockConfig,
Nested: builderBasicNestedMockConfig,
NestedSlice: []NestedMockConfig{
builderBasicNestedMockConfig,
builderBasicNestedMockConfig,
},
},
}

basicMockProvisioner = &MockProvisioner{
Config: MockConfig{
NotSquashed: "value <UNKNOWN>",
Expand Down Expand Up @@ -273,17 +262,6 @@ var (
NestedSlice: []NestedMockConfig{},
},
}
basicMockCommunicator = &MockCommunicator{
Config: MockConfig{
NestedMockConfig: basicNestedMockConfig,
Nested: basicNestedMockConfig,
NestedSlice: []NestedMockConfig{
{
Tags: []MockTag{},
},
},
},
}

emptyMockBuilder = &MockBuilder{
Config: MockConfig{
Expand All @@ -295,13 +273,6 @@ var (
},
}

emptyMockProvisioner = &MockProvisioner{
Config: MockConfig{
NestedMockConfig: NestedMockConfig{Tags: []MockTag{}},
NestedSlice: []NestedMockConfig{},
},
}

dynamicTagList = []MockTag{
{
Key: "first_tag_key",
Expand Down
10 changes: 0 additions & 10 deletions hcl2template/functions.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@ package hcl2template
import (
"bytes"
"encoding/base64"
"fmt"

"github.com/hashicorp/go-cty-funcs/cidr"
"github.com/hashicorp/go-cty-funcs/collection"
Expand Down Expand Up @@ -226,12 +225,3 @@ var TextDecodeBase64Func = function.New(&function.Spec{
return cty.StringVal(string(decoded)), nil
},
})

var unimplFunc = function.New(&function.Spec{
Type: func([]cty.Value) (cty.Type, error) {
return cty.DynamicPseudoType, fmt.Errorf("function not yet implemented")
},
Impl: func([]cty.Value, cty.Type) (cty.Value, error) {
return cty.DynamicVal, fmt.Errorf("function not yet implemented")
},
})
1 change: 0 additions & 1 deletion hcl2template/types.packer_config_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,6 @@ import (
var (
refVBIsoUbuntu1204 = SourceRef{Type: "virtualbox-iso", Name: "ubuntu-1204"}
refAWSEBSUbuntu1604 = SourceRef{Type: "amazon-ebs", Name: "ubuntu-1604"}
refAWSV3MyImage = SourceRef{Type: "amazon-v3-ebs", Name: "my-image"}
refNull = SourceRef{Type: "null", Name: "test"}
pTrue = pointerToBool(true)
)
Expand Down
Loading

0 comments on commit a8bcc23

Please sign in to comment.