Skip to content

Commit 2d005a3

Browse files
committed
fix ci
1 parent 54afc33 commit 2d005a3

File tree

4 files changed

+105
-94
lines changed

4 files changed

+105
-94
lines changed

internal/cmd/storagebox/create.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,7 @@ var CreateCmd = base.CreateCmd[*hcloud.StorageBox]{
5252

5353
return cmd
5454
},
55-
Run: func(s state.State, cmd *cobra.Command, strings []string) (*hcloud.StorageBox, any, error) {
55+
Run: func(s state.State, cmd *cobra.Command, _ []string) (*hcloud.StorageBox, any, error) {
5656
name, _ := cmd.Flags().GetString("name")
5757
sbType, _ := cmd.Flags().GetString("type")
5858
location, _ := cmd.Flags().GetString("location")
@@ -103,7 +103,7 @@ var CreateCmd = base.CreateCmd[*hcloud.StorageBox]{
103103

104104
return storageBox, util.Wrap("storage_box", hcloud.SchemaFromStorageBox(result.StorageBox)), nil
105105
},
106-
PrintResource: func(s state.State, cmd *cobra.Command, storageBox *hcloud.StorageBox) {
106+
PrintResource: func(_ state.State, cmd *cobra.Command, storageBox *hcloud.StorageBox) {
107107
cmd.Printf("Server: %s\n", *storageBox.Server)
108108
cmd.Printf("Username: %s\n", *storageBox.Username)
109109
},

internal/cmd/storagebox/create_test.go

Lines changed: 101 additions & 86 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,13 @@ func TestCreate(t *testing.T) {
2424
cmd := storagebox.CreateCmd.CobraCommand(fx.State())
2525
fx.ExpectEnsureToken()
2626

27+
sb := &hcloud.StorageBox{
28+
ID: 123,
29+
Name: "my-storage-box",
30+
Server: hcloud.Ptr("u12345.your-storagebox.de"),
31+
Username: hcloud.Ptr("u12345"),
32+
}
33+
2734
fx.Client.StorageBoxClient.EXPECT().
2835
Create(gomock.Any(), hcloud.StorageBoxCreateOpts{
2936
Name: "my-storage-box",
@@ -41,20 +48,23 @@ func TestCreate(t *testing.T) {
4148
SSHKeys: []string{"mykey"},
4249
}).
4350
Return(hcloud.StorageBoxCreateResult{
44-
StorageBox: &hcloud.StorageBox{
45-
ID: 123,
46-
Name: "my-storage-box",
47-
},
48-
Action: &hcloud.Action{ID: 456},
51+
StorageBox: sb,
52+
Action: &hcloud.Action{ID: 456},
4953
}, nil, nil)
54+
fx.Client.StorageBoxClient.EXPECT().
55+
GetByID(gomock.Any(), sb.ID).
56+
Return(sb, nil, nil)
5057
fx.ActionWaiter.EXPECT().
5158
WaitForActions(gomock.Any(), gomock.Any(), &hcloud.Action{ID: 456}).
5259
Return(nil)
5360

5461
out, errOut, err := fx.Run(cmd, []string{"--name", "my-storage-box", "--type", "bx11", "--location", "fsn1",
5562
"--password", "my-password", "--enable-samba", "--enable-ssh", "--enable-zfs", "--ssh-key", "mykey"})
5663

57-
expOut := "Storage Box 123 created\n"
64+
expOut := `Storage Box 123 created
65+
Server: u12345.your-storagebox.de
66+
Username: u12345
67+
`
5868

5969
require.NoError(t, err)
6070
assert.Empty(t, errOut)
@@ -68,6 +78,85 @@ func TestCreateJSON(t *testing.T) {
6878
cmd := storagebox.CreateCmd.CobraCommand(fx.State())
6979
fx.ExpectEnsureToken()
7080

81+
sb := &hcloud.StorageBox{
82+
ID: 42,
83+
Username: hcloud.Ptr("u12345"),
84+
Status: hcloud.StorageBoxStatusActive,
85+
Name: "string",
86+
StorageBoxType: &hcloud.StorageBoxType{
87+
ID: 42,
88+
Name: "bx11",
89+
Description: "BX11",
90+
SnapshotLimit: hcloud.Ptr(10),
91+
AutomaticSnapshotLimit: hcloud.Ptr(10),
92+
SubaccountsLimit: 200,
93+
Size: 1073741824,
94+
Pricings: []hcloud.StorageBoxTypeLocationPricing{
95+
{
96+
Location: "fsn1",
97+
PriceHourly: hcloud.Price{
98+
Net: "1.0000",
99+
Gross: "1.1900",
100+
},
101+
PriceMonthly: hcloud.Price{
102+
Net: "1.0000",
103+
Gross: "1.1900",
104+
},
105+
SetupFee: hcloud.Price{
106+
Net: "1.0000",
107+
Gross: "1.1900",
108+
},
109+
},
110+
},
111+
DeprecatableResource: hcloud.DeprecatableResource{
112+
Deprecation: &hcloud.DeprecationInfo{
113+
Announced: time.Date(2023, 6, 1, 0, 0, 0, 0, time.UTC),
114+
UnavailableAfter: time.Date(2023, 9, 1, 0, 0, 0, 0, time.UTC),
115+
},
116+
},
117+
},
118+
Location: &hcloud.Location{
119+
ID: 42,
120+
Name: "fsn1",
121+
Description: "Falkenstein DC Park 1",
122+
Country: "DE",
123+
City: "Falkenstein",
124+
Latitude: 50.47612,
125+
Longitude: 12.370071,
126+
NetworkZone: "eu-central",
127+
},
128+
AccessSettings: hcloud.StorageBoxAccessSettings{
129+
ReachableExternally: false,
130+
SambaEnabled: false,
131+
SSHEnabled: false,
132+
WebDAVEnabled: false,
133+
ZFSEnabled: false,
134+
},
135+
Server: hcloud.Ptr("u1337.your-storagebox.de"),
136+
System: hcloud.Ptr("FSN1-BX355"),
137+
Stats: &hcloud.StorageBoxStats{
138+
Size: 0,
139+
SizeData: 0,
140+
SizeSnapshots: 0,
141+
},
142+
Labels: map[string]string{
143+
"environment": "prod",
144+
"example.com/my": "label",
145+
"just-a-key": "",
146+
},
147+
Protection: hcloud.StorageBoxProtection{
148+
Delete: false,
149+
},
150+
SnapshotPlan: &hcloud.StorageBoxSnapshotPlan{
151+
MaxSnapshots: 0,
152+
Minute: nil,
153+
Hour: nil,
154+
DayOfWeek: nil,
155+
DayOfMonth: nil,
156+
},
157+
Created: time.Date(2016, 1, 30, 23, 55, 0, 0, time.UTC),
158+
}
159+
71160
fx.Client.StorageBoxClient.EXPECT().
72161
Create(gomock.Any(), hcloud.StorageBoxCreateOpts{
73162
Name: "my-storage-box",
@@ -85,86 +174,12 @@ func TestCreateJSON(t *testing.T) {
85174
SSHKeys: []string{"mykey"},
86175
}).
87176
Return(hcloud.StorageBoxCreateResult{
88-
StorageBox: &hcloud.StorageBox{
89-
ID: 42,
90-
Username: hcloud.Ptr("u12345"),
91-
Status: hcloud.StorageBoxStatusActive,
92-
Name: "string",
93-
StorageBoxType: &hcloud.StorageBoxType{
94-
ID: 42,
95-
Name: "bx11",
96-
Description: "BX11",
97-
SnapshotLimit: hcloud.Ptr(10),
98-
AutomaticSnapshotLimit: hcloud.Ptr(10),
99-
SubaccountsLimit: 200,
100-
Size: 1073741824,
101-
Pricings: []hcloud.StorageBoxTypeLocationPricing{
102-
{
103-
Location: "fsn1",
104-
PriceHourly: hcloud.Price{
105-
Net: "1.0000",
106-
Gross: "1.1900",
107-
},
108-
PriceMonthly: hcloud.Price{
109-
Net: "1.0000",
110-
Gross: "1.1900",
111-
},
112-
SetupFee: hcloud.Price{
113-
Net: "1.0000",
114-
Gross: "1.1900",
115-
},
116-
},
117-
},
118-
DeprecatableResource: hcloud.DeprecatableResource{
119-
Deprecation: &hcloud.DeprecationInfo{
120-
Announced: time.Date(2023, 6, 1, 0, 0, 0, 0, time.UTC),
121-
UnavailableAfter: time.Date(2023, 9, 1, 0, 0, 0, 0, time.UTC),
122-
},
123-
},
124-
},
125-
Location: &hcloud.Location{
126-
ID: 42,
127-
Name: "fsn1",
128-
Description: "Falkenstein DC Park 1",
129-
Country: "DE",
130-
City: "Falkenstein",
131-
Latitude: 50.47612,
132-
Longitude: 12.370071,
133-
NetworkZone: "eu-central",
134-
},
135-
AccessSettings: hcloud.StorageBoxAccessSettings{
136-
ReachableExternally: false,
137-
SambaEnabled: false,
138-
SSHEnabled: false,
139-
WebDAVEnabled: false,
140-
ZFSEnabled: false,
141-
},
142-
Server: hcloud.Ptr("u1337.your-storagebox.de"),
143-
System: hcloud.Ptr("FSN1-BX355"),
144-
Stats: &hcloud.StorageBoxStats{
145-
Size: 0,
146-
SizeData: 0,
147-
SizeSnapshots: 0,
148-
},
149-
Labels: map[string]string{
150-
"environment": "prod",
151-
"example.com/my": "label",
152-
"just-a-key": "",
153-
},
154-
Protection: hcloud.StorageBoxProtection{
155-
Delete: false,
156-
},
157-
SnapshotPlan: &hcloud.StorageBoxSnapshotPlan{
158-
MaxSnapshots: 0,
159-
Minute: nil,
160-
Hour: nil,
161-
DayOfWeek: nil,
162-
DayOfMonth: nil,
163-
},
164-
Created: time.Date(2016, 1, 30, 23, 55, 0, 0, time.UTC),
165-
},
166-
Action: &hcloud.Action{ID: 456},
177+
StorageBox: sb,
178+
Action: &hcloud.Action{ID: 456},
167179
}, nil, nil)
180+
fx.Client.StorageBoxClient.EXPECT().
181+
GetByID(gomock.Any(), sb.ID).
182+
Return(sb, nil, nil)
168183
fx.ActionWaiter.EXPECT().
169184
WaitForActions(gomock.Any(), gomock.Any(), &hcloud.Action{ID: 456}).
170185
Return(nil)
@@ -179,6 +194,6 @@ func TestCreateJSON(t *testing.T) {
179194
assert.JSONEq(t, createResponseJSON, jsonOut)
180195
}
181196

182-
func TestCreateProtection(t *testing.T) {
197+
func TestCreateProtection(_ *testing.T) {
183198
// TODO implement once change-protection is implemented
184199
}

internal/cmd/storagebox/list.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,11 +19,11 @@ var ListCmd = base.ListCmd[*hcloud.StorageBox, schema.StorageBox]{
1919
ResourceNamePlural: "Storage Boxes",
2020
JSONKeyGetByName: "storage_boxes",
2121
DefaultColumns: []string{"id", "name", "username", "server", "type", "size", "location", "age"},
22-
Fetch: func(s state.State, set *pflag.FlagSet, opts hcloud.ListOpts, strings []string) ([]*hcloud.StorageBox, error) {
22+
Fetch: func(s state.State, _ *pflag.FlagSet, opts hcloud.ListOpts, _ []string) ([]*hcloud.StorageBox, error) {
2323
listOpts := hcloud.StorageBoxListOpts{ListOpts: opts}
2424
return s.Client().StorageBox().AllWithOpts(s, listOpts)
2525
},
26-
OutputTable: func(t *output.Table, client hcapi2.Client) {
26+
OutputTable: func(t *output.Table, _ hcapi2.Client) {
2727
t.
2828
AddAllowedFields(hcloud.StorageBox{}).
2929
AddFieldFn("type", func(obj any) string {

internal/hcapi2/storage_box.go

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,6 @@ package hcapi2
33
import (
44
"context"
55
"strconv"
6-
"sync"
76

87
"github.com/hetznercloud/hcloud-go/v2/hcloud"
98
)
@@ -22,9 +21,6 @@ func NewStorageBoxClient(client hcloud.IStorageBoxClient) StorageBoxClient {
2221

2322
type storageBoxClient struct {
2423
hcloud.IStorageBoxClient
25-
26-
once sync.Once
27-
err error
2824
}
2925

3026
// Names obtains a list of available Storage Boxes. It returns nil if Storage Box

0 commit comments

Comments
 (0)