當前位置: 首頁>>代碼示例>>Golang>>正文


Golang assert.New函數代碼示例

本文整理匯總了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")
	}
}
開發者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


注:本文中的github.com/square/metrics/testing_support/assert.New函數示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。