github.com/vmware/govmomi@v0.37.1/toolbox/power_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 toolbox 18 19 import ( 20 "errors" 21 "testing" 22 ) 23 24 func TestPowerCommandHandler(t *testing.T) { 25 shutdown = "/bin/echo" 26 27 in := new(mockChannelIn) 28 out := new(mockChannelOut) 29 30 service := NewService(in, out) 31 power := service.Power 32 33 // cover nil Handler and out.Receive paths 34 _, _ = power.Halt.Dispatch(nil) 35 36 out.reply = append(out.reply, rpciOK, rpciOK) 37 38 power.Halt.Handler = Halt 39 power.Reboot.Handler = Reboot 40 power.Suspend.Handler = func() error { 41 return errors.New("an error") 42 } 43 44 commands := []PowerCommand{ 45 power.Halt, 46 power.Reboot, 47 power.Suspend, 48 } 49 50 for _, cmd := range commands { 51 _, _ = cmd.Dispatch(nil) 52 } 53 }