@@ -31,6 +31,7 @@ import (
31
31
"github.com/vmware/govmomi/simulator/esx"
32
32
"github.com/vmware/govmomi/simulator/vpx"
33
33
"github.com/vmware/govmomi/view"
34
+ "github.com/vmware/govmomi/vim25"
34
35
"github.com/vmware/govmomi/vim25/methods"
35
36
"github.com/vmware/govmomi/vim25/mo"
36
37
"github.com/vmware/govmomi/vim25/soap"
@@ -846,6 +847,53 @@ func TestPropertyCollectorInvalidSpecName(t *testing.T) {
846
847
}
847
848
}
848
849
850
+ func TestPropertyCollectorInvalidProperty (t * testing.T ) {
851
+ tests := []struct {
852
+ name string
853
+ path string
854
+ expectedFault types.BaseMethodFault
855
+ }{
856
+ {
857
+ "specify property of array property" ,
858
+ "config.hardware.device.key" ,
859
+ new (types.InvalidProperty ),
860
+ },
861
+ }
862
+
863
+ for _ , test := range tests {
864
+ test := test // assign to local var since loop var is reused
865
+
866
+ t .Run (test .name , func (t * testing.T ) {
867
+ m := ESX ()
868
+
869
+ Test (func (ctx context.Context , c * vim25.Client ) {
870
+ pc := property .DefaultCollector (c )
871
+
872
+ vm := Map .Any ("VirtualMachine" )
873
+ vmRef := vm .Reference ()
874
+
875
+ var vmMo mo.VirtualMachine
876
+ err := pc .RetrieveOne (ctx , vmRef , []string {test .path }, & vmMo )
877
+ if err == nil {
878
+ t .Fatal ("expected error" )
879
+ }
880
+
881
+ // NOTE: since soap.vimFaultError is not exported, use interface literal for assertion instead
882
+ fault , ok := err .(interface {
883
+ Fault () types.BaseMethodFault
884
+ })
885
+ if ! ok {
886
+ t .Fatalf ("err does not have fault: type: %T" , err )
887
+ }
888
+
889
+ if reflect .TypeOf (fault .Fault ()) != reflect .TypeOf (test .expectedFault ) {
890
+ t .Errorf ("expected fault: %T, actual fault: %T" , test .expectedFault , fault .Fault ())
891
+ }
892
+ }, m )
893
+ })
894
+ }
895
+ }
896
+
849
897
func TestPropertyCollectorRecursiveSelectSet (t * testing.T ) {
850
898
ctx := context .Background ()
851
899
0 commit comments