-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy patherrors_test.go
More file actions
171 lines (146 loc) · 5.35 KB
/
Copy patherrors_test.go
File metadata and controls
171 lines (146 loc) · 5.35 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
// Copyright (c) 2019 - Ray Ruan <falconray@yahoo.com>
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
package fsm
import (
"errors"
"github.com/stretchr/testify/assert"
"strconv"
"testing"
)
func TestEventStartReserveMissingError_Error(t *testing.T) {
err := EventStartReserveMissingError{}
assert.Equal(t, `Event {EventID:fsm.EventStartID, Name:fsm.EventStartStr} reserve and should be included in eventMap`, err.Error())
}
func TestEventStartReserveError_Error(t *testing.T) {
err := EventStartReserveError{}
assert.Equal(t, `Event {ID:0, Name:"EventStart"} reserve for all event callback Index`, err.Error())
}
func TestStateStartReserveMissingError_Error(t *testing.T) {
err := StateStartReserveMissingError{}
assert.Equal(t, `State {StateID:fsm.StateStartID, Name:fsm.StateStartStr} reserve and should be included in stateMap`, err.Error() )
}
func TestStateStartReserveError_Error(t *testing.T) {
err := StateStartReserveError{}
assert.Equal(t, `State {ID:0, Name:"StateStart"} reserve for all state callback Index`, err.Error() )
}
func TestDuplicateCallbackEnterStateError_Error(t *testing.T) {
err := DuplicateCallbackEnterStateError{state: "opened"}
assert.Equal(t, "duplicate callback of enter state " + "opened", err.Error())
}
func TestDuplicateCallbackLeaveStateError_Error(t *testing.T) {
err := DuplicateCallbackLeaveStateError{state: "opened"}
assert.Equal(t, "duplicate callback of leave state " + "opened", err.Error())
}
func TestDuplicateCallbackAfterEventError_Error(t *testing.T) {
err := DuplicateCallbackAfterEventError{event: "open"}
assert.Equal(t, "duplicate callback of after event " + "open", err.Error())
}
func TestDuplicateCallbackBeforeEventError_Error(t *testing.T) {
err := DuplicateCallbackBeforeEventError{event: "open"}
assert.Equal(t, "duplicate callback of before event " + "open", err.Error())
}
func TestDuplicateCallbackError_Error(t *testing.T) {
err := DuplicateCallbackError{}
assert.Equal(t, "duplicate callback register", err.Error())
}
func TestDuplicateTransitionError_Error(t *testing.T) {
event := "open"
state := "opened"
err := DuplicateTransitionError{event: event, state: state}
assert.Equal(t, "duplicate transition from { " + event + ", " + state + " }", err.Error())
}
func TestEventOutOfRangeError_Error(t *testing.T) {
const (
EventPlay = iota
EventStop = iota
)
err := EventOutOfRangeError{ID: EventStop}
assert.Equal(t, "eventID " + strconv.Itoa(EventStop) + " out of the range", err.Error())
}
func TestStateOutOfRangeError_Error(t *testing.T) {
const (
StatePlay = iota
StateStop = iota
)
err := StateOutOfRangeError{ID: StateStop}
assert.Equal(t, "stateID " + strconv.Itoa(StateStop) + " out of the range", err.Error())
}
func TestCallbackTypeOutOfRangeError_Error(t *testing.T) {
err := CallbackTypeOutOfRangeError{Type: CallbackEnterState}
assert.Equal(t, "callback type " + strconv.Itoa(CallbackEnterState) + " out of the range", err.Error())
}
func TestInvalidEventError(t *testing.T) {
event := "invalid event"
state := "state"
e := InvalidEventError{Event: event, State: state}
if e.Error() != "event "+e.Event+" inappropriate in current state "+e.State {
t.Error("InvalidEventError string mismatch")
}
}
func TestUnknownEventError(t *testing.T) {
event := "invalid event"
e := UnknownEventError{Event: event}
if e.Error() != "event "+e.Event+" does not exist" {
t.Error("UnknownEventError string mismatch")
}
}
func TestInTransitionError(t *testing.T) {
event := "in transition"
e := InTransitionError{Event: event}
if e.Error() != "event "+e.Event+" inappropriate because previous transition did not complete" {
t.Error("InTransitionError string mismatch")
}
}
func TestNotInTransitionError(t *testing.T) {
e := NotInTransitionError{}
if e.Error() != "transition inappropriate because no state change in progress" {
t.Error("NotInTransitionError string mismatch")
}
}
func TestNoTransitionError(t *testing.T) {
e := NoTransitionError{}
if e.Error() != "no transition" {
t.Error("NoTransitionError string mismatch")
}
e.Err = errors.New("no transition")
if e.Error() != "no transition with error: "+e.Err.Error() {
t.Error("NoTransitionError string mismatch")
}
}
func TestCanceledError(t *testing.T) {
e := CanceledError{}
if e.Error() != "transition canceled" {
t.Error("CanceledError string mismatch")
}
e.Err = errors.New("canceled")
if e.Error() != "transition canceled with error: "+e.Err.Error() {
t.Error("CanceledError string mismatch")
}
}
func TestAsyncError(t *testing.T) {
e := AsyncError{}
if e.Error() != "async started" {
t.Error("AsyncError string mismatch")
}
e.Err = errors.New("async")
if e.Error() != "async started with error: "+e.Err.Error() {
t.Error("AsyncError string mismatch")
}
}
func TestInternalError(t *testing.T) {
e := InternalError{}
if e.Error() != "internal error on state transition" {
t.Error("InternalError string mismatch")
}
}