...
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15 package main
16
17 import (
18 "log"
19 "os"
20 "os/signal"
21 "strings"
22 "syscall"
23 "testing"
24
25 "go.etcd.io/etcd/server/v3/etcdmain"
26 )
27
28 func SplitTestArgs(args []string) (testArgs, appArgs []string) {
29 for i, arg := range os.Args {
30 switch {
31 case strings.HasPrefix(arg, "-test."):
32 testArgs = append(testArgs, arg)
33 case i == 0:
34 appArgs = append(appArgs, arg)
35 testArgs = append(testArgs, arg)
36 default:
37 appArgs = append(appArgs, arg)
38 }
39 }
40 return
41 }
42
43 func TestEmpty(t *testing.T) {}
44
45
51 func TestMain(m *testing.M) {
52
53 if strings.HasSuffix(os.Args[0], ".test") {
54 log.Printf("skip launching etcd server when invoked via go test")
55 return
56 }
57
58 testArgs, appArgs := SplitTestArgs(os.Args)
59
60 notifier := make(chan os.Signal, 1)
61 signal.Notify(notifier, syscall.SIGINT, syscall.SIGTERM)
62 go etcdmain.Main(appArgs)
63 <-notifier
64
65
66 os.Args = testArgs
67 m.Run()
68 }
69
View as plain text