-
-
Notifications
You must be signed in to change notification settings - Fork 5
/
tests_test.go
130 lines (105 loc) · 2.33 KB
/
tests_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
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
package utils
import (
"context"
"fmt"
"testing"
"time"
"github.com/stretchr/testify/require"
)
// MockTB mock testing.TB
type MockTB struct {
testing.TB
}
// Cleanup mock testing.TB Cleanup
func (t *MockTB) Cleanup(func()) {
fmt.Println("Cleanup")
}
// Error mock testing.TB Error
func (t *MockTB) Error(args ...any) {
fmt.Println("Error")
}
// Errorf mock testing.TB Errorf
func (t *MockTB) Errorf(format string, args ...any) {
fmt.Println("Errorf")
}
// Fail mock testing.TB Fail
func (t *MockTB) Fail() {
fmt.Println("Fail")
}
// FailNow mock testing.TB FailNow
func (t *MockTB) FailNow() {
fmt.Println("FailNow")
}
// Failed mock testing.TB Failed
func (t *MockTB) Failed() bool {
fmt.Println("Failed")
return false
}
// Fatal mock testing.TB Fatal
func (t *MockTB) Fatal(args ...any) {
fmt.Println("Fatal")
}
// Fatalf mock testing.TB Fatalf
func (t *MockTB) Fatalf(format string, args ...any) {
fmt.Println("Fatalf")
}
// Helper mock testing.TB Helper
func (t *MockTB) Helper() {
fmt.Println("Helper")
}
// Log mock testing.TB Log
func (t *MockTB) Log(args ...any) {
fmt.Println("Log")
}
// Logf mock testing.TB Logf
func (t *MockTB) Logf(format string, args ...any) {
fmt.Println("Logf")
}
// Name mock testing.TB Name
func (t *MockTB) Name() string {
fmt.Println("Name")
return ""
}
// Setenv mock testing.TB Setenv
func (t *MockTB) Setenv(key, value string) {
fmt.Println("Setenv")
}
// Skip mock testing.TB Skip
func (t *MockTB) Skip(args ...any) {
fmt.Println("Skip")
}
// SkipNow mock testing.TB SkipNow
func (t *MockTB) SkipNow() {
fmt.Println("SkipNow")
}
// Skipf mock testing.TB Skipf
func (t *MockTB) Skipf(format string, args ...any) {
fmt.Println("Skipf")
}
// Skipped mock testing.TB Skipped
func (t *MockTB) Skipped() bool {
fmt.Println("Skipped")
return false
}
// TempDir mock testing.TB TempDir
func (t *MockTB) TempDir() string {
fmt.Println("TempDir")
return ""
}
// Private mock testing.TB private
func (t *MockTB) Private() {
fmt.Println("private")
}
func TestNewGoroutineTest(t *testing.T) {
testInGoroutine := func(t testing.TB) {
time.Sleep(time.Second)
t.Fail()
}
ctx, cancel := context.WithCancel(context.Background())
defer cancel()
ok := t.Run("fail in goroutine", func(t *testing.T) {
go testInGoroutine(NewGoroutineTest(&MockTB{}, cancel))
<-ctx.Done()
})
require.True(t, ok)
}