2015-04-08 12:24:49 +00:00
|
|
|
// Copyright 2014 Manu Martinez-Almeida. All rights reserved.
|
|
|
|
// Use of this source code is governed by a MIT style
|
|
|
|
// license that can be found in the LICENSE file.
|
|
|
|
|
|
|
|
package gin
|
|
|
|
|
|
|
|
import (
|
2017-07-05 12:37:28 +00:00
|
|
|
"os"
|
2015-04-08 12:24:49 +00:00
|
|
|
"testing"
|
|
|
|
|
2017-07-10 08:33:35 +00:00
|
|
|
"github.com/gin-gonic/gin/binding"
|
2015-04-08 12:24:49 +00:00
|
|
|
"github.com/stretchr/testify/assert"
|
|
|
|
)
|
|
|
|
|
|
|
|
func init() {
|
2017-07-05 13:05:02 +00:00
|
|
|
os.Setenv(ENV_GIN_MODE, TestMode)
|
2015-04-08 12:24:49 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
func TestSetMode(t *testing.T) {
|
2017-11-21 13:18:45 +00:00
|
|
|
assert.Equal(t, testCode, ginMode)
|
|
|
|
assert.Equal(t, TestMode, Mode())
|
2017-07-05 13:05:02 +00:00
|
|
|
os.Unsetenv(ENV_GIN_MODE)
|
|
|
|
|
2018-02-23 01:09:33 +00:00
|
|
|
SetMode("")
|
|
|
|
assert.Equal(t, debugCode, ginMode)
|
|
|
|
assert.Equal(t, DebugMode, Mode())
|
|
|
|
|
2015-04-08 12:24:49 +00:00
|
|
|
SetMode(DebugMode)
|
2017-11-21 13:18:45 +00:00
|
|
|
assert.Equal(t, debugCode, ginMode)
|
|
|
|
assert.Equal(t, DebugMode, Mode())
|
2015-04-08 12:24:49 +00:00
|
|
|
|
|
|
|
SetMode(ReleaseMode)
|
2017-11-21 13:18:45 +00:00
|
|
|
assert.Equal(t, releaseCode, ginMode)
|
|
|
|
assert.Equal(t, ReleaseMode, Mode())
|
2015-04-08 12:24:49 +00:00
|
|
|
|
|
|
|
SetMode(TestMode)
|
2017-11-21 13:18:45 +00:00
|
|
|
assert.Equal(t, testCode, ginMode)
|
|
|
|
assert.Equal(t, TestMode, Mode())
|
2015-04-08 12:24:49 +00:00
|
|
|
|
|
|
|
assert.Panics(t, func() { SetMode("unknown") })
|
|
|
|
}
|
2017-07-10 08:33:35 +00:00
|
|
|
|
|
|
|
func TestEnableJsonDecoderUseNumber(t *testing.T) {
|
|
|
|
assert.False(t, binding.EnableDecoderUseNumber)
|
|
|
|
EnableJsonDecoderUseNumber()
|
|
|
|
assert.True(t, binding.EnableDecoderUseNumber)
|
|
|
|
}
|