github.com/vmware/govmomi@v0.51.0/vslm/simulator/simulator_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_test 6 7 import ( 8 "context" 9 "testing" 10 11 "github.com/vmware/govmomi/fault" 12 "github.com/vmware/govmomi/simulator" 13 "github.com/vmware/govmomi/vim25" 14 "github.com/vmware/govmomi/vim25/soap" 15 "github.com/vmware/govmomi/vim25/types" 16 "github.com/vmware/govmomi/vslm" 17 ) 18 19 func TestClientCookie(t *testing.T) { 20 simulator.Test(func(ctx context.Context, vc *vim25.Client) { 21 c, err := vslm.NewClient(ctx, vc) 22 if err != nil { 23 t.Fatal(err) 24 } 25 26 m := vslm.NewGlobalObjectManager(c) 27 // Using default / expected Header.Cookie.XMLName = vcSessionCookie 28 _, err = m.ListObjectsForSpec(ctx, nil, 1000) 29 if err != nil { 30 t.Fatal(err) 31 } 32 33 // Using invalid Header.Cookie.XMLName = myCookie 34 myCookie := vc.SessionCookie() 35 myCookie.XMLName.Local = "myCookie" 36 37 c.Client.Cookie = func() *soap.HeaderElement { 38 return myCookie 39 } 40 41 _, err = m.ListObjectsForSpec(ctx, nil, 1000) 42 if !fault.Is(err, &types.NotAuthenticated{}) { 43 t.Errorf("err=%#v", err) 44 } 45 }) 46 }