本文整理汇总了Golang中test_utils.BuildLogger函数的典型用法代码示例。如果您正苦于以下问题:Golang BuildLogger函数的具体用法?Golang BuildLogger怎么用?Golang BuildLogger使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了BuildLogger函数的11个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Golang代码示例。
示例1: TestTestCollect
func TestTestCollect(t *testing.T) {
config := make(map[string]interface{})
testChannel := make(chan metric.Metric)
testLogger := test_utils.BuildLogger()
// conforms to the valueGenerator interface in the collector
mockGen := func() float64 {
return 4.0
}
test := NewTest(testChannel, 123, testLogger)
test.Configure(config)
test.generator = mockGen
go test.Collect()
select {
case m := <-test.Channel():
assert.Equal(t, 4.0, m.Value)
return
case <-time.After(2 * time.Second):
t.Fail()
}
}
示例2: TestDiamondCollect
func TestDiamondCollect(t *testing.T) {
config := make(map[string]interface{})
config["port"] = "0"
testChannel := make(chan metric.Metric)
testLog := test_utils.BuildLogger()
d := newDiamond(testChannel, 123, testLog).(*Diamond)
d.Configure(config)
// start collecting Diamond metrics
go d.Collect()
conn, err := connectToDiamondCollector(d)
require.Nil(t, err, "should connect")
require.NotNil(t, conn, "should connect")
emitTestMetric(conn)
select {
case m := <-d.Channel():
assert.Equal(t, m.Name, "test")
case <-time.After(1 * time.Second):
t.Fail()
}
}
示例3: TestProcStatusCollect
func TestProcStatusCollect(t *testing.T) {
config := make(map[string]interface{})
config["interval"] = 9999
dims := map[string]string{
"module": "(.*)",
}
config["generatedDimensions"] = dims
channel := make(chan metric.Metric)
testLog := test_utils.BuildLogger()
ps := NewProcStatus(channel, 12, testLog)
ps.Configure(config)
go ps.Collect()
select {
case <-ps.Channel():
return
case <-time.After(2 * time.Second):
t.Fail()
}
}
示例4: TestProcStatusMetrics
func TestProcStatusMetrics(t *testing.T) {
testLog := test_utils.BuildLogger()
config := make(map[string]interface{})
dims := map[string]string{
"seven": "(.......)",
"eleven": "(...........)",
}
config["generatedDimensions"] = dims
ps := NewProcStatus(nil, 12, testLog)
ps.Configure(config)
count := 0
for _, m := range ps.procStatusMetrics() {
mDims := m.Dimensions
_, existsSeven := mDims["seven"]
_, existsEleven := mDims["eleven"]
if existsSeven == false || existsEleven == false {
continue
}
count++
}
if count == 0 {
t.Fail()
}
}
示例5: TestCollectorLogsErrors
func TestCollectorLogsErrors(t *testing.T) {
testLogger := test_utils.BuildLogger()
testLogger = testLogger.WithField("collector", "Test")
channel := make(chan metric.Metric)
config := make(map[string]interface{})
testCol := collector.NewTest(channel, 123, testLogger)
testCol.Configure(config)
timeout := time.Duration(5 * time.Second)
h := handler.NewTest(channel, 10, 10, timeout, testLogger)
hook := NewLogErrorHook([]handler.Handler{h})
testLogger.Logger.Hooks.Add(hook)
go testCol.Collect()
testLogger.Error("testing Error log")
select {
case m := <-h.Channel():
assert.Equal(t, "fullerite.collector_errors", m.Name)
assert.Equal(t, 1.0, m.Value)
assert.Equal(t, "Test", m.Dimensions["collector"])
return
case <-time.After(1 * time.Second):
t.Fail()
}
}
示例6: TestProcStatusCollectMetricTypes
func TestProcStatusCollectMetricTypes(t *testing.T) {
config := make(map[string]interface{})
config["interval"] = 9999
dims := map[string]string{
"module": "(.*)",
}
config["generatedDimensions"] = dims
channel := make(chan metric.Metric)
testLog := test_utils.BuildLogger()
ps := NewProcStatus(channel, 12, testLog)
ps.Configure(config)
go ps.Collect()
select {
case <-ps.Channel():
for _, m := range ps.procStatusMetrics() {
if m.Name == "CPUTime" {
assert.Equal(t, m.MetricType, metric.CumulativeCounter, "CPUTime is a CumulativeCounter")
} else {
assert.Equal(t, m.MetricType, metric.Gauge, "All others are a Gauge")
}
}
}
}
示例7: TestFulleriteCollect
func TestFulleriteCollect(t *testing.T) {
config := make(map[string]interface{})
testChannel := make(chan metric.Metric)
testLog := test_utils.BuildLogger()
f := NewFullerite(testChannel, 123, testLog)
f.Configure(config)
go f.Collect()
select {
case <-f.Channel():
return
case <-time.After(2 * time.Second):
t.Fail()
}
}
示例8: TestTestConfigureMetricName
func TestTestConfigureMetricName(t *testing.T) {
config := make(map[string]interface{})
config["metricName"] = "lala"
testChannel := make(chan metric.Metric)
testLogger := test_utils.BuildLogger()
test := NewTest(testChannel, 123, testLogger)
test.Configure(config)
go test.Collect()
select {
case m := <-test.Channel():
// don't test for the value - only metric name
assert.Equal(t, m.Name, "lala")
case <-time.After(1 * time.Second):
t.Fail()
}
}
示例9: TestCpuInfoCollect
func TestCpuInfoCollect(t *testing.T) {
config := make(map[string]interface{})
config["procPath"] = path.Join(test_utils.DirectoryOfCurrentFile(), "/../../fixtures/proc/cpuinfo")
testChannel := make(chan metric.Metric)
testLogger := test_utils.BuildLogger()
cpuInfo := newCPUInfo(testChannel, 100, testLogger)
cpuInfo.Configure(config)
go cpuInfo.Collect()
select {
case m := <-cpuInfo.Channel():
assert.Equal(t, 2.0, m.Value)
assert.Equal(t, "Xeon(R) CPU E5-2630 0 @ 2.30GHz", m.Dimensions["model"])
return
case <-time.After(2 * time.Second):
t.Fail()
}
}
示例10: TestProcStatusExtractDimensions
func TestProcStatusExtractDimensions(t *testing.T) {
testLog := test_utils.BuildLogger()
config := make(map[string]interface{})
dims := map[string]string{
"module": "^python.*?test.*?\\.([^\\.]*)?\\-\\[\\d+\\]$",
"order": "^python.*?test.*?\\.[^\\.]*?\\-\\[(\\d+)\\]$",
}
config["generatedDimensions"] = dims
ps := NewProcStatus(nil, 12, testLog)
ps.Configure(config)
dim := map[string]string{
"module": "bond",
"order": "007",
}
extracted := ps.extractDimensions("python -m test.my.function.bond-[007]")
assert.Equal(t, dim, extracted)
}
示例11: TestProcStatusMatches
func TestProcStatusMatches(t *testing.T) {
assert := assert.New(t)
testLog := test_utils.BuildLogger()
ps := NewProcStatus(nil, 12, testLog)
config := make(map[string]interface{})
commGenerator := func(comm string, err error) func() (string, error) {
return func() (string, error) {
return comm, err
}
}
config["pattern"] = ".*"
config["matchCommandLine"] = true
ps.Configure(config)
match := ps.matches([]string{"proc", "status"}, commGenerator("proc", nil))
assert.True(match)
match = ps.matches([]string{"proc", "status"}, commGenerator("proc", errors.New("")))
assert.True(match)
config["pattern"] = ".*"
config["matchCommandLine"] = false
ps.Configure(config)
match = ps.matches([]string{"proc", "status"}, commGenerator("proc", nil))
assert.True(match)
match = ps.matches([]string{"proc", "status"}, commGenerator("proc", errors.New("")))
assert.False(match)
config["pattern"] = "sta"
config["matchCommandLine"] = true
ps.Configure(config)
match = ps.matches([]string{"proc", "status"}, commGenerator("proc", nil))
assert.True(match)
match = ps.matches([]string{"proc", "butter"}, commGenerator("proc", nil))
assert.False(match)
match = ps.matches([]string{"proc", "butter"}, commGenerator("status", nil))
assert.False(match)
match = ps.matches([]string{"proc", "status"}, commGenerator("proc", errors.New("")))
assert.True(match)
config["pattern"] = "pro"
config["matchCommandLine"] = false
ps.Configure(config)
match = ps.matches([]string{"proc", "status"}, commGenerator("proc", nil))
assert.True(match)
match = ps.matches([]string{"peanut", "status"}, commGenerator("peanut", nil))
assert.False(match)
match = ps.matches([]string{"proc", "status"}, commGenerator("peanut", nil))
assert.False(match)
match = ps.matches([]string{"proc", "status"}, commGenerator("proc", errors.New("")))
assert.False(match)
config["pattern"] = "oc sta"
config["matchCommandLine"] = true
ps.Configure(config)
match = ps.matches([]string{"proc", "status"}, commGenerator("proc", nil))
assert.True(match)
}