1 Star 0 Fork 0

团团 / consul-template

加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
克隆/下载
main_test.go 1.17 KB
一键复制 编辑 原始数据 按行查看 历史
package main
import (
"fmt"
"io/ioutil"
"log"
"os"
"testing"
dep "github.com/hashicorp/consul-template/dependency"
"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 = "warn"
c.Stdout = ioutil.Discard
c.Stderr = ioutil.Discard
})
log.SetOutput(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() {
// Attempt to recover from a panic and stop the server. If we don't stop
// it, the panic will cause the server to remain running in the
// background. Here we catch the panic and the re-raise it.
if r := recover(); r != nil {
testConsul.Stop()
panic(r)
}
}()
exitCh <- m.Run()
}()
exit := <-exitCh
testConsul.Stop()
os.Exit(exit)
}
马建仓 AI 助手
尝试更多
代码解读
代码找茬
代码优化
Go
1
https://gitee.com/tuantuan5420/consul-template.git
git@gitee.com:tuantuan5420/consul-template.git
tuantuan5420
consul-template
consul-template
master

搜索帮助

344bd9b3 5694891 D2dac590 5694891