Skip to content

Commit

Permalink
improve command desription, more tests
Browse files Browse the repository at this point in the history
  • Loading branch information
James F. Carter committed Apr 4, 2018
1 parent b9630ac commit 098a0ef
Show file tree
Hide file tree
Showing 2 changed files with 35 additions and 7 deletions.
4 changes: 4 additions & 0 deletions cmd/bytemark/commands/update/server.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
38 changes: 31 additions & 7 deletions cmd/bytemark/commands/update/server_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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 != "" {
Expand All @@ -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, " ")
Expand Down

0 comments on commit 098a0ef

Please sign in to comment.