当前位置: 首页>>代码示例>>Golang>>正文


Golang TB.Errorf方法代码示例

本文整理汇总了Golang中testing.TB.Errorf方法的典型用法代码示例。如果您正苦于以下问题:Golang TB.Errorf方法的具体用法?Golang TB.Errorf怎么用?Golang TB.Errorf使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在testing.TB的用法示例。


在下文中一共展示了TB.Errorf方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Golang代码示例。

示例1: ShouldCASError

func ShouldCASError(t testing.TB, s store.Store, key string, from, to store.CASV, wantErr error) {
	err := s.CAS(key, from, to, nil)
	if err != wantErr {
		t.Errorf("CAS(%#v, %v, %v) returned error %v, but wanted %v",
			key, from, to, err, wantErr)
	}
}
开发者ID:encryptio,项目名称:slime,代码行数:7,代码来源:operations.go

示例2: ShouldGetError

func ShouldGetError(t testing.TB, s store.Store, key string, wantErr error) {
	got, _, err := s.Get(key, store.GetOptions{})
	if err != wantErr {
		t.Errorf("Get(%#v) = (%#v, %v), but wanted err = %v",
			key, got, err, wantErr)
	}
}
开发者ID:encryptio,项目名称:slime,代码行数:7,代码来源:operations.go

示例3: ShouldStatMiss

func ShouldStatMiss(t testing.TB, s store.Store, key string) {
	st, err := s.Stat(key, nil)
	if err != store.ErrNotFound {
		t.Errorf("Stat(%#v) returned (%v, %v), but wanted %v",
			key, st, err, store.ErrNotFound)
	}
}
开发者ID:encryptio,项目名称:slime,代码行数:7,代码来源:operations.go

示例4: ShouldGetPartialMiss

func ShouldGetPartialMiss(t testing.TB, s store.RangeReadStore, key string, start, length int64) {
	_, _, err := s.GetPartial(key, start, length, store.GetOptions{})
	if err != store.ErrNotFound {
		t.Errorf("GetPartial(%#v, %v, %v) returned err %v, but wanted %v",
			key, start, length, err, store.ErrNotFound)
	}
}
开发者ID:encryptio,项目名称:slime,代码行数:7,代码来源:operations.go

示例5: validateIndex

func validateIndex(t testing.TB, repo restic.Repository, idx *Index) {
	for id := range repo.List(restic.DataFile, nil) {
		if _, ok := idx.Packs[id]; !ok {
			t.Errorf("pack %v missing from index", id.Str())
		}
	}
}
开发者ID:ckemper67,项目名称:restic,代码行数:7,代码来源:index_test.go

示例6: testMetric

func testMetric(t testing.TB) {
	var scenarios = []struct {
		input       Metric
		fingerprint Fingerprint
	}{
		{
			input:       Metric{},
			fingerprint: 2676020557754725067,
		},
		{
			input: Metric{
				"first_name":   "electro",
				"occupation":   "robot",
				"manufacturer": "westinghouse",
			},
			fingerprint: 13260944541294022935,
		},
		{
			input: Metric{
				"x": "y",
			},
			fingerprint: 1470933794305433534,
		},
	}

	for i, scenario := range scenarios {
		if scenario.fingerprint != scenario.input.Fingerprint() {
			t.Errorf("%d. expected %d, got %d", i, scenario.fingerprint, scenario.input.Fingerprint())
		}
	}
}
开发者ID:jameswei,项目名称:xcodis,代码行数:31,代码来源:metric_test.go

示例7: loadTestPointers

