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


Golang TB.Error方法代码示例

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


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

示例1: 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

示例2: netPipe

// netPipe provides a pair of io.ReadWriteClosers connected to each other.
// The functions is identical to os.Pipe with the exception that netPipe
// provides the Read/Close guarentees that os.File derrived pipes do not.
func netPipe(t testing.TB) (io.ReadWriteCloser, io.ReadWriteCloser) {
	type result struct {
		net.Conn
		error
	}

	l, err := net.Listen("tcp", "127.0.0.1:0")
	if err != nil {
		t.Fatal(err)
	}

	ch := make(chan result, 1)
	go func() {
		conn, err := l.Accept()
		ch <- result{conn, err}
		err = l.Close()
		if err != nil {
			t.Error(err)
		}
	}()
	c1, err := net.Dial("tcp", l.Addr().String())
	if err != nil {
		l.Close() // might cause another in the listening goroutine, but too bad
		t.Fatal(err)
	}
	r := <-ch
	if r.error != nil {
		t.Fatal(err)
	}
	return c1, r.Conn
}
开发者ID:acquia,项目名称:fifo2kinesis,代码行数:34,代码来源:client_integration_test.go

示例3: Error

func Error(t testing.TB, err error) bool {
	if err == nil {
		t.Error("Expecting error but nil got!")
		return false
	}
	return true
}
开发者ID:thomasf,项目名称:alkasir,代码行数:7,代码来源:assert.go

示例4: assertDnsMessage

func assertDnsMessage(t testing.TB, q DnsTestMsg) {
	dns, err := decodeDnsData(TransportUdp, q.rawData)
	if err != nil {
		t.Error("failed to decode dns data")
	}

	mapStr := common.MapStr{}
	addDnsToMapStr(mapStr, dns, true, true)
	if q.question != nil {
		for k, v := range q.question {
			assert.NotNil(t, mapStr["question"].(common.MapStr)[k])
			assert.Equal(t, v, mapStr["question"].(common.MapStr)[k])
		}
	}
	if len(q.answers) > 0 {
		assertRRs(t, q.answers, mapStr["answer"].([]common.MapStr))
	}
	if len(q.authorities) > 0 {
		assertRRs(t, q.authorities, mapStr["authorities"].([]common.MapStr))
	}
	if len(q.additionals) > 0 {
		assertRRs(t, q.additionals, mapStr["additionals"].([]common.MapStr))
	}
	if q.opt != nil {
		for k, v := range q.opt {
			assert.NotNil(t, mapStr["opt"].(common.MapStr)[k])
			assert.Equal(t, v, mapStr["opt"].(common.MapStr)[k])
		}
	}
}
开发者ID:ChongFeng,项目名称:beats,代码行数:30,代码来源:names_test.go

示例5: test

func (c *concurrentTxExecTest) test(t testing.TB) error {
	_, err := c.tx.Exec("NOSERT|people|name=Chris,age=?,photo=CPHOTO,bdate=?", 3, chrisBirthday)
	if err != nil {
		t.Error(err)
		return err
	}
	return nil
}
开发者ID:maqayum,项目名称:gcc-libitm,代码行数:8,代码来源:sql_test.go

示例6: testMatch

func testMatch(t testing.TB, method, path, host string) {
	req, err := newRequest(method, path)
	if err != nil {
		t.Error(err)
	}

	r, _ := testMatcherGeneric.match(req)
	checkMatch(t, r, err, host)
}
开发者ID:nishanthvasudevan,项目名称:skipper,代码行数:9,代码来源:matcher_test.go

示例7: testNewGeoIP

func testNewGeoIP(t testing.TB, filename string) *GeoIP {
	data := readFile(t, filename)
	geo, err := New(bytes.NewReader(data))
	if err != nil {
		t.Error(err)
		return nil
	}
	return geo
}
开发者ID:kelixin,项目名称:geoipmap,代码行数:9,代码来源:geoip_test.go

示例8: expectResult

// expectResult returns one MapStr result from the Dns results channel. If
// no result is available then the test fails.
func expectResult(t testing.TB, dns *Dns) common.MapStr {
	select {
	case result := <-dns.results:
		return result
	default:
		t.Error("Expected a result to be published.")
	}
	return nil
}
开发者ID:venkateshdaram434,项目名称:packetbeat,代码行数:11,代码来源:dns_test.go

示例9: getPfsClient

func getPfsClient(tb testing.TB) pfs.APIClient {
	pfsdAddr := os.Getenv("PFSD_PORT_650_TCP_ADDR")
	if pfsdAddr == "" {
		tb.Error("PFSD_PORT_650_TCP_ADDR not set")
	}
	clientConn, err := grpc.Dial(fmt.Sprintf("%s:650", pfsdAddr), grpc.WithInsecure())
	require.NoError(tb, err)
	return pfs.NewAPIClient(clientConn)
}
开发者ID:angelabier1,项目名称:pachyderm,代码行数:9,代码来源:testing_test.go

示例10: fileTest

