OSDN Git Service

delete miner
[bytom/vapor.git] / vendor / github.com / go-kit / kit / log / term / terminal_windows_test.go
1 package term
2
3 import (
4         "fmt"
5         "syscall"
6         "testing"
7 )
8
9 // +build windows
10
11 type myWriter struct {
12         fd uintptr
13 }
14
15 func (w *myWriter) Write(p []byte) (int, error) {
16         return 0, fmt.Errorf("not implemented")
17 }
18
19 func (w *myWriter) Fd() uintptr {
20         return w.fd
21 }
22
23 var procGetStdHandle = kernel32.NewProc("GetStdHandle")
24
25 const stdOutputHandle = ^uintptr(0) - 11 + 1
26
27 func getConsoleHandle() syscall.Handle {
28         ptr, err := syscall.UTF16PtrFromString("CONOUT$")
29
30         if err != nil {
31                 panic(err)
32         }
33
34         handle, err := syscall.CreateFile(ptr, syscall.GENERIC_READ|syscall.GENERIC_WRITE, syscall.FILE_SHARE_READ, nil, syscall.OPEN_EXISTING, 0, 0)
35
36         if err != nil {
37                 panic(err)
38         }
39
40         return handle
41 }
42
43 func TestIsTerminal(t *testing.T) {
44         // This is necessary because depending on whether `go test` is called with
45         // the `-v` option, stdout will or will not be bound, changing the behavior
46         // of the test. So we refer to it directly to avoid flakyness.
47         handle := getConsoleHandle()
48
49         writer := &myWriter{
50                 fd: uintptr(handle),
51         }
52
53         if !IsTerminal(writer) {
54                 t.Errorf("output is supposed to be a terminal")
55         }
56 }
57
58 func TestIsConsole(t *testing.T) {
59         // This is necessary because depending on whether `go test` is called with
60         // the `-v` option, stdout will or will not be bound, changing the behavior
61         // of the test. So we refer to it directly to avoid flakyness.
62         handle := getConsoleHandle()
63
64         writer := &myWriter{
65                 fd: uintptr(handle),
66         }
67
68         if !IsConsole(writer) {
69                 t.Errorf("output is supposed to be a console")
70         }
71 }