From 098a0ef68ac9c09f4566c4c3eba7a795a3575f1c Mon Sep 17 00:00:00 2001 From: "James F. Carter" Date: Wed, 4 Apr 2018 14:54:29 +0100 Subject: [PATCH] improve command desription, more tests --- cmd/bytemark/commands/update/server.go | 4 +++ cmd/bytemark/commands/update/server_test.go | 38 +++++++++++++++++---- 2 files changed, 35 insertions(+), 7 deletions(-) diff --git a/cmd/bytemark/commands/update/server.go b/cmd/bytemark/commands/update/server.go index a604d4a6..e5122041 100644 --- a/cmd/bytemark/commands/update/server.go +++ b/cmd/bytemark/commands/update/server.go @@ -21,6 +21,10 @@ func init() { Note that for changes to memory or hardware profile to take effect you will need to restart the server. +--hw-profile the hardware profile used. Hardware profiles can be simply thought of as what virtual motherboard you're using - generally you want a pretty recent one for maximum speed, but if you're running a very old or experimental OS (e.g. DOS or OS/2 or something) you may require the compatibility one. See "bytemark hwprofiles" for which ones are currently available. + +Memory is specified in GiB by default, but can be suffixed with an M to indicate that it is provided in MiB. + Updating a server's name also allows it to be moved between groups and accounts you administer. EXAMPLES diff --git a/cmd/bytemark/commands/update/server_test.go b/cmd/bytemark/commands/update/server_test.go index 8806bf87..8886c06b 100644 --- a/cmd/bytemark/commands/update/server_test.go +++ b/cmd/bytemark/commands/update/server_test.go @@ -24,7 +24,7 @@ func TestUpdateServer(t *testing.T) { Name: "test", Hostname: "test.default", GroupID: 1, - Memory: 1024, + Memory: 2048, } type move struct { expected bool @@ -106,18 +106,42 @@ func TestUpdateServer(t *testing.T) { hwProfileLock: true, }, { - name: "ChangeMemory", - args: "--force --memory 10 --server test", + name: "ChangeMemoryDoesNotNeedForceToDecrease", + args: "--memory 1 --server test", vmName: testVMName, vm: testVM, - memory: 10, + memory: 1, + }, + { + name: "ChangeMemoryNeedsForceToIncrease", + args: "--memory 10 --server test", + vmName: testVMName, + vm: testVM, + memory: 10, + shouldErr: true, + }, + { + name: "CombinedChanges", + args: "--new-name new --memory 1 --hw-profile foo --server test", + vmName: testVMName, + vm: testVM, + hwProfile: "foo", + memory: 1, + move: move{ + expected: true, + newName: lib.VirtualMachineName{ + VirtualMachine: "new", + Group: "default", + Account: "default-account", + }, + }, }, } for _, test := range tests { t.Run(test.name, func(t *testing.T) { config, client, app := testutil.BaseTestAuthSetup(t, false, commands.Commands) config.When("GetVirtualMachine").Return(defVM) - client.When("GetVirtualMachine", test.vmName).Return(&test.vm).Times(1) + client.When("GetVirtualMachine", test.vmName).Return(test.vm).Times(1) config.When("Force").Return(true) if test.hwProfile != "" { @@ -128,8 +152,8 @@ func TestUpdateServer(t *testing.T) { client.When("MoveVirtualMachine", test.vmName, test.move.newName).Return(nil).Times(1) } - if test.memory > 0 { - client.When("SetVirtualMachineMemory", test.vmName, test.memory * 1024).Return(nil).Times(1) + if test.memory > 0 && !test.shouldErr { + client.When("SetVirtualMachineMemory", test.vmName, test.memory*1024).Return(nil).Times(1) } args := strings.Split("bytemark update server "+test.args, " ")