-
Notifications
You must be signed in to change notification settings - Fork 0
/
mode_test.go
43 lines (34 loc) · 925 Bytes
/
mode_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 jin
import (
"flag"
"github.com/stretchr/testify/assert"
"os"
"testing"
)
func TestSetMode(t *testing.T) {
_ = os.Setenv(EnvJinMode, TestMode)
mode := os.Getenv(EnvJinMode)
SetMode(mode)
assert.Equal(t, testCode, jinMode)
assert.Equal(t, TestMode, Mode())
_ = os.Unsetenv(EnvJinMode)
SetMode("")
assert.Equal(t, testCode, jinMode)
assert.Equal(t, TestMode, Mode())
tmp := flag.CommandLine
flag.CommandLine = flag.NewFlagSet("", flag.ContinueOnError)
SetMode("")
assert.Equal(t, debugCode, jinMode)
assert.Equal(t, DebugMode, Mode())
flag.CommandLine = tmp
SetMode(DebugMode)
assert.Equal(t, debugCode, jinMode)
assert.Equal(t, DebugMode, Mode())
SetMode(ReleaseMode)
assert.Equal(t, releaseCode, jinMode)
assert.Equal(t, ReleaseMode, Mode())
SetMode(TestMode)
assert.Equal(t, testCode, jinMode)
assert.Equal(t, TestMode, Mode())
assert.Panics(t, func() { SetMode("unknown") })
}