本文整理汇总了Golang中github.com/square/metrics/assert.New函数的典型用法代码示例。如果您正苦于以下问题:Golang New函数的具体用法?Golang New怎么用?Golang New使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了New函数的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Golang代码示例。
示例1: TestCommand_Describe
func TestCommand_Describe(t *testing.T) {
fakeApi := mocks.NewFakeApi()
fakeApi.AddPair(api.TaggedMetric{"series_0", api.ParseTagSet("dc=west,env=production,host=a")}, emptyGraphiteName)
fakeApi.AddPair(api.TaggedMetric{"series_0", api.ParseTagSet("dc=west,env=staging,host=b")}, emptyGraphiteName)
fakeApi.AddPair(api.TaggedMetric{"series_0", api.ParseTagSet("dc=east,env=production,host=c")}, emptyGraphiteName)
fakeApi.AddPair(api.TaggedMetric{"series_0", api.ParseTagSet("dc=east,env=staging,host=d")}, emptyGraphiteName)
for _, test := range []struct {
query string
backend api.API
expected map[string][]string
}{
{"describe series_0", fakeApi, map[string][]string{"dc": {"east", "west"}, "env": {"production", "staging"}, "host": {"a", "b", "c", "d"}}},
{"describe`series_0`", fakeApi, map[string][]string{"dc": {"east", "west"}, "env": {"production", "staging"}, "host": {"a", "b", "c", "d"}}},
{"describe series_0 where dc='west'", fakeApi, map[string][]string{"dc": {"west"}, "env": {"production", "staging"}, "host": {"a", "b"}}},
{"describe`series_0`where(dc='west')", fakeApi, map[string][]string{"dc": {"west"}, "env": {"production", "staging"}, "host": {"a", "b"}}},
{"describe series_0 where dc='west' or env = 'production'", fakeApi, map[string][]string{"dc": {"east", "west"}, "env": {"production", "staging"}, "host": {"a", "b", "c"}}},
{"describe series_0 where`dc`='west'or`env`='production'", fakeApi, map[string][]string{"dc": {"east", "west"}, "env": {"production", "staging"}, "host": {"a", "b", "c"}}},
{"describe series_0 where dc='west' or env = 'production' and doesnotexist = ''", fakeApi, map[string][]string{"dc": {"west"}, "env": {"production", "staging"}, "host": {"a", "b"}}},
{"describe series_0 where env = 'production' and doesnotexist = '' or dc = 'west'", fakeApi, map[string][]string{"dc": {"west"}, "env": {"production", "staging"}, "host": {"a", "b"}}},
{"describe series_0 where (dc='west' or env = 'production') and doesnotexist = ''", fakeApi, map[string][]string{}},
{"describe series_0 where(dc='west' or env = 'production')and`doesnotexist` = ''", fakeApi, map[string][]string{}},
} {
a := assert.New(t).Contextf("query=%s", test.query)
command, err := Parse(test.query)
if err != nil {
a.Errorf("Unexpected error while parsing")
continue
}
a.EqString(command.Name(), "describe")
rawResult, _ := command.Execute(ExecutionContext{Backend: nil, API: test.backend, FetchLimit: 1000, Timeout: 0})
a.Eq(rawResult, test.expected)
}
}
开发者ID:postfix,项目名称:metrics,代码行数:35,代码来源:command_test.go
示例2: TestCommand_Describe
func TestCommand_Describe(t *testing.T) {
fakeApi := mocks.NewFakeApi()
fakeApi.AddPair(api.TaggedMetric{"series_0", api.ParseTagSet("dc=west,env=production,host=a")}, emptyGraphiteName)
fakeApi.AddPair(api.TaggedMetric{"series_0", api.ParseTagSet("dc=west,env=staging,host=b")}, emptyGraphiteName)
fakeApi.AddPair(api.TaggedMetric{"series_0", api.ParseTagSet("dc=east,env=production,host=c")}, emptyGraphiteName)
fakeApi.AddPair(api.TaggedMetric{"series_0", api.ParseTagSet("dc=east,env=staging,host=d")}, emptyGraphiteName)
for _, test := range []struct {
query string
backend api.API
length int // expected length of the result.
}{
{"describe series_0", fakeApi, 4},
{"describe`series_0`", fakeApi, 4},
{"describe series_0 where dc='west'", fakeApi, 2},
{"describe`series_0`where(dc='west')", fakeApi, 2},
{"describe series_0 where dc='west' or env = 'production'", fakeApi, 3},
{"describe series_0 where`dc`='west'or`env`='production'", fakeApi, 3},
{"describe series_0 where dc='west' or env = 'production' and doesnotexist = ''", fakeApi, 2},
{"describe series_0 where env = 'production' and doesnotexist = '' or dc = 'west'", fakeApi, 2},
{"describe series_0 where (dc='west' or env = 'production') and doesnotexist = ''", fakeApi, 0},
{"describe series_0 where(dc='west' or env = 'production')and`doesnotexist` = ''", fakeApi, 0},
} {
a := assert.New(t).Contextf("query=%s", test.query)
command, err := Parse(test.query)
if err != nil {
a.Errorf("Unexpected error while parsing")
continue
}
a.EqString(command.Name(), "describe")
rawResult, _ := command.Execute(ExecutionContext{Backend: nil, API: test.backend, FetchLimit: 1000, Timeout: 0})
parsedResult := rawResult.([]string)
a.EqInt(len(parsedResult), test.length)
}
}
开发者ID:alokmenghrajani,项目名称:metrics,代码行数:35,代码来源:command_test.go
示例3: TestCommand_DescribeAll
func TestCommand_DescribeAll(t *testing.T) {
fakeApi := mocks.NewFakeApi()
fakeApi.AddPair(api.TaggedMetric{"series_0", api.ParseTagSet("")}, emptyGraphiteName)
fakeApi.AddPair(api.TaggedMetric{"series_1", api.ParseTagSet("")}, emptyGraphiteName)
fakeApi.AddPair(api.TaggedMetric{"series_2", api.ParseTagSet("")}, emptyGraphiteName)
fakeApi.AddPair(api.TaggedMetric{"series_3", api.ParseTagSet("")}, emptyGraphiteName)
for _, test := range []struct {
query string
backend api.API
expected []api.MetricKey
}{
{"describe all", fakeApi, []api.MetricKey{"series_0", "series_1", "series_2", "series_3"}},
{"describe all match '_0'", fakeApi, []api.MetricKey{"series_0"}},
{"describe all match '_5'", fakeApi, []api.MetricKey{}},
} {
a := assert.New(t).Contextf("query=%s", test.query)
command, err := Parse(test.query)
if err != nil {
a.Errorf("Unexpected error while parsing")
continue
}
a.EqString(command.Name(), "describe all")
rawResult, err := command.Execute(ExecutionContext{Backend: nil, API: test.backend, FetchLimit: 1000, Timeout: 0})
a.CheckError(err)
a.Eq(rawResult, test.expected)
}
}
开发者ID:jmptrader,项目名称:metrics,代码行数:29,代码来源:command_test.go
示例4: Test_TagIndex
func Test_TagIndex(t *testing.T) {
a := assert.New(t)
db := newDatabase(t)
if db == nil {
return
}
defer cleanDatabase(t, db)
if db == nil {
return
}
if rows, err := db.GetMetricKeys("environment", "production"); err != nil {
a.CheckError(err)
} else {
a.EqInt(len(rows), 0)
}
a.CheckError(db.AddToTagIndex("environment", "production", "a.b.c"))
a.CheckError(db.AddToTagIndex("environment", "production", "d.e.f"))
if rows, err := db.GetMetricKeys("environment", "production"); err != nil {
a.CheckError(err)
} else {
a.EqInt(len(rows), 2)
}
a.CheckError(db.RemoveFromTagIndex("environment", "production", "a.b.c"))
if rows, err := db.GetMetricKeys("environment", "production"); err != nil {
a.CheckError(err)
} else {
a.EqInt(len(rows), 1)
a.EqString(string(rows[0]), "d.e.f")
}
}
开发者ID:alokmenghrajani,项目名称:metrics,代码行数:31,代码来源:cassandra_test.go
示例5: TestFunctionName
func TestFunctionName(t *testing.T) {
a := assert.New(t)
a.EqString(functionName(0), "TestFunctionName")
first, second := testFunction1()
a.EqString(first, "testFunction1")
a.EqString(second, "TestFunctionName")
}
开发者ID:jmptrader,项目名称:metrics,代码行数:7,代码来源:parser_test.go
示例6: TestCompile_Good
func TestCompile_Good(t *testing.T) {
a := assert.New(t)
_, err := Compile(RawRule{
Pattern: "prefix.%foo%",
MetricKeyPattern: "test-metric",
})
a.CheckError(err)
}
开发者ID:jmptrader,项目名称:metrics,代码行数:8,代码来源:rules_test.go
示例7: checkConversionErrorCode
func checkConversionErrorCode(t *testing.T, err error, expected ConversionErrorCode) {
casted, ok := err.(ConversionError)
if !ok {
t.Errorf("Invalid Error type")
return
}
a := assert.New(t)
a.EqInt(int(casted.Code()), int(expected))
}
开发者ID:jmptrader,项目名称:metrics,代码行数:9,代码来源:rules_test.go
示例8: TestCompile
func TestCompile(t *testing.T) {
for _, row := range inputs {
a := assert.New(t).Contextf(row)
p := Parser{Buffer: row}
p.Init()
a.CheckError(p.Parse())
p.Execute()
testParserResult(a, p)
}
}
开发者ID:alokmenghrajani,项目名称:metrics,代码行数:10,代码来源:query_test.go
示例9: TestUnescapeLiteral
func TestUnescapeLiteral(t *testing.T) {
a := assert.New(t)
a.EqString(unescapeLiteral("'foo'"), "foo")
a.EqString(unescapeLiteral("foo"), "foo")
a.EqString(unescapeLiteral("nodes.cpu.io"), "nodes.cpu.io")
a.EqString(unescapeLiteral(`"hello"`), `hello`)
a.EqString(unescapeLiteral(`"\"hello\""`), `"hello"`)
a.EqString(unescapeLiteral(`'\"hello\"'`), `"hello"`)
a.EqString(unescapeLiteral("\"\\`\""), "`")
}
开发者ID:jmptrader,项目名称:metrics,代码行数:10,代码来源:parser_test.go
示例10: Test_Registry_Default
func Test_Registry_Default(t *testing.T) {
a := assert.New(t)
sr := StandardRegistry{mapping: make(map[string]function.MetricFunction)}
a.Eq(sr.All(), []string{})
if err := sr.Register(function.MetricFunction{Name: "foo", Compute: dummyCompute}); err != nil {
a.CheckError(err)
}
if err := sr.Register(function.MetricFunction{Name: "bar", Compute: dummyCompute}); err != nil {
a.CheckError(err)
}
a.Eq(sr.All(), []string{"bar", "foo"})
}
开发者ID:jmptrader,项目名称:metrics,代码行数:12,代码来源:registry_test.go
示例11: TestRandom
func TestRandom(t *testing.T) {
a := assert.New(t)
expected := []string{"Apple", "apple", "file2", "file22", "file90", "file99", "file100", "Zoo", "zoo"}
test := []string{"Apple", "apple", "file2", "file22", "file90", "file99", "file100", "Zoo", "zoo"}
Sort(test)
a.Eq(test, expected)
for i := 0; i < 1000; i++ {
testShuffle(test)
a := a.Contextf("input: %+v", test)
Sort(test)
a.Eq(test, expected)
}
}
开发者ID:jmptrader,项目名称:metrics,代码行数:13,代码来源:natural_test.go
示例12: TestLoadYAML_Invalid
func TestLoadYAML_Invalid(t *testing.T) {
a := assert.New(t)
rawYAML := `
rules
-
pattern: foo.bar.baz.%tag%
metric_key: abc
regex: {}
`
ruleSet, err := LoadYAML([]byte(rawYAML))
checkRuleErrorCode(a, err, InvalidYaml)
a.EqInt(len(ruleSet.rules), 0)
}
开发者ID:jmptrader,项目名称:metrics,代码行数:13,代码来源:rules_test.go
示例13: TestNaturalSort
func TestNaturalSort(t *testing.T) {
a := assert.New(t)
expected := []string{"Apple", "apple", "file2", "file22", "file90", "file99", "file100", "Zoo", "zoo"}
tests := [][]string{
{"Apple", "apple", "file2", "file90", "file99", "file100", "Zoo", "zoo", "file22"},
{"Zoo", "Apple", "apple", "file100", "file2", "file90", "file99", "zoo", "file22"},
{"file2", "file90", "apple", "Zoo", "file100", "file22", "file99", "zoo", "Apple"},
}
Sort([]string{}) // check that no panic occurs
for _, test := range tests {
Sort(test)
a.Eq(test, expected)
}
}
开发者ID:jmptrader,项目名称:metrics,代码行数:14,代码来源:natural_test.go
示例14: TestLoadYAML
func TestLoadYAML(t *testing.T) {
a := assert.New(t)
rawYAML := `
rules:
-
pattern: foo.bar.baz.%tag%
metric_key: abc
regex: {}
`
ruleSet, err := LoadYAML([]byte(rawYAML))
a.CheckError(err)
a.EqInt(len(ruleSet.rules), 1)
a.EqString(string(ruleSet.rules[0].raw.MetricKeyPattern), "abc")
a.Eq(ruleSet.rules[0].graphitePatternTags, []string{"tag"})
}
开发者ID:jmptrader,项目名称:metrics,代码行数:15,代码来源:rules_test.go
示例15: Test_ParallelMultiBackend_Success
func Test_ParallelMultiBackend_Success(t *testing.T) {
a := assert.New(t)
suite := newSuite()
defer suite.cleanup()
go func() {
_, err := suite.multiBackend.FetchMultipleSeries(api.FetchMultipleRequest{
Metrics: []api.TaggedMetric{api.TaggedMetric{"a", api.NewTagSet()}},
Cancellable: suite.cancellable,
})
a.CheckError(err)
suite.waitGroup.Done()
}()
suite.backend.tickets <- struct{}{}
suite.waitGroup.Wait()
}
开发者ID:jmptrader,项目名称:metrics,代码行数:15,代码来源:multibackend_test.go
示例16: TestToGraphiteName
func TestToGraphiteName(t *testing.T) {
a := assert.New(t)
rule, err := Compile(RawRule{
Pattern: "prefix.%foo%",
MetricKeyPattern: "test-metric",
})
a.CheckError(err)
tm := api.TaggedMetric{
MetricKey: "test-metric",
TagSet: api.ParseTagSet("foo=fooValue"),
}
reversed, err := rule.ToGraphiteName(tm)
a.CheckError(err)
a.EqString(string(reversed), "prefix.fooValue")
}
开发者ID:jmptrader,项目名称:metrics,代码行数:15,代码来源:rules_test.go
示例17: TestCompile_Error
func TestCompile_Error(t *testing.T) {
for _, test := range []struct {
rawRule RawRule
expectedCode RuleErrorCode
}{
{RawRule{Pattern: "prefix.%foo%", MetricKeyPattern: ""}, InvalidMetricKey},
{RawRule{Pattern: "prefix.%foo%abc%", MetricKeyPattern: "test-metric"}, InvalidPattern},
{RawRule{Pattern: "", MetricKeyPattern: "test-metric"}, InvalidPattern},
{RawRule{Pattern: "prefix.%foo%.%foo%", MetricKeyPattern: "test-metric"}, InvalidPattern},
{RawRule{Pattern: "prefix.%foo%.abc.%%", MetricKeyPattern: "test-metric"}, InvalidPattern},
{RawRule{Pattern: "prefix.%foo%", MetricKeyPattern: "test-metric", Regex: map[string]string{"foo": "(bar)"}}, InvalidCustomRegex},
} {
_, err := Compile(test.rawRule)
a := assert.New(t).Contextf("%s", test.rawRule.Pattern)
checkRuleErrorCode(a, err, test.expectedCode)
}
}
开发者ID:jmptrader,项目名称:metrics,代码行数:17,代码来源:rules_test.go
示例18: TestTimeseries_Downsample
func TestTimeseries_Downsample(t *testing.T) {
a := assert.New(t)
for _, suite := range []struct {
input []float64
inputRange Timerange
newRange Timerange
sampler func([]float64) float64
expected []float64
}{
{[]float64{1, 2, 3, 4, 5}, Timerange{0, 4, 1}, Timerange{0, 4, 2}, max, []float64{2, 4, 5}},
} {
tagset := ParseTagSet("key=value")
ts := Timeseries{suite.input, tagset}
sampled, err := ts.downsample(suite.inputRange, suite.newRange, suite.sampler)
a.CheckError(err)
a.Eq(sampled.Values, suite.expected)
}
}
开发者ID:jmptrader,项目名称:metrics,代码行数:18,代码来源:timeseries_test.go
示例19: Test_ScalarExpression
func Test_ScalarExpression(t *testing.T) {
timerangeA, err := api.NewTimerange(0, 10, 2)
if err != nil {
t.Fatalf("invalid timerange used for testcase")
return
}
for _, test := range []struct {
expr scalarExpression
timerange api.Timerange
expectedSeries []api.Timeseries
}{
{
scalarExpression{5},
timerangeA,
[]api.Timeseries{
api.Timeseries{
[]float64{5.0, 5.0, 5.0, 5.0, 5.0, 5.0},
api.NewTagSet(),
},
},
},
} {
a := assert.New(t).Contextf("%+v", test)
result, err := evaluateToSeriesList(test.expr, function.EvaluationContext{
MultiBackend: backend.NewSequentialMultiBackend(FakeBackend{}),
Timerange: test.timerange,
SampleMethod: api.SampleMean,
FetchLimit: function.NewFetchCounter(1000),
Registry: registry.Default(),
})
if err != nil {
t.Fatalf("failed to convert number into serieslist")
}
a.EqInt(len(result.Series), len(test.expectedSeries))
for i := 0; i < len(result.Series); i += 1 {
a.Eq(result.Series[i].Values, test.expectedSeries[i].Values)
}
}
}
开发者ID:treejames,项目名称:metrics,代码行数:42,代码来源:expression_test.go
示例20: Test_GetAllMetrics
func Test_GetAllMetrics(t *testing.T) {
a := assert.New(t)
db := newDatabase(t)
if db == nil {
return
}
defer cleanDatabase(t, db)
a.CheckError(db.AddMetricName("metric.a", api.ParseTagSet("foo=a")))
a.CheckError(db.AddMetricName("metric.a", api.ParseTagSet("foo=b")))
keys, err := db.GetAllMetrics()
a.CheckError(err)
sort.Sort(api.MetricKeys(keys))
a.Eq(keys, []api.MetricKey{"metric.a"})
a.CheckError(db.AddMetricName("metric.b", api.ParseTagSet("foo=c")))
a.CheckError(db.AddMetricName("metric.b", api.ParseTagSet("foo=c")))
keys, err = db.GetAllMetrics()
a.CheckError(err)
sort.Sort(api.MetricKeys(keys))
a.Eq(keys, []api.MetricKey{"metric.a", "metric.b"})
}
开发者ID:alokmenghrajani,项目名称:metrics,代码行数:20,代码来源:cassandra_test.go
注:本文中的github.com/square/metrics/assert.New函数示例由纯净天空整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论