-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathmaintest_test.go
43 lines (36 loc) · 928 Bytes
/
maintest_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
package fixenv
import (
"testing"
"github.com/stretchr/testify/assert"
)
func TestCreateMainTestEnv(t *testing.T) {
t.Run("simple", func(t *testing.T) {
at := assert.New(t)
e, cancel := CreateMainTestEnv(nil)
at.Equal(packageScopeName, e.t.Name())
at.NotNil(globalScopeInfo[packageScopeName])
cancel()
at.Nil(globalScopeInfo[packageScopeName])
})
t.Run("fatal_as_panic", func(t *testing.T) {
at := assert.New(t)
e, cancel := CreateMainTestEnv(nil)
defer cancel()
at.Panics(func() {
e.T().Fatalf("asd")
})
})
t.Run("opt_fatal", func(t *testing.T) {
at := assert.New(t)
var fFormat string
var fArgs []interface{}
e, cancel := CreateMainTestEnv(&CreateMainTestEnvOpts{Fatalf: func(format string, args ...interface{}) {
fFormat = format
fArgs = args
}})
defer cancel()
e.T().Fatalf("asd", 1, 2, 3)
at.Equal("asd", fFormat)
at.Equal([]interface{}{1, 2, 3}, fArgs)
})
}