Fix some tests (#3100)
* Sleep for one millisecond in the handler because the `Latency` will return `0s` sometimes and the test will fail * The `TCPListener.File` is not supported by windows, it is unimplemented now * Remove the `LF` in the `testdata/template/raw.tmpl`, because if set the git config `core.autocrlf=true`, will append `CR` to the raw.tmpl automatically, then test is failed on Windows
This commit is contained in:
parent
696d37e030
commit
444e156fb1
@ -15,6 +15,7 @@ import (
|
|||||||
"net/http/httptest"
|
"net/http/httptest"
|
||||||
"os"
|
"os"
|
||||||
"path/filepath"
|
"path/filepath"
|
||||||
|
"runtime"
|
||||||
"sync"
|
"sync"
|
||||||
"testing"
|
"testing"
|
||||||
"time"
|
"time"
|
||||||
@ -281,7 +282,16 @@ func TestFileDescriptor(t *testing.T) {
|
|||||||
listener, err := net.ListenTCP("tcp", addr)
|
listener, err := net.ListenTCP("tcp", addr)
|
||||||
assert.NoError(t, err)
|
assert.NoError(t, err)
|
||||||
socketFile, err := listener.File()
|
socketFile, err := listener.File()
|
||||||
|
if isWindows() {
|
||||||
|
// not supported by windows, it is unimplemented now
|
||||||
|
assert.Error(t, err)
|
||||||
|
} else {
|
||||||
assert.NoError(t, err)
|
assert.NoError(t, err)
|
||||||
|
}
|
||||||
|
|
||||||
|
if socketFile == nil {
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
go func() {
|
go func() {
|
||||||
router.GET("/example", func(c *Context) { c.String(http.StatusOK, "it worked") })
|
router.GET("/example", func(c *Context) { c.String(http.StatusOK, "it worked") })
|
||||||
@ -547,3 +557,7 @@ func TestTreeRunDynamicRouting(t *testing.T) {
|
|||||||
testRequest(t, ts.URL+"/addr/dd/aa", "404 Not Found")
|
testRequest(t, ts.URL+"/addr/dd/aa", "404 Not Found")
|
||||||
testRequest(t, ts.URL+"/something/secondthing/121", "404 Not Found")
|
testRequest(t, ts.URL+"/something/secondthing/121", "404 Not Found")
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func isWindows() bool {
|
||||||
|
return runtime.GOOS == "windows"
|
||||||
|
}
|
||||||
|
@ -202,7 +202,7 @@ func TestLoadHTMLGlobFromFuncMap(t *testing.T) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
resp, _ := ioutil.ReadAll(res.Body)
|
resp, _ := ioutil.ReadAll(res.Body)
|
||||||
assert.Equal(t, "Date: 2017/07/01\n", string(resp))
|
assert.Equal(t, "Date: 2017/07/01", string(resp))
|
||||||
}
|
}
|
||||||
|
|
||||||
func init() {
|
func init() {
|
||||||
@ -320,7 +320,7 @@ func TestLoadHTMLFilesFuncMap(t *testing.T) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
resp, _ := ioutil.ReadAll(res.Body)
|
resp, _ := ioutil.ReadAll(res.Body)
|
||||||
assert.Equal(t, "Date: 2017/07/01\n", string(resp))
|
assert.Equal(t, "Date: 2017/07/01", string(resp))
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestAddRoute(t *testing.T) {
|
func TestAddRoute(t *testing.T) {
|
||||||
|
@ -208,6 +208,7 @@ func TestLoggerWithConfigFormatting(t *testing.T) {
|
|||||||
// set dummy ClientIP
|
// set dummy ClientIP
|
||||||
c.Request.Header.Set("X-Forwarded-For", "20.20.20.20")
|
c.Request.Header.Set("X-Forwarded-For", "20.20.20.20")
|
||||||
gotKeys = c.Keys
|
gotKeys = c.Keys
|
||||||
|
time.Sleep(time.Millisecond)
|
||||||
})
|
})
|
||||||
PerformRequest(router, "GET", "/example?a=100")
|
PerformRequest(router, "GET", "/example?a=100")
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user