Skip to content

Commit b99852c

Browse files
committed
add missing test
1 parent c006fc1 commit b99852c

File tree

1 file changed

+62
-2
lines changed

1 file changed

+62
-2
lines changed

internal/cmd/storagebox/create_test.go

Lines changed: 62 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -203,6 +203,66 @@ func TestCreateJSON(t *testing.T) {
203203
assert.JSONEq(t, createResponseJSON, jsonOut)
204204
}
205205

206-
func TestCreateProtection(_ *testing.T) {
207-
// TODO implement once change-protection is implemented
206+
func TestCreateProtection(t *testing.T) {
207+
fx := testutil.NewFixture(t)
208+
defer fx.Finish()
209+
210+
cmd := storagebox.CreateCmd.CobraCommand(fx.State())
211+
fx.ExpectEnsureToken()
212+
213+
sb := &hcloud.StorageBox{
214+
ID: 123,
215+
Name: "my-storage-box",
216+
Server: hcloud.Ptr("u12345.your-storagebox.de"),
217+
Username: hcloud.Ptr("u12345"),
218+
}
219+
220+
fx.Client.StorageBoxClient.EXPECT().
221+
Create(gomock.Any(), hcloud.StorageBoxCreateOpts{
222+
Name: "my-storage-box",
223+
StorageBoxType: &hcloud.StorageBoxType{Name: "bx11"},
224+
Location: &hcloud.Location{Name: "fsn1"},
225+
Password: "my-password",
226+
AccessSettings: &hcloud.StorageBoxCreateOptsAccessSettings{
227+
SambaEnabled: hcloud.Ptr(true),
228+
SSHEnabled: hcloud.Ptr(true),
229+
ZFSEnabled: hcloud.Ptr(true),
230+
ReachableExternally: hcloud.Ptr(false),
231+
WebDAVEnabled: hcloud.Ptr(false),
232+
},
233+
Labels: make(map[string]string),
234+
SSHKeys: []string{pubKey1},
235+
}).
236+
Return(hcloud.StorageBoxCreateResult{
237+
StorageBox: sb,
238+
Action: &hcloud.Action{ID: 456},
239+
}, nil, nil)
240+
fx.Client.StorageBoxClient.EXPECT().
241+
ChangeProtection(gomock.Any(), sb, hcloud.StorageBoxChangeProtectionOpts{
242+
Delete: true,
243+
}).
244+
Return(&hcloud.Action{ID: 789}, nil, nil)
245+
fx.ActionWaiter.EXPECT().
246+
WaitForActions(gomock.Any(), gomock.Any(), &hcloud.Action{ID: 789}).
247+
Return(nil)
248+
fx.Client.StorageBoxClient.EXPECT().
249+
GetByID(gomock.Any(), sb.ID).
250+
Return(sb, nil, nil)
251+
fx.ActionWaiter.EXPECT().
252+
WaitForActions(gomock.Any(), gomock.Any(), &hcloud.Action{ID: 456}).
253+
Return(nil)
254+
255+
out, errOut, err := fx.Run(cmd, []string{"--name", "my-storage-box", "--type", "bx11", "--location", "fsn1",
256+
"--password", "my-password", "--enable-samba", "--enable-ssh", "--enable-zfs",
257+
"--ssh-key", pubKey1, "--enable-protection", "delete"})
258+
259+
expOut := `Storage Box 123 created
260+
Resource protection enabled for Storage Box 123
261+
Server: u12345.your-storagebox.de
262+
Username: u12345
263+
`
264+
265+
require.NoError(t, err)
266+
assert.Empty(t, errOut)
267+
assert.Equal(t, expOut, out)
208268
}

0 commit comments

Comments
 (0)