本文整理汇总了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)
}
}
}
}
}
示例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
}
示例3: Error
func Error(t testing.TB, err error) bool {
if err == nil {
t.Error("Expecting error but nil got!")
return false
}
return true
}
示例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])
}
}
}
示例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
}
示例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)
}
示例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
}
示例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
}
示例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)
}
示例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)
}
示例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)
}
}
示例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)
}
}
示例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
}
示例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
}
示例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)
}