• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    迪恩网络公众号

Golang assert.New函数代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

本文整理汇总了Golang中github.com/square/metrics/testing_support/assert.New函数的典型用法代码示例。如果您正苦于以下问题:Golang New函数的具体用法?Golang New怎么用?Golang New使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。



在下文中一共展示了New函数的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的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")
	}
}
开发者ID:deveshmittal,项目名称:metrics,代码行数:29,代码来源:cassandra_db_test.go


示例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)
	}
}
开发者ID:ratneshdeepak,项目名称:metrics,代码行数:26,代码来源:types_test.go


示例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")
}
开发者ID:ratneshdeepak,项目名称:metrics,代码行数:7,代码来源:types_test.go


示例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)
	}
}
开发者ID:ratneshdeepak,项目名称:metrics,代码行数:32,代码来源:types_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:ratneshdeepak,项目名称:metrics,代码行数:7,代码来源:parser_test.go


示例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)
			}
		}
	}
}
开发者ID:deveshmittal,项目名称:metrics,代码行数:59,代码来源:cassandra_db_test.go


示例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)
}
开发者ID:deveshmittal,项目名称:metrics,代码行数:8,代码来源:rules_test.go


示例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")
}
开发者ID:ratneshdeepak,项目名称:metrics,代码行数:8,代码来源:types_test.go


示例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))
}
开发者ID:deveshmittal,项目名称:metrics,代码行数:9,代码来源:rules_test.go


示例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)
	}
}
开发者ID:ratneshdeepak,项目名称:metrics,代码行数:10,代码来源:query_test.go


示例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("\"\\`\""), "`")
}
开发者ID:ratneshdeepak,项目名称:metrics,代码行数:10,代码来源:parser_test.go


示例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")
}
开发者ID:ratneshdeepak,项目名称:metrics,代码行数:11,代码来源:types_test.go


示例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"})
}
开发者ID:ratneshdeepak,项目名称:metrics,代码行数:12,代码来源:registry_test.go


示例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)
}
开发者ID:deveshmittal,项目名称:metrics,代码行数:13,代码来源:rules_test.go


示例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)
	}
}
开发者ID:ratneshdeepak,项目名称:metrics,代码行数:13,代码来源:natural_test.go


示例16: TestTimerange_MarshalJSON

func TestTimerange_MarshalJSON(t *testing.T) {
	for _, suite := range []struct {
		input    Timerange
		expected string
	}{
		{Timerange{0, 100, 10}, `{"start":0,"end":100,"resolution":10}`},
		{Timerange{100, 10000, 50}, `{"start":100,"end":10000,"resolution":50}`},
	} {
		a := assert.New(t).Contextf("expected=%s", suite.expected)
		encoded, err := json.Marshal(suite.input)
		a.CheckError(err)
		a.Eq(string(encoded), suite.expected)
	}
}
开发者ID:ratneshdeepak,项目名称:metrics,代码行数:14,代码来源:types_test.go


示例17: Test_FetchCounter

func Test_FetchCounter(t *testing.T) {
	c := NewFetchCounter(10)
	a := assert.New(t)
	a.EqInt(c.Current(), 0)
	a.EqInt(c.Limit(), 10)
	a.EqBool(c.Consume(5), true)
	a.EqInt(c.Current(), 5)
	a.EqBool(c.Consume(4), true)
	a.EqInt(c.Current(), 9)
	a.EqBool(c.Consume(1), true)
	a.EqInt(c.Current(), 10)
	a.EqBool(c.Consume(1), false)
	a.EqInt(c.Current(), 11)
}
开发者ID:ratneshdeepak,项目名称:metrics,代码行数:14,代码来源:expression_test.go


示例18: 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:ratneshdeepak,项目名称:metrics,代码行数:14,代码来源:natural_test.go


示例19: Test_GetAllMetrics_API

func Test_GetAllMetrics_API(t *testing.T) {
	a := assert.New(t)
	cassandra, context := newCassandraAPI(t)
	defer cleanAPI(t, cassandra)
	a.CheckError(cassandra.AddMetric(api.TaggedMetric{
		"metric.a",
		api.ParseTagSet("foo=a"),
	}, context))
	a.CheckError(cassandra.AddMetric(api.TaggedMetric{
		"metric.a",
		api.ParseTagSet("foo=b"),
	}, context))
	a.CheckError(cassandra.AddMetrics([]api.TaggedMetric{
		{
			"metric.c",
			api.TagSet{
				"bar": "cat",
			},
		},
		{
			"metric.d",
			api.TagSet{
				"bar": "dog",
			},
		},
		{
			"metric.e",
			api.TagSet{
				"bar": "cat",
			},
		},
	}, context))
	keys, err := cassandra.GetAllMetrics(context)
	a.CheckError(err)
	sort.Sort(api.MetricKeys(keys))
	a.Eq(keys, []api.MetricKey{"metric.a", "metric.c", "metric.d", "metric.e"})
	a.CheckError(cassandra.AddMetric(api.TaggedMetric{
		"metric.b",
		api.ParseTagSet("foo=c"),
	}, context))
	a.CheckError(cassandra.AddMetric(api.TaggedMetric{
		"metric.b",
		api.ParseTagSet("foo=c"),
	}, context))
	keys, err = cassandra.GetAllMetrics(context)
	a.CheckError(err)
	sort.Sort(api.MetricKeys(keys))
	a.Eq(keys, []api.MetricKey{"metric.a", "metric.b", "metric.c", "metric.d", "metric.e"})
}
开发者ID:deveshmittal,项目名称:metrics,代码行数:49,代码来源:cassandra_api_test.go


示例20: 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:deveshmittal,项目名称:metrics,代码行数:15,代码来源:rules_test.go



注:本文中的github.com/square/metrics/testing_support/assert.New函数示例由纯净天空整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
Golang errors.UnsupportedError函数代码示例发布时间:2022-05-28
下一篇:
Golang assert.New函数代码示例发布时间:2022-05-28
热门推荐
热门话题
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap