本文整理汇总了Golang中testing.TB.Logf方法的典型用法代码示例。如果您正苦于以下问题:Golang TB.Logf方法的具体用法?Golang TB.Logf怎么用?Golang TB.Logf使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类testing.TB
的用法示例。
在下文中一共展示了TB.Logf方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Golang代码示例。
示例1: TestCreateSnapshot
// TestCreateSnapshot creates a snapshot filled with fake data. The
// fake data is generated deterministically from the timestamp `at`, which is
// also used as the snapshot's timestamp.
func TestCreateSnapshot(t testing.TB, repo *repository.Repository, at time.Time) backend.ID {
fakedir := fmt.Sprintf("fakedir-at-%v", at.Format("2006-01-02 15:04:05"))
snapshot, err := NewSnapshot([]string{fakedir})
if err != nil {
t.Fatal(err)
}
snapshot.Time = at
treeID := saveTree(t, repo, at.UnixNano())
snapshot.Tree = &treeID
id, err := repo.SaveJSONUnpacked(backend.Snapshot, snapshot)
if err != nil {
t.Fatal(err)
}
t.Logf("saved snapshot %v", id.Str())
err = repo.Flush()
if err != nil {
t.Fatal(err)
}
err = repo.SaveIndex()
if err != nil {
t.Fatal(err)
}
return id
}
示例2: loadIDSet
func loadIDSet(t testing.TB, filename string) restic.BlobSet {
f, err := os.Open(filename)
if err != nil {
t.Logf("unable to open golden file %v: %v", filename, err)
return restic.NewBlobSet()
}
sc := bufio.NewScanner(f)
blobs := restic.NewBlobSet()
for sc.Scan() {
var h restic.BlobHandle
err := json.Unmarshal([]byte(sc.Text()), &h)
if err != nil {
t.Errorf("file %v contained invalid blob: %#v", filename, err)
continue
}
blobs.Insert(h)
}
if err = f.Close(); err != nil {
t.Errorf("closing file %v failed with error %v", filename, err)
}
return blobs
}
示例3: cmdKeyRemove
func cmdKeyRemove(t testing.TB, global GlobalOptions, IDs []string) {
cmd := &CmdKey{global: &global}
t.Logf("remove %d keys: %q\n", len(IDs), IDs)
for _, id := range IDs {
OK(t, cmd.Execute([]string{"rm", id}))
}
}
示例4: ConstructRandomStateDelta
func ConstructRandomStateDelta(
t testing.TB,
chaincodeIDPrefix string,
numChaincodes int,
maxKeySuffix int,
numKeysToInsert int,
kvSize int) *StateDelta {
delta := NewStateDelta()
s2 := rand.NewSource(time.Now().UnixNano())
r2 := rand.New(s2)
for i := 0; i < numKeysToInsert; i++ {
chaincodeID := chaincodeIDPrefix + "_" + strconv.Itoa(r2.Intn(numChaincodes))
key := "key_" + strconv.Itoa(r2.Intn(maxKeySuffix))
valueSize := kvSize - len(key)
if valueSize < 1 {
panic(fmt.Errorf("valueSize cannot be less than one. ValueSize=%d", valueSize))
}
value := testutil.ConstructRandomBytes(t, valueSize)
delta.Set(chaincodeID, key, value, nil)
}
for _, chaincodeDelta := range delta.ChaincodeStateDeltas {
sortedKeys := chaincodeDelta.getSortedKeys()
smallestKey := sortedKeys[0]
largestKey := sortedKeys[len(sortedKeys)-1]
t.Logf("chaincode=%s, numKeys=%d, smallestKey=%s, largestKey=%s", chaincodeDelta.ChaincodeID, len(sortedKeys), smallestKey, largestKey)
}
return delta
}
示例5: 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...)
}
}
示例6: saveTree
// saveTree saves a tree of fake files in the repo and returns the ID.
func saveTree(t testing.TB, repo *repository.Repository, seed int64) backend.ID {
rnd := rand.NewSource(seed)
numNodes := int(rnd.Int63() % 64)
t.Logf("create %v nodes", numNodes)
var tree Tree
for i := 0; i < numNodes; i++ {
seed := rnd.Int63() % maxSeed
size := rnd.Int63() % maxFileSize
node := &Node{
Name: fmt.Sprintf("file-%v", seed),
Type: "file",
Mode: 0644,
Size: uint64(size),
}
node.Content = saveFile(t, repo, fakeFile(t, seed, size))
tree.Nodes = append(tree.Nodes, node)
}
id, err := repo.SaveJSON(pack.Tree, tree)
if err != nil {
t.Fatal(err)
}
return id
}
示例7: innerTest
func innerTest(client *FlumeClient, t testing.TB) {
//header: {businessName=feed, type=list}.
//body: 100311 list {"view_self":0,"remoteid":"5445285","timestamp":1403512030,"flume_timestamp":"2014-06-23 16:27:10","business_type":"feed"}
body := "{\"view_self\":0,\"remoteid\":\"5445285\",\"timestamp\":1403512030,\"flume_timestamp\":\"2014-06-23 16:27:10\",\"business_type\":\"feed\"}"
var demo LogDemo
err := json.Unmarshal([]byte(body), &demo)
if nil != err {
t.Fail()
return
}
data, err := json.Marshal(demo)
if nil != err {
t.Fail()
return
}
header := make(map[string]string, 2)
header["businessName"] = "feed"
header["type"] = "list"
for i := 0; i < 1; i++ {
err := client.Append(header, data)
if nil != err {
t.Log(err.Error())
t.Fail()
} else {
t.Logf("%d, send succ ", i)
}
}
}
示例8: innerTest
func innerTest(client *FlumeClient, t testing.TB) {
//header: {businessName=feed, type=list}.
//body: 100311 list {"view_self":0,"remoteid":"5445285","timestamp":1403512030,"flume_timestamp":"2014-06-23 16:27:10","business_type":"feed"}
body := "{\"view_self\":0,\"remoteid\":\"5445285\",\"timestamp\":1403512030,\"flume_timestamp\":\"2014-06-23 16:27:10\",\"business_type\":\"feed\"}"
var demo LogDemo
err := json.Unmarshal([]byte(body), &demo)
if nil != err {
t.Fail()
return
}
data, err := json.Marshal(demo)
if nil != err {
t.Fail()
return
}
event := NewFlumeEvent("feed", "list", data)
events := []*flume.ThriftFlumeEvent{event}
for i := 0; i < 1; i++ {
err := client.AppendBatch(events)
err = client.Append(event)
if nil != err {
t.Log(err.Error())
t.Fail()
} else {
t.Logf("%d, send succ ", i)
}
}
}
示例9: withTestEnvironment
// withTestEnvironment creates a test environment and calls f with it. After f has
// returned, the temporary directory is removed.
func withTestEnvironment(t testing.TB, f func(*testEnvironment, GlobalOptions)) {
if !RunIntegrationTest {
t.Skip("integration tests disabled")
}
tempdir, err := ioutil.TempDir(TestTempDir, "restic-test-")
OK(t, err)
env := testEnvironment{
base: tempdir,
cache: filepath.Join(tempdir, "cache"),
repo: filepath.Join(tempdir, "repo"),
testdata: filepath.Join(tempdir, "testdata"),
}
OK(t, os.MkdirAll(env.testdata, 0700))
OK(t, os.MkdirAll(env.cache, 0700))
OK(t, os.MkdirAll(env.repo, 0700))
f(&env, configureRestic(t, env.cache, env.repo))
if !TestCleanup {
t.Logf("leaving temporary directory %v used for test", tempdir)
return
}
RemoveAll(t, tempdir)
}
示例10: testRunInit
func testRunInit(t testing.TB, opts GlobalOptions) {
repository.TestUseLowSecurityKDFParameters(t)
restic.TestSetLockTimeout(t, 0)
OK(t, runInit(opts, nil))
t.Logf("repository initialized at %v", opts.Repo)
}
示例11: AssertPanic
func AssertPanic(t testing.TB, msg string) {
x := recover()
if x == nil {
t.Fatal(msg)
} else {
t.Logf("A panic was caught successfully. Actual msg = %s", x)
}
}
示例12: cleanupTempdir
func cleanupTempdir(t testing.TB, tempdir string) {
if !TestCleanup {
t.Logf("leaving temporary directory %v used for test", tempdir)
return
}
RemoveAll(t, tempdir)
}
示例13: fatal
func fatal(tb testing.TB, userMsgAndArgs []interface{}, msgFmt string, msgArgs ...interface{}) {
logMessage(tb, userMsgAndArgs)
_, file, line, ok := runtime.Caller(2)
if ok {
tb.Logf("%s:%d", file, line)
}
tb.Fatalf(msgFmt, msgArgs...)
}
示例14: cmdBackup
func cmdBackup(t testing.TB, global GlobalOptions, target []string, parentID backend.ID) {
cmd := &CmdBackup{global: &global}
cmd.Parent = parentID.String()
t.Logf("backing up %v", target)
OK(t, cmd.Execute(target))
}
示例15: logMessage
func logMessage(tb testing.TB, msgAndArgs ...interface{}) {
if len(msgAndArgs) == 1 {
tb.Logf(msgAndArgs[0].(string))
}
if len(msgAndArgs) > 1 {
tb.Logf(msgAndArgs[0].(string), msgAndArgs[1:]...)
}
}