github.com/vmware/govmomi@v0.51.0/cli/esx/command_test.go (about)

     1  // © Broadcom. All Rights Reserved.
     2  // The term “Broadcom” refers to Broadcom Inc. and/or its subsidiaries.
     3  // SPDX-License-Identifier: Apache-2.0
     4  
     5  package esx
     6  
     7  import (
     8  	"reflect"
     9  	"testing"
    10  
    11  	"github.com/vmware/govmomi/internal"
    12  	"github.com/vmware/govmomi/vim25/types"
    13  )
    14  
    15  func TestSystemSettingsAdvancedSetCommand(t *testing.T) {
    16  	c := NewCommand([]string{"system", "settings", "advanced", "set", "-o", "/Net/GuestIPHack", "-i", "1"})
    17  
    18  	tests := []struct {
    19  		f      func() string
    20  		expect string
    21  	}{
    22  		{c.Name, "set"},
    23  		{c.Namespace, "system.settings.advanced"},
    24  		{c.Method, "vim.EsxCLI.system.settings.advanced.set"},
    25  		{c.Moid, "ha-cli-handler-system-settings-advanced"},
    26  	}
    27  
    28  	for _, test := range tests {
    29  		actual := test.f()
    30  		if actual != test.expect {
    31  			t.Errorf("%s != %s", actual, test.expect)
    32  		}
    33  	}
    34  
    35  	params := []CommandInfoParam{
    36  		{
    37  			CommandInfoItem: CommandInfoItem{Name: "default", DisplayName: "default", Help: "Reset the option to its default value."},
    38  			Aliases:         []string{"-d", "--default"},
    39  			Flag:            true,
    40  		},
    41  		{
    42  			CommandInfoItem: CommandInfoItem{Name: "intvalue", DisplayName: "int-value", Help: "If the option is an integer value use this option."},
    43  			Aliases:         []string{"-i", "--int-value"},
    44  			Flag:            false,
    45  		},
    46  		{
    47  			CommandInfoItem: CommandInfoItem{Name: "option", DisplayName: "option", Help: "The name of the option to set the value of. Example: \"/Misc/HostName\""},
    48  			Aliases:         []string{"-o", "--option"},
    49  			Flag:            false,
    50  		},
    51  		{
    52  			CommandInfoItem: CommandInfoItem{Name: "stringvalue", DisplayName: "string-value", Help: "If the option is a string use this option."},
    53  			Aliases:         []string{"-s", "--string-value"},
    54  			Flag:            false,
    55  		},
    56  	}
    57  
    58  	args, err := c.Parse(params)
    59  	if err != nil {
    60  		t.Fatal(err)
    61  	}
    62  
    63  	expect := []internal.ReflectManagedMethodExecuterSoapArgument{
    64  		{
    65  			DynamicData: types.DynamicData{},
    66  			Name:        "intvalue",
    67  			Val:         "<intvalue>1</intvalue>",
    68  		},
    69  		{
    70  			DynamicData: types.DynamicData{},
    71  			Name:        "option",
    72  			Val:         "<option>/Net/GuestIPHack</option>",
    73  		},
    74  	}
    75  
    76  	if !reflect.DeepEqual(args, expect) {
    77  		t.Errorf("%s != %s", args, expect)
    78  	}
    79  }
    80  
    81  func TestNetworkVmListCommand(t *testing.T) {
    82  	c := NewCommand([]string{"network", "vm", "list"})
    83  
    84  	tests := []struct {
    85  		f      func() string
    86  		expect string
    87  	}{
    88  		{c.Name, "list"},
    89  		{c.Namespace, "network.vm"},
    90  		{c.Method, "vim.EsxCLI.network.vm.list"},
    91  		{c.Moid, "ha-cli-handler-network-vm"},
    92  	}
    93  
    94  	for _, test := range tests {
    95  		actual := test.f()
    96  		if actual != test.expect {
    97  			t.Errorf("%s != %s", actual, test.expect)
    98  		}
    99  	}
   100  
   101  	var params []CommandInfoParam
   102  
   103  	args, err := c.Parse(params)
   104  	if err != nil {
   105  		t.Fatal(err)
   106  	}
   107  
   108  	expect := []internal.ReflectManagedMethodExecuterSoapArgument{}
   109  
   110  	if !reflect.DeepEqual(args, expect) {
   111  		t.Errorf("%s != %s", args, expect)
   112  	}
   113  }