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


Golang TB.Fatalf方法代码示例

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


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

示例1: mustConnect

func mustConnect(t testing.TB, config pgx.ConnConfig) *pgx.Conn {
	conn, err := pgx.Connect(config)
	if err != nil {
		t.Fatalf("Unable to establish connection: %v", err)
	}
	return conn
}
开发者ID:segmentio,项目名称:pgx,代码行数:7,代码来源:helper_test.go

示例2: run

func run(t testing.TB, commands []Command) {
	e := empiretest.NewEmpire(t)
	s := empiretest.NewServer(t, e)
	defer s.Close()

	token, err := e.AccessTokensCreate(&empire.AccessToken{
		User: &empire.User{Name: "fake", GitHubToken: "token"},
	})
	if err != nil {
		t.Fatal(err)
	}

	for _, cmd := range commands {
		got := cli(t, token.Token, s.URL, cmd.Command)

		if want, ok := cmd.Output.(string); ok {
			if want != "" {
				want = want + "\n"
			}

			if got != want {
				t.Fatalf("%q != %q", got, want)
			}
		} else if regex, ok := cmd.Output.(*regexp.Regexp); ok {
			if !regex.MatchString(got) {
				t.Fatalf("%q != %q", got, regex.String())
			}
		}
	}
}
开发者ID:frewsxcv,项目名称:empire,代码行数:30,代码来源:cli_test.go

示例3: mustExec

func mustExec(t testing.TB, conn *pgx.Conn, sql string, arguments ...interface{}) (commandTag pgx.CommandTag) {
	var err error
	if commandTag, err = conn.Exec(sql, arguments...); err != nil {
		t.Fatalf("Exec unexpectedly failed with %v: %v", sql, err)
	}
	return
}
开发者ID:segmentio,项目名称:pgx,代码行数:7,代码来源:helper_test.go

示例4: mustNewRR

func mustNewRR(tb testing.TB, s string) dns.RR {
	rr, err := dns.NewRR(s)
	if err != nil {
		tb.Fatalf("invalid RR %q: %v", s, err)
	}
	return rr
}
开发者ID:albertito,项目名称:dnss,代码行数:7,代码来源:caching_test.go

示例5: saveFile

func saveFile(t testing.TB, be Saver, filename string, n int) {
	f, err := os.Open(filename)
	if err != nil {
		t.Fatal(err)
	}

	data := make([]byte, n)
	m, err := io.ReadFull(f, data)

	if m != n {
		t.Fatalf("read wrong number of bytes from %v: want %v, got %v", filename, m, n)
	}

	if err = f.Close(); err != nil {
		t.Fatal(err)
	}

	h := backend.Handle{Type: backend.Data, Name: backend.Hash(data).String()}

	err = be.Save(h, data)
	if err != nil {
		t.Fatal(err)
	}

	err = os.Remove(filename)
	if err != nil {
		t.Fatal(err)
	}
}
开发者ID:MirkoDziadzka,项目名称:restic,代码行数:29,代码来源:packer_manager_test.go

示例6: CheckGossip

// CheckGossip fetches the gossip infoStore from each node and invokes the given
// function. The test passes if the function returns 0 for every node,
// retrying for up to the given duration.
func CheckGossip(
	ctx context.Context, t testing.TB, c cluster.Cluster, d time.Duration, f CheckGossipFunc,
) {
	err := util.RetryForDuration(d, func() error {
		select {
		case <-stopper.ShouldStop():
			t.Fatalf("interrupted")
			return nil
		case <-time.After(1 * time.Second):
		}

		var infoStatus gossip.InfoStatus
		for i := 0; i < c.NumNodes(); i++ {
			if err := httputil.GetJSON(cluster.HTTPClient, c.URL(ctx, i)+"/_status/gossip/local", &infoStatus); err != nil {
				return errors.Wrapf(err, "failed to get gossip status from node %d", i)
			}
			if err := f(infoStatus.Infos); err != nil {
				return errors.Errorf("node %d: %s", i, err)
			}
		}

		return nil
	})
	if err != nil {
		t.Fatal(errors.Errorf("condition failed to evaluate within %s: %s", d, err))
	}
}
开发者ID:BramGruneir,项目名称:cockroach,代码行数:30,代码来源:util.go

示例7: run

