阶段十:完成 Go Cmd Tools 注释基线清零
This commit is contained in:
1 parent
393c45a1e3
commit
ea1f2ec430
25 files changed
+694
-4281
No files matched your search
@@ -11,15 +11,18 @@ import (
|
||||
"golang.org/x/sys/windows"
|
||||
)
|
||||
|
||||
// fakeWindowsServiceController 保存fakeWindowsService请求取消控制器,供当前处理流程使用
|
||||
type fakeWindowsServiceController struct {
|
||||
states []uint32
|
||||
actions []string
|
||||
}
|
||||
|
||||
// state 负责状态相关处理。
|
||||
func (controller *fakeWindowsServiceController) state() (uint32, error) {
|
||||
if len(controller.states) == 0 {
|
||||
return 0, fmt.Errorf("测试状态序列为空")
|
||||
}
|
||||
// state 保存状态,供当前处理流程使用
|
||||
state := controller.states[0]
|
||||
if len(controller.states) > 1 {
|
||||
controller.states = controller.states[1:]
|
||||
@@ -27,19 +30,24 @@ func (controller *fakeWindowsServiceController) state() (uint32, error) {
|
||||
return state, nil
|
||||
}
|
||||
|
||||
// start 负责开始相关处理。
|
||||
func (controller *fakeWindowsServiceController) start() error {
|
||||
controller.actions = append(controller.actions, "start")
|
||||
return nil
|
||||
}
|
||||
|
||||
// stop 负责stop相关处理。
|
||||
func (controller *fakeWindowsServiceController) stop() error {
|
||||
controller.actions = append(controller.actions, "stop")
|
||||
return nil
|
||||
}
|
||||
|
||||
// close 负责close相关处理。
|
||||
func (controller *fakeWindowsServiceController) close() {}
|
||||
|
||||
// TestWindowsRestartWaitsForStoppedBeforeStarting 负责TestWindowsRestartWaitsForStoppedBeforeStarting相关处理。
|
||||
func TestWindowsRestartWaitsForStoppedBeforeStarting(t *testing.T) {
|
||||
// controller 保存请求取消控制器,供当前处理流程使用
|
||||
controller := &fakeWindowsServiceController{
|
||||
states: []uint32{
|
||||
windows.SERVICE_RUNNING,
|
||||
@@ -50,15 +58,19 @@ func TestWindowsRestartWaitsForStoppedBeforeStarting(t *testing.T) {
|
||||
windows.SERVICE_RUNNING,
|
||||
},
|
||||
}
|
||||
if err := controlWindowsService(controller, "restart", time.Second, time.Millisecond); err != nil {
|
||||
if // err 保存err,供当前处理流程使用
|
||||
err := controlWindowsService(controller, "restart", time.Second, time.Millisecond); err != nil {
|
||||
t.Fatalf("restart Windows service: %v", err)
|
||||
}
|
||||
if want := []string{"stop", "start"}; !reflect.DeepEqual(controller.actions, want) {
|
||||
if // want 保存want,供当前处理流程使用
|
||||
want := []string{"stop", "start"}; !reflect.DeepEqual(controller.actions, want) {
|
||||
t.Fatalf("actions = %v, want %v", controller.actions, want)
|
||||
}
|
||||
}
|
||||
|
||||
// TestWindowsStartWaitsForPreviousStop 负责TestWindows开始WaitsForPreviousStop相关处理。
|
||||
func TestWindowsStartWaitsForPreviousStop(t *testing.T) {
|
||||
// controller 保存请求取消控制器,供当前处理流程使用
|
||||
controller := &fakeWindowsServiceController{
|
||||
states: []uint32{
|
||||
windows.SERVICE_STOP_PENDING,
|
||||
@@ -67,15 +79,19 @@ func TestWindowsStartWaitsForPreviousStop(t *testing.T) {
|
||||
windows.SERVICE_RUNNING,
|
||||
},
|
||||
}
|
||||
if err := controlWindowsService(controller, "start", time.Second, time.Millisecond); err != nil {
|
||||
if // err 保存err,供当前处理流程使用
|
||||
err := controlWindowsService(controller, "start", time.Second, time.Millisecond); err != nil {
|
||||
t.Fatalf("start Windows service: %v", err)
|
||||
}
|
||||
if want := []string{"start"}; !reflect.DeepEqual(controller.actions, want) {
|
||||
if // want 保存want,供当前处理流程使用
|
||||
want := []string{"start"}; !reflect.DeepEqual(controller.actions, want) {
|
||||
t.Fatalf("actions = %v, want %v", controller.actions, want)
|
||||
}
|
||||
}
|
||||
|
||||
// TestWindowsServiceAccessIsLimitedToStatusStartStop 负责TestWindowsServiceAccessIsLimitedTo状态开始Stop相关处理。
|
||||
func TestWindowsServiceAccessIsLimitedToStatusStartStop(t *testing.T) {
|
||||
// want 保存want,供当前处理流程使用
|
||||
want := uint32(windows.SERVICE_QUERY_STATUS | windows.SERVICE_START | windows.SERVICE_STOP)
|
||||
if windowsServiceAccess != want {
|
||||
t.Fatalf("service access = %#x, want %#x", windowsServiceAccess, want)
|
||||
|
||||
Reference in new issue
Block a user