// creates a file and cleans it up after the test is run.
func fileTest(t testing.TB, testFunc func(f *os.File)) {
	f, err := ioutil.TempFile("", "")
	if err != nil {
		t.Error(err)
	}
	defer os.Remove(f.Name())
	defer f.Close()
	testFunc(f)
}
开发者ID:djherbis,项目名称:times,代码行数:10,代码来源:util_test.go

示例11: testKernel

func testKernel(t testing.TB, d *DeployInfo, bundle string, test func(k *kernel)) {

	cli, err := docker.NewDefaultClient(3 * time.Second)
	if err != nil {
		t.Fatal(err)
	}

	imgName := randSeq(16)
	containerName := randSeq(16)

	var stderr bytes.Buffer

	dockerFile, err := createDockerfile(d)
	if err != nil {
		t.Errorf("failed to create dockerfile: %v", err)
		return
	}

	if err := buildImage(dockerFile, bundle, imgName, &stderr); err != nil {
		t.Errorf("could not build image: %v %s", err, stderr.String())
		return
	}
	defer exec.Command("docker", "rmi", imgName).Run()
	stderr.Reset()

	cid, conn, err := startContainer(imgName, containerName)
	if err != nil {
		t.Errorf("could not start container: %v", err)
		return
	}
	defer exec.Command("docker", "rm", "-f", cid).Run()

	errc := make(chan error, 1)
	go func() {
		cli.Wait(cid)
		errc <- fmt.Errorf("container exited")
	}()

	go func() {
		<-time.After(10 * time.Second)
		errc <- fmt.Errorf("prediction timed out")
	}()

	go func() {
		kernel, err := newKernel(conn, &stderr)
		if err != nil {
			errc <- fmt.Errorf("could not init model: %v %s", err, stderr.String())
			return
		}
		test(kernel)
		errc <- nil
	}()
	if err = <-errc; err != nil {
		t.Error(err)
	}
}
开发者ID:yhat,项目名称:workload-simulator,代码行数:56,代码来源:kernel_test.go

示例12: checkMatch

func checkMatch(t testing.TB, r *Route, err error, host string) {
	if err != nil {
		t.Error(err)
		return
	}

	if r.Backend != host {
		t.Error("failed to match the right value", r.Backend, host)
	}
}
开发者ID:nishanthvasudevan,项目名称:skipper,代码行数:10,代码来源:matcher_test.go

示例13: expectResult

// expectResult returns one MapStr result from the Dns results channel. If
// no result is available then the test fails.
func expectResult(t testing.TB, dns *dnsPlugin) common.MapStr {
	client := dns.results.(*publish.ChanTransactions)
	select {
	case result := <-client.Channel:
		return result
	default:
		t.Error("Expected a result to be published.")
	}
	return nil
}
开发者ID:ruflin,项目名称:beats,代码行数:12,代码来源:dns_test.go

示例14: expectResult

// expectResult returns one MapStr result from the Dns results channel. If
// no result is available then the test fails.
func expectResult(t testing.TB, dns *Dns) common.MapStr {
	client := dns.results.(publisher.ChanClient)
	select {
	case result := <-client.Channel:
		return result
	default:
		t.Error("Expected a result to be published.")
	}
	return nil
}
开发者ID:navenel,项目名称:packetbeat,代码行数:12,代码来源:dns_test.go

示例15: solveOfficial

func solveOfficial(tb testing.TB) {
	test :=
		`1 _ 3 _ _ 6 _ 8 _
_ 5 _ _ 8 _ 1 2 _
7 _ 9 1 _ 3 _ 5 6
_ 3 _ _ 6 7 _ 9 _
5 _ 7 8 _ _ _ 3 _
8 _ 1 _ 3 _ 5 _ 7
_ 4 _ _ 7 8 _ 1 _
6 _ 8 _ _ 2 _ 4 _
_ 1 2 _ 4 5 _ 7 8
`
	expect :=
		`1 2 3 4 5 6 7 8 9
4 5 6 7 8 9 1 2 3
7 8 9 1 2 3 4 5 6
2 3 4 5 6 7 8 9 1
5 6 7 8 9 1 2 3 4
8 9 1 2 3 4 5 6 7
3 4 5 6 7 8 9 1 2
6 7 8 9 1 2 3 4 5
9 1 2 3 4 5 6 7 8
`

	var puzz puzzle
	in := bytes.NewBufferString(test)

	if err := puzz.init(in); err != nil {
		tb.Error(err)
	}

	vout := &bytes.Buffer{}

	var category string
	puzz, category = solve(puzz, vout)
	tb.Log(vout)

	if err := puzz.solved(); err != nil {
		tb.Errorf("puzzle not solved [%s]", err)
	}
	if !strings.EqualFold("hard", category) {
		tb.Error("puzzle not hard")
	}

	out := &bytes.Buffer{}
	puzz.printme(out)

	actual := out.String()
	if expect != actual {
		tb.Errorf("Expect [%s] Actual [%s]", expect, actual)
	}

	tb.Log(out)
}
开发者ID:bruceadowns,项目名称:sudoku,代码行数:54,代码来源:sudoku_test.go


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