-
Notifications
You must be signed in to change notification settings - Fork 0
/
instance_test.go
66 lines (59 loc) · 1.58 KB
/
instance_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
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
package goretry
import (
"bytes"
"testing"
"time"
)
func TestInstance_logWithoutLogger(t *testing.T) {
withoutLogInstance := Instance{
Logger: nil,
}
withoutLogInstance.log("Test %s", "no logger") // without error or panic
}
func TestInstance_logWithLogger(t *testing.T) {
var buffer bytes.Buffer
instanceWithLogger := Instance{
Logger: &buffer,
}
instanceWithLogger.log("Test %s", "logger")
expected := "Test logger\n"
if buffer.String() != expected {
t.Errorf("Expected: %v, got: %v", expected, buffer.String())
}
}
func TestInstance_sleepWithMaxValue(t *testing.T) {
var buffer bytes.Buffer
instanceWithLogger := Instance{
CeilingSleep: time.Duration(100 * time.Millisecond),
Logger: &buffer,
}
instanceWithLogger.sleep(200 * time.Millisecond)
expected := "sleep 100ms\n"
if buffer.String() != expected {
t.Errorf("Expected: %v, got: %v", expected, buffer.String())
}
}
func TestInstance_sleepWithoutMaxValue(t *testing.T) {
var buffer bytes.Buffer
instanceWithLogger := Instance{
Logger: &buffer,
}
instanceWithLogger.sleep(200 * time.Millisecond)
expected := "sleep 200ms\n"
if buffer.String() != expected {
t.Errorf("Expected: %v, got: %v", expected, buffer.String())
}
}
func TestInstance_sleepWithJitter(t *testing.T) {
var buffer bytes.Buffer
instanceWithLogger := Instance{
Logger: &buffer,
JitterEnabled: true,
JitterFloorSleep: 10 * time.Millisecond,
}
instanceWithLogger.sleep(200 * time.Millisecond)
notExpected := "sleep 200ms\n"
if buffer.String() == notExpected {
t.Errorf("Not expected but got: %v", buffer.String())
}
}