add test case of mode

This commit is contained in:
thinkerou 2017-07-05 21:05:02 +08:00
parent 2a36eefcff
commit f843c33370

View File

@ -12,10 +12,14 @@ import (
) )
func init() { func init() {
SetMode(TestMode) os.Setenv(ENV_GIN_MODE, TestMode)
} }
func TestSetMode(t *testing.T) { func TestSetMode(t *testing.T) {
assert.Equal(t, ginMode, testCode)
assert.Equal(t, Mode(), TestMode)
os.Unsetenv(ENV_GIN_MODE)
SetMode(DebugMode) SetMode(DebugMode)
assert.Equal(t, ginMode, debugCode) assert.Equal(t, ginMode, debugCode)
assert.Equal(t, Mode(), DebugMode) assert.Equal(t, Mode(), DebugMode)
@ -29,9 +33,4 @@ func TestSetMode(t *testing.T) {
assert.Equal(t, Mode(), TestMode) assert.Equal(t, Mode(), TestMode)
assert.Panics(t, func() { SetMode("unknown") }) assert.Panics(t, func() { SetMode("unknown") })
os.Setenv(ENV_GIN_MODE, DebugMode)
assert.Equal(t, ginMode, debugCode)
assert.Equal(t, Mode(), DebugMode)
os.Unsetenv(ENV_GIN_MODE)
} }