packer: address gosimple lint errors

This commit is contained in:
Lucas Bajolet 2024-07-18 09:13:29 -04:00 committed by Lucas Bajolet
parent e8d3a55b5f
commit 962ccdfc80
10 changed files with 20 additions and 52 deletions

View file

@ -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)

View file

@ -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 {
@ -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.")
}

View file

@ -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"},
}
}
@ -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")
@ -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)

View file

@ -13,7 +13,7 @@ type FixerGalaxyCommand struct{}
func (FixerGalaxyCommand) DeprecatedOptions() map[string][]string {
return map[string][]string{
"ansible": []string{"galaxycommand"},
"ansible": {"galaxycommand"},
}
}
@ -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

View file

@ -12,7 +12,7 @@ type FixerSSHTimout struct{}
func (FixerSSHTimout) DeprecatedOptions() map[string][]string {
return map[string][]string{
"*": []string{"ssh_wait_timeout"},
"*": {"ssh_wait_timeout"},
}
}
@ -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

View file

@ -891,7 +891,7 @@ func (c *Core) renderVarsRecursively() (*interpolate.Context, error) {
for _, kv := range sortedMap {
// Interpolate the default
renderedV, err := interpolate.RenderRegex(kv.Value, ctx, renderFilter)
switch err.(type) {
switch err := err.(type) {
case nil:
// We only get here if interpolation has succeeded, so something is
// different in this loop than in the last one.
@ -910,8 +910,7 @@ func (c *Core) renderVarsRecursively() (*interpolate.Context, error) {
shouldRetry = true
}
case ttmp.ExecError:
castError := err.(ttmp.ExecError)
if strings.Contains(castError.Error(), interpolate.ErrVariableNotSetString) {
if strings.Contains(err.Error(), interpolate.ErrVariableNotSetString) {
shouldRetry = true
failedInterpolation = fmt.Sprintf(`"%s": "%s"; error: %s`, kv.Key, kv.Value, err)
} else {

View file

@ -1022,6 +1022,6 @@ func init() {
// Should never error if both components are set
localAPIVersion, err = NewAPIVersion(fmt.Sprintf("x%s.%s", pluginsdk.APIVersionMajor, pluginsdk.APIVersionMinor))
if err != nil {
panic(fmt.Sprintf("malformed API version in Packer. This is a programming error, please open an error to report it."))
panic("malformed API version in Packer. This is a programming error, please open an error to report it.")
}
}

View file

@ -306,7 +306,6 @@ func (config *Config) detectFromFilename() {
// We didn't match a known compression format. Default to tar + pgzip
config.Algorithm = "pgzip"
config.Archive = "tar"
return
}
func makeBGZFWriter(output io.WriteCloser, compressionLevel int) (io.WriteCloser, error) {

View file

@ -372,10 +372,7 @@ func (p *Provisioner) Provision(ctx context.Context, ui packersdk.Ui, comm packe
if p.config.PauseAfter != 0 {
ui.Say(fmt.Sprintf("Pausing %s after this provisioner...", p.config.PauseAfter))
select {
case <-time.After(p.config.PauseAfter):
return nil
}
time.Sleep(p.config.PauseAfter)
}
return nil

View file

@ -210,17 +210,15 @@ func TestProvision_waitForRestartTimeout(t *testing.T) {
// Block until cancel comes through
waitForCommunicator = func(context.Context, *Provisioner) error {
for {
select {
case <-waitDone:
waitContinue <- true
}
for range waitDone {
}
waitContinue <- true
return nil
}
go func() {
err = p.Provision(context.Background(), ui, comm, make(map[string]interface{}))
waitDone <- true
close(waitDone)
}()
<-waitContinue