-
Notifications
You must be signed in to change notification settings - Fork 1
/
main_test.go
53 lines (44 loc) · 960 Bytes
/
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
package main
import (
"fmt"
"io/ioutil"
"log"
"os"
"testing"
dep "github.com/Assada/consul-generator/client"
"github.com/hashicorp/consul/testutil"
)
var testConsul *testutil.TestServer
var testClients *dep.ClientSet
func TestMain(m *testing.M) {
consul, err := testutil.NewTestServerConfig(func(c *testutil.TestServerConfig) {
c.LogLevel = "info"
c.Stdout = ioutil.Discard
c.Stderr = ioutil.Discard
})
if err != nil {
log.Fatal(fmt.Errorf("failed to start consul server: %v", err))
}
testConsul = consul
clients := dep.NewClientSet()
if err := clients.CreateConsulClient(&dep.CreateConsulClientInput{
Address: testConsul.HTTPAddr,
}); err != nil {
testConsul.Stop()
log.Fatal(err)
}
testClients = clients
exitCh := make(chan int, 1)
func() {
defer func() {
if r := recover(); r != nil {
testConsul.Stop()
panic(r)
}
}()
exitCh <- m.Run()
}()
exit := <-exitCh
testConsul.Stop()
os.Exit(exit)
}