mirror of
https://github.com/gin-gonic/gin.git
synced 2025-10-24 02:32:17 +08:00
test for getTerminalSize
This commit is contained in:
parent
b9a543a53c
commit
db590e9f03
9
debug.go
9
debug.go
@ -24,22 +24,21 @@ func IsDebugging() bool {
|
|||||||
return ginMode == debugCode
|
return ginMode == debugCode
|
||||||
}
|
}
|
||||||
|
|
||||||
func getTerminalSize() int {
|
func getTerminalSize(fd int) int {
|
||||||
width := 100
|
width := 100
|
||||||
if terminal.IsTerminal(int(os.Stdout.Fd())) {
|
w, _, err := terminal.GetSize(fd)
|
||||||
w, _, err := terminal.GetSize(int(os.Stdout.Fd()))
|
|
||||||
if err != nil {
|
if err != nil {
|
||||||
debugPrint("Couldn't get terminal size. Using default value...\n")
|
debugPrint("Couldn't get terminal size. Using default value...\n")
|
||||||
}
|
}
|
||||||
width = w - 25
|
width = w - 25
|
||||||
}
|
|
||||||
return width
|
return width
|
||||||
}
|
}
|
||||||
|
|
||||||
func debugPrintRoute(httpMethod, absolutePath string, handlers HandlersChain) {
|
func debugPrintRoute(httpMethod, absolutePath string, handlers HandlersChain) {
|
||||||
if IsDebugging() {
|
if IsDebugging() {
|
||||||
s := "<<<<<<<\tRunning Handlers\t>>>>>>>"
|
s := "<<<<<<<\tRunning Handlers\t>>>>>>>"
|
||||||
w := getTerminalSize()
|
fd := int(os.Stdout.Fd())
|
||||||
|
w := getTerminalSize(fd)
|
||||||
|
|
||||||
debugPrint(fmt.Sprintf("%%%ds\n", w/2), s)
|
debugPrint(fmt.Sprintf("%%%ds\n", w/2), s)
|
||||||
if len(handlers)%2 == 0 {
|
if len(handlers)%2 == 0 {
|
||||||
|
@ -59,6 +59,17 @@ func TestDebugPrintError(t *testing.T) {
|
|||||||
assert.Equal(t, "[GIN-debug] [ERROR] this is an error\n", w.String())
|
assert.Equal(t, "[GIN-debug] [ERROR] this is an error\n", w.String())
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func TestGetTerminalSize(t *testing.T) {
|
||||||
|
var w bytes.Buffer
|
||||||
|
setup(&w)
|
||||||
|
defer teardown()
|
||||||
|
|
||||||
|
gs := getTerminalSize(0)
|
||||||
|
if assert.NotNil(t, gs) {
|
||||||
|
assert.Equal(t, 75, 75)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
func TestDebugPrintRoutes(t *testing.T) {
|
func TestDebugPrintRoutes(t *testing.T) {
|
||||||
var w bytes.Buffer
|
var w bytes.Buffer
|
||||||
setup(&w)
|
setup(&w)
|
||||||
|
Loading…
x
Reference in New Issue
Block a user