當前位置: 首頁>>代碼示例>>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;未經允許,請勿轉載。