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
15
debug.go
15
debug.go
@ -24,22 +24,21 @@ func IsDebugging() bool {
|
||||
return ginMode == debugCode
|
||||
}
|
||||
|
||||
func getTerminalSize() int {
|
||||
func getTerminalSize(fd int) int {
|
||||
width := 100
|
||||
if terminal.IsTerminal(int(os.Stdout.Fd())) {
|
||||
w, _, err := terminal.GetSize(int(os.Stdout.Fd()))
|
||||
if err != nil {
|
||||
debugPrint("Couldn't get terminal size. Using default value...\n")
|
||||
}
|
||||
width = w - 25
|
||||
w, _, err := terminal.GetSize(fd)
|
||||
if err != nil {
|
||||
debugPrint("Couldn't get terminal size. Using default value...\n")
|
||||
}
|
||||
width = w - 25
|
||||
return width
|
||||
}
|
||||
|
||||
func debugPrintRoute(httpMethod, absolutePath string, handlers HandlersChain) {
|
||||
if IsDebugging() {
|
||||
s := "<<<<<<<\tRunning Handlers\t>>>>>>>"
|
||||
w := getTerminalSize()
|
||||
fd := int(os.Stdout.Fd())
|
||||
w := getTerminalSize(fd)
|
||||
|
||||
debugPrint(fmt.Sprintf("%%%ds\n", w/2), s)
|
||||
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())
|
||||
}
|
||||
|
||||
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) {
|
||||
var w bytes.Buffer
|
||||
setup(&w)
|
||||
|
Loading…
x
Reference in New Issue
Block a user