func run(t testing.TB, commands []Command) {
	e := empiretest.NewEmpire(t)
	s := empiretest.NewServer(t, e)
	defer s.Close()

	token, err := e.AccessTokensCreate(&empire.AccessToken{
		User: &empire.User{Name: "fake", GitHubToken: "token"},
	})
	if err != nil {
		t.Fatal(err)
	}

	for _, cmd := range commands {
		got := cli(t, token.Token, s.URL, cmd.Command)

		want := cmd.Output
		if want != "" {
			want = want + "\n"
		}

		if got != want {
			t.Fatalf("%q != %q", got, want)
		}
	}
}
开发者ID:yourchanges,项目名称:empire,代码行数:25,代码来源:cli_test.go

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

示例9: AssertEqualf

// AssertEqualf verifies that two objects are equals and calls FailNow() to
// immediately cancel the test case.
//
// It must be called from the main goroutine. Other goroutines must call
// ExpectEqual* flavors.
//
// This functions enables specifying an arbitrary string on failure.
//
// Equality is determined via reflect.DeepEqual().
func AssertEqualf(t testing.TB, expected, actual interface{}, format string, items ...interface{}) {
	// This is cheezy, as there's no way to figure out if the test was properly
	// started by the test framework.
	found := false
	root := ""
	for i := 1; ; i++ {
		if _, file, _, ok := runtime.Caller(i); ok {
			if filepath.Base(file) == "testing.go" {
				found = true
				break
			}
			root = file
		} else {
			break
		}
	}
	if !found {
		t.Logf(Decorate("ut.AssertEqual*() function MUST be called from within main test goroutine, use ut.ExpectEqual*() instead; found %s."), root)
		// TODO(maruel): Warning: this will be enforced soon.
		//t.Fail()
	}
	if !reflect.DeepEqual(actual, expected) {
		t.Fatalf(Decorate(format), items...)
	}
}
开发者ID:nodirt,项目名称:pre-commit-go,代码行数:34,代码来源:utiltest.go

示例10: newScheduler

func newScheduler(t testing.TB) *docker.Scheduler {
	s, err := docker.NewSchedulerFromEnv()
	if err != nil {
		t.Fatalf("Could not build docker scheduler: %v", err)
	}
	return s
}
开发者ID:ejholmes,项目名称:12factor,代码行数:7,代码来源:docker_test.go

示例11: createClient

func createClient(t testing.TB, urlStr string) *Client {
	client, _, err := Dial(urlStr, nil) // use default ClientMessageHandler
	if err != nil {
		t.Fatalf("Dial: ", err)
	}
	return client
}
开发者ID:ayinlaabdulsalam,项目名称:networkwebsockets,代码行数:7,代码来源:client_server_test.go

示例12: withTestTerminal

func withTestTerminal(name string, t testing.TB, fn func(*FakeTerminal)) {
	os.Setenv("TERM", "dumb")
	listener, err := net.Listen("tcp", "localhost:0")
	if err != nil {
		t.Fatalf("couldn't start listener: %s\n", err)
	}
	defer listener.Close()
	server := rpc2.NewServer(&service.Config{
		Listener:    listener,
		ProcessArgs: []string{test.BuildFixture(name).Path},
	}, false)
	if err := server.Run(); err != nil {
		t.Fatal(err)
	}
	client := rpc2.NewClient(listener.Addr().String())
	defer func() {
		client.Detach(true)
	}()

	ft := &FakeTerminal{
		t:    t,
		Term: New(client, nil),
	}
	fn(ft)
}
开发者ID:DuoSoftware,项目名称:v6engine-deps,代码行数:25,代码来源:command_test.go

示例13: dial

func dial(t testing.TB) net.Conn {
	c, err := net.Dial("unix", sockpath)
	if err != nil {
		t.Fatalf("Couldn't open %s: %s.", sockpath, err)
	}
	return c
}
开发者ID:bjc,项目名称:goctl,代码行数:7,代码来源:goctl_test.go

示例14: NewRequest

// NewRequest is like http.NewRequest, but calls t.Fatal on error.
func NewRequest(t testing.TB, method, url string, body io.Reader) *http.Request {
	req, err := http.NewRequest(method, url, body)
	if err != nil {
		t.Fatalf("Bug in test: cannot construct http.Request from method=%q, url=%q, body=%#v: %s", method, url, body, err)
	}
	return req
}
开发者ID:tv42,项目名称:mockhttp,代码行数:8,代码来源:mockrequest.go

示例15: fatal

func fatal(t testing.TB, msg string) {
	// Hack to override the default line number printing.
	// This is the standard trick used by gocheck and others.
	// See https://code.google.com/p/go/issues/detail?id=4899
	// for one better solution for the future.
	t.Fatalf("\r\t%s: %s", caller(), msg)
}
开发者ID:philc,项目名称:gumshoedb,代码行数:7,代码来源:asrt.go


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