This repository was archived by the owner on Dec 6, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 30
/
Copy pathmain_test.go
128 lines (108 loc) · 2.21 KB
/
main_test.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
package main
import (
"flag"
"fmt"
"io/ioutil"
"os"
"os/exec"
"regexp"
"strings"
"testing"
"github.com/davecgh/go-spew/spew"
log "github.com/sirupsen/logrus"
)
// ConfigState for spew
var sp spew.ConfigState = spew.ConfigState{
Indent: " ",
DisablePointerAddresses: true,
DisableCapacities: true,
SortKeys: true,
SpewKeys: true,
DisableMethods: true,
}
func show(args ...interface{}) {
fmt.Println(args...)
}
func showf(format string, args ...interface{}) {
fmt.Printf(format+"\\n", args...)
}
func dump(args ...interface{}) {
sp.Dump(args...)
}
func fdump(filenames ...string) {
for _, filename := range filenames {
buf, err := ioutil.ReadFile(filename)
if err == nil {
show(string(buf))
} else {
show(err)
}
}
}
func sdump(args ...interface{}) string {
return sp.Sdump(args...)
}
func grep(search string, data ...interface{}) {
re := regexp.MustCompile(search)
lines := strings.Split(sp.Sdump(data...), "\n")
for _, line := range lines {
//show(line)
if re.Match([]byte(line)) {
show(strings.TrimSpace(line))
}
}
}
func run(cli string) string {
res, err := exec.Command("sh", "-c", cli).CombinedOutput()
if err != nil {
return err.Error()
}
return string(res)
}
type recovering func()
func capture(fn recovering) {
defer func() {
if r := recover(); r != nil {
show("capture:", r)
}
}()
fn()
}
func debug(arg ...interface{}) {
log.Debug(arg...)
}
func trace(arg ...interface{}) {
log.Trace(arg...)
}
func traceOn() {
log.SetLevel(log.TraceLevel)
}
func traceOff() {
log.SetLevel(log.DebugLevel)
}
func TestMain(m *testing.M) {
flag.Parse()
*DryRunFlag = true
*useDefaultAPIKey = true
log.SetOutput(ioutil.Discard)
//decomment this if you to see error log in tests
//log.SetOutput(os.Stderr)
log.SetFormatter(&log.TextFormatter{
DisableColors: true,
DisableTimestamp: true,
})
log.SetLevel(log.DebugLevel)
Version = "test"
os.Setenv("HOME", "/tmp/iosdk-test")
run("rm -Rvf /tmp/iosdk-test ; mkdir /tmp/iosdk-test")
os.Exit(m.Run())
}
func first(arg interface{}, err error) interface{} {
return arg
}
func last(arg interface{}, err error) error {
return err
}
func Example() {
parse("init")
}