MCPcopy Index your code
hub / github.com/dearcode/candy / TestMain

Function TestMain

client/candy_test.go:44–101  ·  view source on GitHub ↗
(main *testing.M)

Source from the content-addressed store, hash-verified

42}
43
44func TestMain(main *testing.M) {
45 userNames = make(map[string]int64)
46 passwd = make(map[string]string)
47
48 debug := flag.Bool("V", false, "set log level:debug")
49 flag.Parse()
50 if *debug {
51 log.SetLevel(log.LOG_DEBUG)
52 } else {
53 log.SetLevel(log.LOG_ERROR)
54 }
55
56 exes := []string{
57 "../bin/master",
58 "../bin/notice",
59 "../bin/store",
60 "../bin/gate",
61 }
62
63 cmds := []*exec.Cmd{}
64
65 for _, exe := range exes {
66 cmd := exec.Command(exe)
67 if err := cmd.Start(); err != nil {
68 panic(err.Error())
69 }
70 cmds = append(cmds, cmd)
71 }
72
73 time.Sleep(time.Second * 3)
74
75 client = NewCandyClient("0.0.0.0:9000", &cmdClient{})
76 if err := client.Start(); err != nil {
77 panic(err.Error())
78 }
79
80 for i := 0; i < 10; i++ {
81 name := fmt.Sprintf("testuser_%v_%d@qq.com", time.Now().Unix(), i)
82 pass := fmt.Sprintf("testpass_%v_%d", time.Now().Unix(), i)
83 id, err := client.Register(name, pass)
84 if err != nil {
85 for _, cmd := range cmds {
86 cmd.Process.Kill()
87 }
88 panic("Register error:" + err.Error())
89 }
90 userNames[name] = id
91 passwd[name] = pass
92 }
93
94 ret := main.Run()
95
96 for _, cmd := range cmds {
97 cmd.Process.Kill()
98 }
99
100 os.Exit(ret)
101}

Callers

nothing calls this directly

Calls 5

NewCandyClientFunction · 0.85
SetLevelMethod · 0.80
RegisterMethod · 0.65
StartMethod · 0.45
ErrorMethod · 0.45

Tested by

no test coverage detected