Skip to content

Commit 8186df3

Browse files
authored
refactor: use new(...) for pointers in tests and parser (#509)
Replace temporary variable pointer creation with direct new(...) calls. In Go 1.26, a pointer can be created directly from an expression using new(expr). Instead of declaring a temporary variable just to take its address, you can pass the value or function result directly to new. This removes boilerplate, keeps related logic in one place, and makes pointer initialization easier to read. Signed-off-by: Ryan Johnson <ryan@tenthirtyam.org>
1 parent 9c827a9 commit 8186df3

4 files changed

Lines changed: 7 additions & 8 deletions

File tree

builder/vmware/common/driver_parser.go

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1147,8 +1147,7 @@ func ReadDhcpConfiguration(fd *os.File) (DhcpConfiguration, error) {
11471147
var walkDeclarations func(root pDeclaration, out chan *ConfigDeclaration)
11481148

11491149
walkDeclarations = func(root pDeclaration, out chan *ConfigDeclaration) {
1150-
res := createDeclaration(root)
1151-
out <- &res
1150+
out <- new(createDeclaration(root))
11521151
for _, p := range root.declarations {
11531152
walkDeclarations(p, out)
11541153
}

builder/vmware/common/step_create_disks_test.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ func strPtr(s string) *string {
2222
}
2323
func NewTestCreateDiskStep() *StepCreateDisks {
2424
return &StepCreateDisks{
25-
OutputDir: strPtr("output_dir"),
25+
OutputDir: new("output_dir"),
2626
CreateMainDisk: true,
2727
DiskName: "disk_name",
2828
MainDiskSize: uint(1024),

builder/vmware/common/step_create_snapshot_test.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ func TestStepCreateSnapshot_impl(t *testing.T) {
1717

1818
func NewTestCreateSnapshotStep() *StepCreateSnapshot {
1919
return &StepCreateSnapshot{
20-
SnapshotName: strPtr("snapshot_name"),
20+
SnapshotName: new("snapshot_name"),
2121
}
2222
}
2323

@@ -54,7 +54,7 @@ func TestStepCreateSnapshot(t *testing.T) {
5454
func TestStepCreateSnapshot_skip(t *testing.T) {
5555
state := testState(t)
5656
step := NewTestCreateSnapshotStep()
57-
step.SnapshotName = strPtr("")
57+
step.SnapshotName = new("")
5858

5959
state.Put("vmx_path", "foo")
6060

builder/vmware/common/step_export_test.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,7 @@ func TestStepExport_localArgs(t *testing.T) {
5454
step := new(StepExport)
5555

5656
step.SkipExport = false
57-
step.OutputDir = stringPointer("test_output")
57+
step.OutputDir = new("test_output")
5858
step.VMName = "test-name"
5959
step.Format = "ova"
6060

@@ -88,7 +88,7 @@ func TestStepExport_localArgsExportOutputPath(t *testing.T) {
8888
step := new(StepExport)
8989

9090
step.SkipExport = false
91-
step.OutputDir = stringPointer("test_output")
91+
step.OutputDir = new("test_output")
9292
step.VMName = "test-name"
9393
step.Format = "ova"
9494

@@ -121,7 +121,7 @@ func TestStepExport_localArgs_OvftoolOptions(t *testing.T) {
121121
step := new(StepExport)
122122

123123
step.SkipExport = false
124-
step.OutputDir = stringPointer("test_output")
124+
step.OutputDir = new("test_output")
125125
step.VMName = "test-name"
126126
step.Format = "ova"
127127
step.OVFToolOptions = []string{"--option=value", "--second-option=\"quoted value\""}

0 commit comments

Comments
 (0)