-
Notifications
You must be signed in to change notification settings - Fork 71
/
Copy pathcircuit_break_buliding_test.go
49 lines (42 loc) · 1.28 KB
/
circuit_break_buliding_test.go
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
package service_decorators
import (
"testing"
"time"
)
func checkUnexpectedError(err error, t *testing.T) {
if err != nil {
t.Error("unexpected error occurred")
}
}
func checkTimeoutSetting(expected time.Duration, actual time.Duration, t *testing.T) {
if actual != expected {
t.Errorf("The timeout should be set as %d, but it is %d", expected, actual)
}
}
func checkMaxCurReq(expected int, actual int, t *testing.T) {
if actual != expected {
t.Errorf("maxCurRequest should be %d, but it is %d",
expected, actual)
}
}
func TestBuildCircuitBreakDecoratorWithSettings(t *testing.T) {
settingTimeout := time.Second * 10
settingMaxCurReq := 10
cbDecorator, err := CreateCircuitBreakDecorator().
WithTimeout(settingTimeout).
Build()
checkUnexpectedError(err, t)
maxCurReq := cbDecorator.Config.maxCurrentRequests
checkMaxCurReq(0, maxCurReq, t)
timeOut := cbDecorator.Config.timeout
checkTimeoutSetting(settingTimeout, timeOut, t)
cbDecorator, err = CreateCircuitBreakDecorator().
WithTimeout(settingTimeout).
WithMaxCurrentRequests(settingMaxCurReq).
Build()
checkUnexpectedError(err, t)
maxCurReq = cbDecorator.Config.maxCurrentRequests
checkMaxCurReq(settingMaxCurReq, maxCurReq, t)
timeOut = cbDecorator.Config.timeout
checkTimeoutSetting(settingTimeout, timeOut, t)
}