Skip to content

Commit 49717d3

Browse files
committed
chore: prealloc slices
1 parent 2842148 commit 49717d3

File tree

4 files changed

+8
-8
lines changed

4 files changed

+8
-8
lines changed

builder/upcloud/artifact.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ func (a *Artifact) Files() []string {
3232
}
3333

3434
func (a *Artifact) Id() string { //nolint:revive // method is required by packer-plugin-sdk
35-
result := []string{}
35+
result := make([]string, 0, len(a.Templates))
3636
for _, t := range a.Templates {
3737
result = append(result, t.UUID)
3838
}

builder/upcloud/artifact_test.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ func TestArtifact_Id(t *testing.T) {
2424
uuid2 := "some-uuid-2"
2525
expected := fmt.Sprintf("%s,%s", uuid1, uuid2)
2626

27-
templates := []*upcloud.Storage{}
27+
templates := make([]*upcloud.Storage, 0, 2)
2828
templates = append(templates, &upcloud.Storage{UUID: uuid1}, &upcloud.Storage{UUID: uuid2})
2929

3030
a := &Artifact{Templates: templates}
@@ -39,7 +39,7 @@ func TestArtifact_String(t *testing.T) {
3939
t.Parallel()
4040
expected := `Storage template created, UUID: some-uuid`
4141

42-
templates := []*upcloud.Storage{}
42+
templates := make([]*upcloud.Storage, 0, 1)
4343
templates = append(templates, &upcloud.Storage{UUID: "some-uuid"})
4444

4545
a := &Artifact{Templates: templates}
@@ -52,7 +52,7 @@ func TestArtifact_String(t *testing.T) {
5252

5353
func TestArtifact_Metadata(t *testing.T) {
5454
t.Parallel()
55-
templates := []*upcloud.Storage{}
55+
templates := make([]*upcloud.Storage, 0, 2)
5656
templates = append(templates,
5757
&upcloud.Storage{
5858
UUID: "some-uuid",

builder/upcloud/utils.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -63,9 +63,9 @@ func sshHostCallback(state multistep.StateBag) (string, error) {
6363
}
6464

6565
func convertNetworkTypes(rawNetworking []NetworkInterface) []request.CreateServerInterface {
66-
networking := []request.CreateServerInterface{}
66+
networking := make([]request.CreateServerInterface, 0, len(rawNetworking))
6767
for _, iface := range rawNetworking {
68-
ips := []request.CreateServerIPAddress{}
68+
ips := make([]request.CreateServerIPAddress, 0, len(iface.IPAddresses))
6969
for _, ip := range iface.IPAddresses {
7070
ips = append(ips, request.CreateServerIPAddress{Family: ip.Family, Address: ip.Address})
7171
}

post-processor/upcloud-import/config_test.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -60,8 +60,8 @@ func TestNewConfig_BothAuthMethods(t *testing.T) {
6060

6161
assert.NoError(t, err)
6262
assert.Equal(t, "test-api-token", c.Token)
63-
assert.Equal(t, "", c.Username)
64-
assert.Equal(t, "", c.Password)
63+
assert.Empty(t, c.Username)
64+
assert.Empty(t, c.Password)
6565
}
6666

6767
func TestNewConfig_NoAuthMethods(t *testing.T) {

0 commit comments

Comments
 (0)