github.com/vmware/govmomi@v0.43.0/govc/host/esxcli/command_test.go (about) 1 /* 2 Copyright (c) 2014 VMware, Inc. All Rights Reserved. 3 4 Licensed under the Apache License, Version 2.0 (the "License"); 5 you may not use this file except in compliance with the License. 6 You may obtain a copy of the License at 7 8 http://www.apache.org/licenses/LICENSE-2.0 9 10 Unless required by applicable law or agreed to in writing, software 11 distributed under the License is distributed on an "AS IS" BASIS, 12 WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 See the License for the specific language governing permissions and 14 limitations under the License. 15 */ 16 17 package esxcli 18 19 import ( 20 "reflect" 21 "testing" 22 23 "github.com/vmware/govmomi/internal" 24 "github.com/vmware/govmomi/vim25/types" 25 ) 26 27 func TestSystemSettingsAdvancedSetCommand(t *testing.T) { 28 c := NewCommand([]string{"system", "settings", "advanced", "set", "-o", "/Net/GuestIPHack", "-i", "1"}) 29 30 tests := []struct { 31 f func() string 32 expect string 33 }{ 34 {c.Name, "set"}, 35 {c.Namespace, "system.settings.advanced"}, 36 {c.Method, "vim.EsxCLI.system.settings.advanced.set"}, 37 {c.Moid, "ha-cli-handler-system-settings-advanced"}, 38 } 39 40 for _, test := range tests { 41 actual := test.f() 42 if actual != test.expect { 43 t.Errorf("%s != %s", actual, test.expect) 44 } 45 } 46 47 params := []CommandInfoParam{ 48 { 49 CommandInfoItem: CommandInfoItem{Name: "default", DisplayName: "default", Help: "Reset the option to its default value."}, 50 Aliases: []string{"-d", "--default"}, 51 Flag: true, 52 }, 53 { 54 CommandInfoItem: CommandInfoItem{Name: "intvalue", DisplayName: "int-value", Help: "If the option is an integer value use this option."}, 55 Aliases: []string{"-i", "--int-value"}, 56 Flag: false, 57 }, 58 { 59 CommandInfoItem: CommandInfoItem{Name: "option", DisplayName: "option", Help: "The name of the option to set the value of. Example: \"/Misc/HostName\""}, 60 Aliases: []string{"-o", "--option"}, 61 Flag: false, 62 }, 63 { 64 CommandInfoItem: CommandInfoItem{Name: "stringvalue", DisplayName: "string-value", Help: "If the option is a string use this option."}, 65 Aliases: []string{"-s", "--string-value"}, 66 Flag: false, 67 }, 68 } 69 70 args, err := c.Parse(params) 71 if err != nil { 72 t.Fatal(err) 73 } 74 75 expect := []internal.ReflectManagedMethodExecuterSoapArgument{ 76 { 77 DynamicData: types.DynamicData{}, 78 Name: "intvalue", 79 Val: "<intvalue>1</intvalue>", 80 }, 81 { 82 DynamicData: types.DynamicData{}, 83 Name: "option", 84 Val: "<option>/Net/GuestIPHack</option>", 85 }, 86 } 87 88 if !reflect.DeepEqual(args, expect) { 89 t.Errorf("%s != %s", args, expect) 90 } 91 } 92 93 func TestNetworkVmListCommand(t *testing.T) { 94 c := NewCommand([]string{"network", "vm", "list"}) 95 96 tests := []struct { 97 f func() string 98 expect string 99 }{ 100 {c.Name, "list"}, 101 {c.Namespace, "network.vm"}, 102 {c.Method, "vim.EsxCLI.network.vm.list"}, 103 {c.Moid, "ha-cli-handler-network-vm"}, 104 } 105 106 for _, test := range tests { 107 actual := test.f() 108 if actual != test.expect { 109 t.Errorf("%s != %s", actual, test.expect) 110 } 111 } 112 113 var params []CommandInfoParam 114 115 args, err := c.Parse(params) 116 if err != nil { 117 t.Fatal(err) 118 } 119 120 expect := []internal.ReflectManagedMethodExecuterSoapArgument{} 121 122 if !reflect.DeepEqual(args, expect) { 123 t.Errorf("%s != %s", args, expect) 124 } 125 }