Compare commits

...

3 Commits

Author SHA1 Message Date
Megan Marsh 0e564b4883 add source_ami_filter test to acceptance tests from packer-regressions 2020-03-11 16:21:16 -07:00
Wilken Rivera b9f1b3c8d4 Fix gosimple S1005 linting issue (#8870)
Results before change
```
⇶  golangci-lint run ./... --disable-all --enable=gosimple | grep 1005
fix/fixer_comm_config.go:48:4: S1005: should write `sshHostPortMinRaw := builders["ssh_host_port_min"]` instead of `sshHostPortMinRaw, _ := builders["ssh_host_port_min"]` (gosimple)
fix/fixer_comm_config.go:64:4: S1005: should write `sshHostPortMaxRaw := builders["ssh_host_port_max"]` instead of `sshHostPortMaxRaw, _ := builders["ssh_host_port_max"]` (gosimple)
fix/fixer_comm_config.go:81:4: S1005: should write `sshSkipNatMappingRaw := builders["ssh_skip_nat_mapping"]` instead of `sshSkipNatMappingRaw, _ := builders["ssh_skip_nat_mapping"]` (gosimple)
packer/artifact_mock.go:47:2: S1005: should write `value := a.StateValues[name]` instead of `value, _ := a.StateValues[name]` (gosimple)
packer/artifact_test.go:31:2: S1005: should write `value := a.state[name]` instead of `value, _ := a.state[name]` (gosimple)
```

Results after change
```
```
2020-03-11 10:30:08 +01:00
Wilken Rivera 66ad6f3483 builders: Fix gosimple S1007 linting issue (#8871)
Results before change
```
⇶  golangci-lint run ./... --disable-all --enable=gosimple | grep 1007
builder/alicloud/ecs/image_config.go:208:9: S1007: should use raw string
post-processor/vsphere-template/step_mark_as_template.go:130:8: S1007: shape twice (gosimple)
builder/azure/arm/config.go:58:27: S1007: should use raw string (`...`)
builder/azure/arm/config.go:59:27: S1007: should use raw string (`...`)
builder/qemu/driver.go:192:15: S1007: should use raw string (`...`)
```

Results after change
```
⇶  golangci-lint run ./... --disable-all --enable=gosimple | grep 1007
```
2020-03-11 10:29:22 +01:00
7 changed files with 42 additions and 11 deletions
+1 -1
View File
@@ -205,7 +205,7 @@ func (c *AlicloudImageConfig) Prepare(ctx *interpolate.Context) []error {
strings.HasPrefix(c.AlicloudImageName, "https://") {
errs = append(errs, fmt.Errorf("image_name can't start with 'http://' or 'https://'"))
}
reg := regexp.MustCompile("\\s+")
reg := regexp.MustCompile(`\s+`)
if reg.FindString(c.AlicloudImageName) != "" {
errs = append(errs, fmt.Errorf("image_name can't include spaces"))
}
+31
View File
@@ -87,6 +87,14 @@ func TestBuilderAcc_forceDeleteSnapshot(t *testing.T) {
})
}
func TestBuilderAcc_testSourceAmiFilter(t *testing.T) {
builderT.Test(t, builderT.TestCase{
PreCheck: func() { testAccPreCheck(t) },
Builder: &Builder{},
Template: testSourceAmiFilter,
})
}
func checkSnapshotsDeleted(snapshotIds []*string) builderT.TestCheckFunc {
return func(artifacts []packer.Artifact) error {
// Verify the snapshots are gone
@@ -344,6 +352,29 @@ const testBuilderAccEncrypted = `
}
`
const testSourceAmiFilter = `
{
"builders": [{
"type": "test",
"ami_name": "packer-filter-test-{{timestamp}}",
"region": "us-east-1",
"instance_type": "t2.micro",
"ssh_username": "ubuntu",
"source_ami_filter": {
"filters": {
"name": "*ubuntu-xenial-16.04-amd64-server-*",
"root-device-type": "ebs",
"virtualization-type": "hvm"
},
"most_recent": true,
"owners": [
"099720109477"
]
}
}]
}
`
func buildForceDeregisterConfig(val, name string) string {
return fmt.Sprintf(testBuilderAccForceDeregister, val, name)
}
+4 -4
View File
@@ -55,12 +55,12 @@ const (
)
var (
reCaptureContainerName = regexp.MustCompile("^[a-z0-9][a-z0-9\\-]{2,62}$")
reCaptureNamePrefix = regexp.MustCompile("^[A-Za-z0-9][A-Za-z0-9_\\-\\.]{0,23}$")
reCaptureContainerName = regexp.MustCompile(`^[a-z0-9][a-z0-9\-]{2,62}$`)
reCaptureNamePrefix = regexp.MustCompile(`^[A-Za-z0-9][A-Za-z0-9_\-\.]{0,23}$`)
reManagedDiskName = regexp.MustCompile(validManagedDiskName)
reResourceGroupName = regexp.MustCompile(validResourceGroupNameRe)
reSnapshotName = regexp.MustCompile("^[A-Za-z0-9_]{1,79}$")
reSnapshotPrefix = regexp.MustCompile("^[A-Za-z0-9_]{1,59}$")
reSnapshotName = regexp.MustCompile(`^[A-Za-z0-9_]{1,79}$`)
reSnapshotPrefix = regexp.MustCompile(`^[A-Za-z0-9_]{1,59}$`)
)
type PlanInformation struct {
+1 -1
View File
@@ -189,7 +189,7 @@ func (d *QemuDriver) Version() (string, error) {
versionOutput := strings.TrimSpace(stdout.String())
log.Printf("Qemu --version output: %s", versionOutput)
versionRe := regexp.MustCompile("[\\.[0-9]+]*")
versionRe := regexp.MustCompile(`[\.[0-9]+]*`)
matches := versionRe.FindStringSubmatch(versionOutput)
if len(matches) == 0 {
return "", fmt.Errorf("No version found: %s", versionOutput)
+3 -3
View File
@@ -45,7 +45,7 @@ func (FixerCommConfig) Fix(input map[string]interface{}) (map[string]interface{}
} else if _, ok := builders["ssh_host_port_min"]; ok {
// replace ssh_host_port_min with host_port_min
sshHostPortMinRaw, _ := builders["ssh_host_port_min"]
sshHostPortMinRaw := builders["ssh_host_port_min"]
delete(builders, "ssh_host_port_min")
builders["host_port_min"] = sshHostPortMinRaw
}
@@ -61,7 +61,7 @@ func (FixerCommConfig) Fix(input map[string]interface{}) (map[string]interface{}
} else if _, ok := builders["ssh_host_port_max"]; ok {
// replace ssh_host_port_max with host_port_max
sshHostPortMaxRaw, _ := builders["ssh_host_port_max"]
sshHostPortMaxRaw := builders["ssh_host_port_max"]
delete(builders, "ssh_host_port_max")
builders["host_port_max"] = sshHostPortMaxRaw
@@ -78,7 +78,7 @@ func (FixerCommConfig) Fix(input map[string]interface{}) (map[string]interface{}
} else if _, ok := builders["ssh_skip_nat_mapping"]; ok {
// replace ssh_skip_nat_mapping with skip_nat_mapping
sshSkipNatMappingRaw, _ := builders["ssh_skip_nat_mapping"]
sshSkipNatMappingRaw := builders["ssh_skip_nat_mapping"]
sshSkipNatMappingBool, ok := sshSkipNatMappingRaw.(bool)
if ok {
delete(builders, "ssh_skip_nat_mapping")
+1 -1
View File
@@ -44,7 +44,7 @@ func (a *MockArtifact) String() string {
}
func (a *MockArtifact) State(name string) interface{} {
value, _ := a.StateValues[name]
value := a.StateValues[name]
return value
}
+1 -1
View File
@@ -28,7 +28,7 @@ func (*TestArtifact) String() string {
}
func (a *TestArtifact) State(name string) interface{} {
value, _ := a.state[name]
value := a.state[name]
return value
}