func loadTestPointers(tb testing.TB) []geo.Pointer {
	f, err := os.Open("../testdata/points.csv.gz")
	if err != nil {
		tb.Fatalf("unable to open test file %v", err)
	}
	defer f.Close()

	gzReader, err := gzip.NewReader(f)
	if err != nil {
		tb.Fatalf("unable to create gz reader: %v", err)
	}
	defer gzReader.Close()

	// read in events
	var pointers []geo.Pointer
	scanner := bufio.NewScanner(gzReader)
	for scanner.Scan() {
		parts := strings.Split(scanner.Text(), ",")
		lat, _ := strconv.ParseFloat(parts[0], 64)
		lng, _ := strconv.ParseFloat(parts[1], 64)

		if lat == 0 || lng == 0 {
			tb.Errorf("latlng not parsed correctly, %s %s", parts[0], parts[1])
		}

		pointers = append(pointers, &event{
			Location: geo.NewPoint(lng, lat),
		})
	}

	return pointers
}
开发者ID:thomaspeugeot,项目名称:go.geo,代码行数:32,代码来源:prefilter_test.go

示例8: testIPv6

func testIPv6(t testing.TB, g *GeoIP, name string) {
	addrs := []string{
		"::1:ffff:ffff",
		"::2:0:0",
		"::2:0:40",
		"::2:0:50",
		"::2:0:58",
	}
	for _, v := range addrs {
		ip := net.ParseIP(v)
		res, err := g.LookupIPValue(ip)
		expected := expectedValue(ip, name)
		if expected == nil {
			if err == nil {
				t.Errorf("expecting an error for IP %s in DB %s", ip, name)
			}
		} else {
			if err != nil {
				t.Error(err)
			} else {
				if !deepEqual(t, res, expected) {
					t.Errorf("expecting %v for IP %s in DB %s, got %v instead", expected, ip, name, res)
				}
			}
		}
	}
}
开发者ID:kelixin,项目名称:geoipmap,代码行数:27,代码来源:geoip_test.go

示例9: AfterTest

// AfterTest snapshots the currently-running goroutines and returns a
// function to be run at the end of tests to see whether any
// goroutines leaked.
func AfterTest(t testing.TB) func() {
	orig := map[string]bool{}
	for _, g := range interestingGoroutines() {
		orig[g] = true
	}
	return func() {
		// Loop, waiting for goroutines to shut down.
		// Wait up to 5 seconds, but finish as quickly as possible.
		deadline := timeutil.Now().Add(5 * time.Second)
		for {
			var leaked []string
			for _, g := range interestingGoroutines() {
				if !orig[g] {
					leaked = append(leaked, g)
				}
			}
			if len(leaked) == 0 {
				return
			}
			if timeutil.Now().Before(deadline) {
				time.Sleep(50 * time.Millisecond)
				continue
			}
			for _, g := range leaked {
				t.Errorf("Leaked goroutine: %v", g)
			}
			return
		}
	}
}
开发者ID:petermattis,项目名称:cockroach,代码行数:33,代码来源:leaktest.go

示例10: closeDB

func closeDB(t testing.TB, db *DB) {
	if e := recover(); e != nil {
		fmt.Printf("Panic: %v\n", e)
		panic(e)
	}
	defer setHookpostCloseConn(nil)
	setHookpostCloseConn(func(_ *fakeConn, err error) {
		if err != nil {
			t.Errorf("Error closing fakeConn: %v", err)
		}
	})
	for node, i := db.freeConn.Front(), 0; node != nil; node, i = node.Next(), i+1 {
		dc := node.Value.(*driverConn)
		if n := len(dc.openStmt); n > 0 {
			// Just a sanity check. This is legal in
			// general, but if we make the tests clean up
			// their statements first, then we can safely
			// verify this is always zero here, and any
			// other value is a leak.
			t.Errorf("while closing db, freeConn %d/%d had %d open stmts; want 0", i, db.freeConn.Len(), n)
		}
	}
	err := db.Close()
	if err != nil {
		t.Fatalf("error closing DB: %v", err)
	}
	db.mu.Lock()
	count := db.numOpen
	db.mu.Unlock()
	if count != 0 {
		t.Fatalf("%d connections still open after closing DB", db.numOpen)
	}
}
开发者ID:maqayum,项目名称:gcc-libitm,代码行数:33,代码来源:sql_test.go

示例11: verifyStorage

