本文整理汇总了Golang中testing.TB.Fatal方法的典型用法代码示例。如果您正苦于以下问题:Golang TB.Fatal方法的具体用法?Golang TB.Fatal怎么用?Golang TB.Fatal使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类testing.TB
的用法示例。
在下文中一共展示了TB.Fatal方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Golang代码示例。
示例1: assertNotCheckpointed
func assertNotCheckpointed(t testing.TB, checkpointC chan k.Record) {
select {
case <-checkpointC:
t.Fatal("Expected no checkpoint")
default:
}
}
示例2: DriverTestDeepLayerRead
// DriverTestDeepLayerRead reads a file from a lower layer under a given number of layers
func DriverTestDeepLayerRead(t testing.TB, layerCount int, drivername string, driverOptions ...string) {
driver := GetDriver(t, drivername, driverOptions...)
defer PutDriver(t)
base := stringid.GenerateRandomID()
if err := driver.Create(base, "", "", nil); err != nil {
t.Fatal(err)
}
content := []byte("test content")
if err := addFile(driver, base, "testfile.txt", content); err != nil {
t.Fatal(err)
}
topLayer, err := addManyLayers(driver, base, layerCount)
if err != nil {
t.Fatal(err)
}
err = checkManyLayers(driver, topLayer, layerCount)
if err != nil {
t.Fatal(err)
}
if err := checkFile(driver, topLayer, "testfile.txt", content); err != nil {
t.Fatal(err)
}
}
示例3: NewTestServer
func NewTestServer(t testing.TB, protocol uint8) *TestServer {
laddr, err := net.ResolveTCPAddr("tcp", "127.0.0.1:0")
if err != nil {
t.Fatal(err)
}
listen, err := net.ListenTCP("tcp", laddr)
if err != nil {
t.Fatal(err)
}
headerSize := 8
if protocol > protoVersion2 {
headerSize = 9
}
srv := &TestServer{
Address: listen.Addr().String(),
listen: listen,
t: t,
protocol: protocol,
headerSize: headerSize,
quit: make(chan struct{}),
}
go srv.serve()
return srv
}
示例4: tbLoadData
func tbLoadData(tb testing.TB, filename string) []byte {
data, err := ioutil.ReadFile("../testdata/" + filename)
if err != nil {
tb.Fatal(err)
}
return data
}
示例5: NetPipe
func NetPipe(t testing.TB) (net.Conn, net.Conn) {
l, err := net.Listen("tcp", "localhost:0")
if err != nil {
t.Fatal(err)
}
defer l.Close()
client_future := utils.NewFuture()
go func() {
client_future.Set(net.Dial(l.Addr().Network(), l.Addr().String()))
}()
var errs utils.ErrorGroup
server_conn, err := l.Accept()
errs.Add(err)
client_conn, err := client_future.Get()
errs.Add(err)
err = errs.Finalize()
if err != nil {
if server_conn != nil {
server_conn.Close()
}
if client_conn != nil {
client_conn.(net.Conn).Close()
}
t.Fatal(err)
}
return server_conn, client_conn.(net.Conn)
}
示例6: testQueryType
func testQueryType(t testing.TB, fn func(*queryTest), itype indexType) {
defer index.SetVerboseCorpusLogging(true)
index.SetVerboseCorpusLogging(false)
idx := index.NewMemoryIndex() // string key-value pairs in memory, as if they were on disk
var err error
var corpus *index.Corpus
if itype == indexCorpusBuild {
if corpus, err = idx.KeepInMemory(); err != nil {
t.Fatal(err)
}
}
qt := &queryTest{
t: t,
id: indextest.NewIndexDeps(idx),
itype: itype,
}
qt.id.Fataler = t
qt.newHandler = func() *Handler {
h := NewHandler(idx, qt.id.SignerBlobRef)
if itype == indexCorpusScan {
if corpus, err = idx.KeepInMemory(); err != nil {
t.Fatal(err)
}
idx.PreventStorageAccessForTesting()
}
if corpus != nil {
h.SetCorpus(corpus)
}
return h
}
fn(qt)
}
示例7: NewClient
// NewClient implements the Cluster interface.
func (f *Farmer) NewClient(ctx context.Context, t testing.TB, i int) *client.DB {
conn, err := f.RPCContext.GRPCDial(f.Addr(ctx, i, base.DefaultPort))
if err != nil {
t.Fatal(err)
}
return client.NewDB(client.NewSender(conn))
}
示例8: verifyFile
func verifyFile(t testing.TB, path string, mode os.FileMode, uid, gid uint32) {
fi, err := os.Stat(path)
if err != nil {
t.Fatal(err)
}
if fi.Mode()&os.ModeType != mode&os.ModeType {
t.Fatalf("Expected %s type 0x%x, got 0x%x", path, mode&os.ModeType, fi.Mode()&os.ModeType)
}
if fi.Mode()&os.ModePerm != mode&os.ModePerm {
t.Fatalf("Expected %s mode %o, got %o", path, mode&os.ModePerm, fi.Mode()&os.ModePerm)
}
if fi.Mode()&os.ModeSticky != mode&os.ModeSticky {
t.Fatalf("Expected %s sticky 0x%x, got 0x%x", path, mode&os.ModeSticky, fi.Mode()&os.ModeSticky)
}
if fi.Mode()&os.ModeSetuid != mode&os.ModeSetuid {
t.Fatalf("Expected %s setuid 0x%x, got 0x%x", path, mode&os.ModeSetuid, fi.Mode()&os.ModeSetuid)
}
if fi.Mode()&os.ModeSetgid != mode&os.ModeSetgid {
t.Fatalf("Expected %s setgid 0x%x, got 0x%x", path, mode&os.ModeSetgid, fi.Mode()&os.ModeSetgid)
}
if stat, ok := fi.Sys().(*syscall.Stat_t); ok {
if stat.Uid != uid {
t.Fatalf("%s no owned by uid %d", path, uid)
}
if stat.Gid != gid {
t.Fatalf("%s not owned by gid %d", path, gid)
}
}
}
示例9: createBase
func createBase(t testing.TB, driver graphdriver.Driver, name string) {
// We need to be able to set any perms
oldmask := syscall.Umask(0)
defer syscall.Umask(oldmask)
if err := driver.CreateReadWrite(name, "", nil); err != nil {
t.Fatal(err)
}
dir, err := driver.Get(name, "")
if err != nil {
t.Fatal(err)
}
defer driver.Put(name)
subdir := path.Join(dir, "a subdir")
if err := os.Mkdir(subdir, 0705|os.ModeSticky); err != nil {
t.Fatal(err)
}
if err := os.Chown(subdir, 1, 2); err != nil {
t.Fatal(err)
}
file := path.Join(dir, "a file")
if err := ioutil.WriteFile(file, []byte("Some data"), 0222|os.ModeSetuid); err != nil {
t.Fatal(err)
}
}
示例10: newMetricSet
// newMetricSet instantiates a new MetricSet using the given configuration.
// The ModuleFactory and MetricSetFactory are obtained from the global
// Registry.
func newMetricSet(t testing.TB, config interface{}) mb.MetricSet {
c, err := common.NewConfigFrom(config)
if err != nil {
t.Fatal(err)
}
m, err := mb.NewModules([]*common.Config{c}, mb.Registry)
if err != nil {
t.Fatal(err)
}
if !assert.Len(t, m, 1) {
t.FailNow()
}
var metricSet mb.MetricSet
for _, v := range m {
if !assert.Len(t, v, 1) {
t.FailNow()
}
metricSet = v[0]
break
}
if !assert.NotNil(t, metricSet) {
t.FailNow()
}
return metricSet
}
示例11: ringN
func ringN(t testing.TB, n int) ([]*torus.Server, *temp.Server) {
servers, mds := createN(t, n)
var peers torus.PeerInfoList
for _, s := range servers {
peers = append(peers, &models.PeerInfo{
UUID: s.MDS.UUID(),
TotalBlocks: StorageSize / BlockSize,
})
}
rep := 2
ringType := ring.Ketama
if n == 1 {
rep = 1
ringType = ring.Single
}
newRing, err := ring.CreateRing(&models.Ring{
Type: uint32(ringType),
Peers: peers,
ReplicationFactor: uint32(rep),
Version: uint32(2),
})
if err != nil {
t.Fatal(err)
}
err = mds.SetRing(newRing)
if err != nil {
t.Fatal(err)
}
return servers, mds
}
示例12: newConveyor
func newConveyor(t testing.TB) *Conveyor {
db := sqlx.MustConnect("postgres", databaseURL)
if err := core.Reset(db); err != nil {
t.Fatal(err)
}
c := core.New(db)
c.BuildQueue = core.NewBuildQueue(100)
c.Logger = logs.Discard
ch := make(chan core.BuildContext)
c.BuildQueue.Subscribe(ch)
w := worker.New(c, worker.Options{
Builder: builder.BuilderFunc(func(ctx context.Context, w io.Writer, options builder.BuildOptions) (string, error) {
io.WriteString(w, "Pulling base image\n")
return "remind101/acme-inc:1234", nil
}),
BuildRequests: ch,
})
go w.Start()
return &Conveyor{
Conveyor: c,
worker: w,
}
}
示例13: newDB
func newDB(t testing.TB) *sql.DB {
db, err := sql.Open("postgres", "postgres://localhost/empire?sslmode=disable")
if err != nil {
t.Fatal(err)
}
return db
}
示例14: tearDown
func tearDown(t testing.TB) {
sigar.Procd = "/proc"
err := os.RemoveAll(procd)
if err != nil {
t.Fatal(err)
}
}
示例15: VerifyNoImports
// VerifyNoImports verifies that a package doesn't depend (directly or
// indirectly) on forbidden packages. The forbidden packages are specified as
// either exact matches or prefix matches.
// If GOPATH isn't set, it is an indication that the source is not available and
// the test is skipped.
func VerifyNoImports(
t testing.TB, pkgPath string, cgo bool, forbiddenPkgs, forbiddenPrefixes []string,
) {
// Skip test if source is not available.
if build.Default.GOPATH == "" {
t.Skip("GOPATH isn't set")
}
imports, err := TransitiveImports(pkgPath, true)
if err != nil {
t.Fatal(err)
}
for _, forbidden := range forbiddenPkgs {
if _, ok := imports[forbidden]; ok {
t.Errorf("Package %s includes %s, which is forbidden", pkgPath, forbidden)
}
}
for _, forbiddenPrefix := range forbiddenPrefixes {
for k := range imports {
if strings.HasPrefix(k, forbiddenPrefix) {
t.Errorf("Package %s includes %s, which is forbidden", pkgPath, k)
}
}
}
}