github.com/vmware/govmomi@v0.37.1/simulator/entity_test.go (about)

     1  /*
     2  Copyright (c) 2017 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 simulator
    18  
    19  import (
    20  	"testing"
    21  
    22  	"github.com/vmware/govmomi/vim25/methods"
    23  	"github.com/vmware/govmomi/vim25/types"
    24  )
    25  
    26  func TestRename(t *testing.T) {
    27  	m := VPX()
    28  	m.Datacenter = 2
    29  	m.Folder = 2
    30  
    31  	defer m.Remove()
    32  
    33  	err := m.Create()
    34  	if err != nil {
    35  		t.Fatal(err)
    36  	}
    37  
    38  	s := m.Service.NewServer()
    39  	defer s.Close()
    40  
    41  	dc := Map.Any("Datacenter").(*Datacenter)
    42  	vmFolder := Map.Get(dc.VmFolder).(*Folder)
    43  
    44  	f1 := Map.Get(vmFolder.ChildEntity[0]).(*Folder) // "F1"
    45  
    46  	id := vmFolder.CreateFolder(SpoofContext(), &types.CreateFolder{
    47  		This: vmFolder.Reference(),
    48  		Name: "F2",
    49  	}).(*methods.CreateFolderBody).Res.Returnval
    50  
    51  	f2 := Map.Get(id).(*Folder) // "F2"
    52  
    53  	states := []types.TaskInfoState{types.TaskInfoStateError, types.TaskInfoStateSuccess}
    54  	name := f1.Name
    55  
    56  	for _, expect := range states {
    57  		id = f2.RenameTask(SpoofContext(), &types.Rename_Task{
    58  			This:    f2.Reference(),
    59  			NewName: name,
    60  		}).(*methods.Rename_TaskBody).Res.Returnval
    61  
    62  		task := Map.Get(id).(*Task)
    63  		task.Wait()
    64  
    65  		if task.Info.State != expect {
    66  			t.Errorf("state=%s", task.Info.State)
    67  		}
    68  
    69  		name += "-uniq"
    70  	}
    71  }