github.com/vmware/govmomi@v0.51.0/simulator/registry_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 simulator
     6  
     7  import (
     8  	"fmt"
     9  	"testing"
    10  
    11  	"github.com/vmware/govmomi/vim25/mo"
    12  	"github.com/vmware/govmomi/vim25/types"
    13  )
    14  
    15  func TestRegistry(t *testing.T) {
    16  	r := NewRegistry()
    17  
    18  	ref := types.ManagedObjectReference{Type: "Test", Value: "Test"}
    19  	f := &mo.Folder{}
    20  	f.Self = ref
    21  	r.PutEntity(nil, f)
    22  
    23  	e := r.Get(ref)
    24  
    25  	if e.Reference() != ref {
    26  		t.Fail()
    27  	}
    28  
    29  	r.Remove(NewContext(), ref)
    30  
    31  	if r.Get(ref) != nil {
    32  		t.Fail()
    33  	}
    34  
    35  	r.Put(e)
    36  	e = r.Get(ref)
    37  
    38  	if e.Reference() != ref {
    39  		t.Fail()
    40  	}
    41  }
    42  
    43  func TestRemoveReference(t *testing.T) {
    44  	var refs []types.ManagedObjectReference
    45  
    46  	for i := 0; i < 5; i++ {
    47  		refs = append(refs, types.ManagedObjectReference{Type: "any", Value: fmt.Sprintf("%d", i)})
    48  	}
    49  
    50  	n := len(refs)
    51  
    52  	RemoveReference(&refs, refs[2])
    53  
    54  	if len(refs) != n-1 {
    55  		t.Errorf("%d", len(refs))
    56  	}
    57  }