test for getTerminalSize

This commit is contained in:
Jithin James 2017-10-17 16:31:34 +05:30
parent b9a543a53c
commit db590e9f03
2 changed files with 18 additions and 8 deletions

View File

@ -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 {

View File

@ -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)