func verifyStorage(t testing.TB, s Storage, samples clientmodel.Samples, maxAge time.Duration) bool {
	result := true
	for _, i := range rand.Perm(len(samples)) {
		sample := samples[i]
		if sample.Timestamp.Before(clientmodel.TimestampFromTime(time.Now().Add(-maxAge))) {
			continue
			// TODO: Once we have a guaranteed cutoff at the
			// retention period, we can verify here that no results
			// are returned.
		}
		fp := sample.Metric.Fingerprint()
		p := s.NewPreloader()
		p.PreloadRange(fp, sample.Timestamp, sample.Timestamp, time.Hour)
		found := s.NewIterator(fp).GetValueAtTime(sample.Timestamp)
		if len(found) != 1 {
			t.Errorf("Sample %#v: Expected exactly one value, found %d.", sample, len(found))
			result = false
			p.Close()
			continue
		}
		want := float64(sample.Value)
		got := float64(found[0].Value)
		if want != got || sample.Timestamp != found[0].Timestamp {
			t.Errorf(
				"Value (or timestamp) mismatch, want %f (at time %v), got %f (at time %v).",
				want, sample.Timestamp, got, found[0].Timestamp,
			)
			result = false
		}
		p.Close()
	}
	return result
}
开发者ID:gitlabuser,项目名称:prometheus,代码行数:33,代码来源:storage_test.go

示例12: loadIDSet

func loadIDSet(t testing.TB, filename string) restic.BlobSet {
	f, err := os.Open(filename)
	if err != nil {
		t.Logf("unable to open golden file %v: %v", filename, err)
		return restic.NewBlobSet()
	}

	sc := bufio.NewScanner(f)

	blobs := restic.NewBlobSet()
	for sc.Scan() {
		var h restic.BlobHandle
		err := json.Unmarshal([]byte(sc.Text()), &h)
		if err != nil {
			t.Errorf("file %v contained invalid blob: %#v", filename, err)
			continue
		}

		blobs.Insert(h)
	}

	if err = f.Close(); err != nil {
		t.Errorf("closing file %v failed with error %v", filename, err)
	}

	return blobs
}
开发者ID:ckemper67,项目名称:restic,代码行数:27,代码来源:find_test.go

示例13: NoError

func NoError(t testing.TB, err error) bool {
	if err != nil {
		t.Errorf("%s%v", assertPos(0), err)
		return false
	}
	return true
}
开发者ID:thomasf,项目名称:alkasir,代码行数:7,代码来源:assert.go

示例14: NotEqual

func NotEqual(t testing.TB, name string, act, exp interface{}) bool {
	if act == exp {
		t.Errorf("%s%s is not expected to be %q", assertPos(0), name, fmt.Sprint(exp))
		return false
	}
	return true
}
开发者ID:thomasf,项目名称:alkasir,代码行数:7,代码来源:assert.go

示例15: AfterTest

// AfterTest snapshots the currently-running goroutines and returns a
// function to be run at the end of tests to see whether any
// goroutines leaked.
func AfterTest(t testing.TB) func() {
	orig := interestingGoroutines()
	return func() {
		if t.Failed() {
			return
		}
		if r := recover(); r != nil {
			panic(r)
		}
		// Loop, waiting for goroutines to shut down.
		// Wait up to 5 seconds, but finish as quickly as possible.
		deadline := timeutil.Now().Add(5 * time.Second)
		for {
			var leaked []string
			for id, stack := range interestingGoroutines() {
				if _, ok := orig[id]; !ok {
					leaked = append(leaked, stack)
				}
			}
			if len(leaked) == 0 {
				return
			}
			if timeutil.Now().Before(deadline) {
				time.Sleep(50 * time.Millisecond)
				continue
			}
			sort.Strings(leaked)
			for _, g := range leaked {
				t.Errorf("Leaked goroutine: %v", g)
			}
			return
		}
	}
}
开发者ID:BramGruneir,项目名称:cockroach,代码行数:37,代码来源:leaktest.go


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