本文整理汇总了Golang中github.com/square/metrics/testing_support/assert.New函数的典型用法代码示例。如果您正苦于以下问题:Golang New函数的具体用法?Golang New怎么用?Golang New使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了New函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Golang代码示例。
示例1: Test_TagIndex_DB
func Test_TagIndex_DB(t *testing.T) {
a := assert.New(t)
db := newDatabase(t)
if db == nil {
return
}
defer cleanDatabase(t, db)
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")
}
}
示例2: TestTimeseries_MarshalJSON
func TestTimeseries_MarshalJSON(t *testing.T) {
for _, suite := range []struct {
input Timeseries
expected string
}{
{
Timeseries{
TagSet: ParseTagSet("foo=bar"),
Values: []float64{0, 1, -1, math.NaN()},
},
`{"tagset":{"foo":"bar"},"values":[0,1,-1,null]}`,
},
{
Timeseries{
TagSet: NewTagSet(),
Values: []float64{0, 1, -1, math.NaN()},
},
`{"tagset":{},"values":[0,1,-1,null]}`,
},
} {
a := assert.New(t).Contextf("expected=%s", suite.expected)
encoded, err := json.Marshal(suite.input)
a.CheckError(err)
a.Eq(string(encoded), suite.expected)
}
}
示例3: TestTagSet_ParseTagSet
func TestTagSet_ParseTagSet(t *testing.T) {
a := assert.New(t)
a.EqString(ParseTagSet("foo=bar").Serialize(), "foo=bar")
a.EqString(ParseTagSet("a=1,b=2").Serialize(), "a=1,b=2")
a.EqString(ParseTagSet("a\\,b=1").Serialize(), "a\\,b=1")
a.EqString(ParseTagSet("a\\=b=1").Serialize(), "a\\=b=1")
}
示例4: TestTimerange
func TestTimerange(t *testing.T) {
for _, suite := range []struct {
Start int64
End int64
Resolution int64
ExpectedValid bool
ExpectedSlots int
}{
// valid cases
{0, 0, 1, true, 1},
{0, 1, 1, true, 2},
{0, 100, 1, true, 101},
{0, 100, 5, true, 21},
// invalid cases
{100, 0, 1, false, 0},
{0, 100, 6, false, 0},
{0, 100, 200, false, 0},
} {
a := assert.New(t).Contextf("input=%d:%d:%d",
suite.Start,
suite.End,
suite.Resolution,
)
timerange, err := NewTimerange(suite.Start, suite.End, suite.Resolution)
a.EqBool(err == nil, suite.ExpectedValid)
if !suite.ExpectedValid {
continue
}
a.EqInt(timerange.Slots(), suite.ExpectedSlots)
}
}
示例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")
}
示例6: Test_MetricName_GetTagSet_DB
func Test_MetricName_GetTagSet_DB(t *testing.T) {
a := assert.New(t)
db := newDatabase(t)
if db == nil {
return
}
defer cleanDatabase(t, db)
if _, err := db.GetTagSet("sample"); err == nil {
t.Errorf("Cassandra should error on fetching nonexistent metric")
}
metricNamesTests := []struct {
addTest bool
metricName string
tagString string
expectedTags map[string][]string // { metricName: [ tags ] }
}{
{true, "sample", "foo=bar1", map[string][]string{
"sample": []string{"foo=bar1"},
}},
{true, "sample", "foo=bar2", map[string][]string{
"sample": []string{"foo=bar1", "foo=bar2"},
}},
{true, "sample2", "foo=bar2", map[string][]string{
"sample": []string{"foo=bar1", "foo=bar2"},
"sample2": []string{"foo=bar2"},
}},
{false, "sample2", "foo=bar2", map[string][]string{
"sample": []string{"foo=bar1", "foo=bar2"},
}},
{false, "sample", "foo=bar1", map[string][]string{
"sample": []string{"foo=bar2"},
}},
}
for _, c := range metricNamesTests {
if c.addTest {
a.CheckError(db.AddMetricName(api.MetricKey(c.metricName), api.ParseTagSet(c.tagString)))
} else {
a.CheckError(db.RemoveMetricName(api.MetricKey(c.metricName), api.ParseTagSet(c.tagString)))
}
for k, v := range c.expectedTags {
if tags, err := db.GetTagSet(api.MetricKey(k)); err != nil {
t.Errorf("Error fetching tags")
} else {
stringTags := make([]string, len(tags))
for i, tag := range tags {
stringTags[i] = tag.Serialize()
}
a.EqInt(len(stringTags), len(v))
sort.Sort(sort.StringSlice(stringTags))
sort.Sort(sort.StringSlice(v))
a.Eq(stringTags, v)
}
}
}
}
示例7: TestCompile_Good
func TestCompile_Good(t *testing.T) {
a := assert.New(t)
_, err := Compile(RawRule{
Pattern: "prefix.%foo%",
MetricKeyPattern: "test-metric",
})
a.CheckError(err)
}
示例8: TestTagSet_Serialize
func TestTagSet_Serialize(t *testing.T) {
a := assert.New(t)
a.EqString(NewTagSet().Serialize(), "")
ts := NewTagSet()
ts["dc"] = "sjc1b"
ts["env"] = "production"
a.EqString(ts.Serialize(), "dc=sjc1b,env=production")
}
示例9: 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))
}
示例10: 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)
}
}
示例11: 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("\"\\`\""), "`")
}
示例12: TestTagSet_Serialize_Escape
func TestTagSet_Serialize_Escape(t *testing.T) {
a := assert.New(t)
ts := NewTagSet()
ts["weird=key=1"] = "weird,value"
ts["weird=key=2"] = "weird\\value"
a.EqString(ts.Serialize(), "weird\\=key\\=1=weird\\,value,weird\\=key\\=2=weird\\\\value")
parsed := ParseTagSet(ts.Serialize())
a.EqInt(len(parsed), 2)
a.EqString(parsed["weird=key=1"], "weird,value")
a.EqString(parsed["weird=key=2"], "weird\\value")
}
示例13: 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"})
}
示例14: 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)
}
示例15: 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)
}
}