本文整理汇总了Golang中testing.T.Failed方法的典型用法代码示例。如果您正苦于以下问题:Golang T.Failed方法的具体用法?Golang T.Failed怎么用?Golang T.Failed使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类testing.T
的用法示例。
在下文中一共展示了T.Failed方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Golang代码示例。
示例1: TestFailIfEqualToWithUnequalInts
func TestFailIfEqualToWithUnequalInts(t *testing.T) {
t2 := new(testing.T)
Fail(t2).If(intsAreEqual(6, 5))
if t2.Failed() {
t.Error()
}
}
示例2: DumpEtcdOnFailure
func DumpEtcdOnFailure(t *testing.T) {
if !t.Failed() {
return
}
pc := make([]uintptr, 10)
goruntime.Callers(2, pc)
f := goruntime.FuncForPC(pc[0])
last := strings.LastIndex(f.Name(), "Test")
if last == -1 {
last = 0
}
name := f.Name()[last:]
client := NewEtcdClient()
etcdResponse, err := client.RawGet("/", false, true)
if err != nil {
t.Logf("error dumping etcd: %v", err)
return
}
if err := ioutil.WriteFile(GetBaseDir()+"/etcd-dump-"+name+".json", etcdResponse.Body, os.FileMode(0444)); err != nil {
t.Logf("error dumping etcd: %v", err)
return
}
}
示例3: TestOFB
func TestOFB(t *testing.T) {
for _, tt := range ofbTests {
test := tt.name
c, err := aes.NewCipher(tt.key)
if err != nil {
t.Errorf("%s: NewCipher(%d bytes) = %s", test, len(tt.key), err)
continue
}
for j := 0; j <= 5; j += 5 {
plaintext := tt.in[0 : len(tt.in)-j]
ofb := cipher.NewOFB(c, tt.iv)
ciphertext := make([]byte, len(plaintext))
ofb.XORKeyStream(ciphertext, plaintext)
if !bytes.Equal(ciphertext, tt.out[:len(plaintext)]) {
t.Errorf("%s/%d: encrypting\ninput % x\nhave % x\nwant % x", test, len(plaintext), plaintext, ciphertext, tt.out)
}
}
for j := 0; j <= 5; j += 5 {
ciphertext := tt.out[0 : len(tt.in)-j]
ofb := cipher.NewOFB(c, tt.iv)
plaintext := make([]byte, len(ciphertext))
ofb.XORKeyStream(plaintext, ciphertext)
if !bytes.Equal(plaintext, tt.in[:len(ciphertext)]) {
t.Errorf("%s/%d: decrypting\nhave % x\nwant % x", test, len(ciphertext), plaintext, tt.in)
}
}
if t.Failed() {
break
}
}
}
示例4: TestMultipleAfter
func TestMultipleAfter(t *testing.T) {
fakeTest := testing.T{}
g := Goblin(&fakeTest)
after := 0
g.Describe("Numbers", func() {
g.After(func() {
after++
})
g.After(func() {
after++
})
g.It("Should call all the registered after", func() {
g.Assert(after).Equal(0)
})
})
if fakeTest.Failed() && after != 2 {
t.Fatal("Failed")
}
}
示例5: TestMultipleBefore
func TestMultipleBefore(t *testing.T) {
fakeTest := testing.T{}
g := Goblin(&fakeTest)
g.Describe("Numbers", func() {
before := 0
g.Before(func() {
before++
})
g.Before(func() {
before++
})
g.It("Should have called all the registered before", func() {
g.Assert(before).Equal(2)
})
})
if fakeTest.Failed() {
t.Fatal("Failed")
}
}
示例6: TestCTR_AES
func TestCTR_AES(t *testing.T) {
for _, tt := range ctrAESTests {
test := tt.name
c, err := aes.NewCipher(tt.key)
if err != nil {
t.Errorf("%s: NewCipher(%d bytes) = %s", test, len(tt.key), err)
continue
}
for j := 0; j <= 5; j += 5 {
in := tt.in[0 : len(tt.in)-j]
ctr := cipher.NewCTR(c, tt.iv)
encrypted := make([]byte, len(in))
ctr.XORKeyStream(encrypted, in)
if out := tt.out[0:len(in)]; !bytes.Equal(out, encrypted) {
t.Errorf("%s/%d: CTR\ninpt %x\nhave %x\nwant %x", test, len(in), in, encrypted, out)
}
}
for j := 0; j <= 7; j += 7 {
in := tt.out[0 : len(tt.out)-j]
ctr := cipher.NewCTR(c, tt.iv)
plain := make([]byte, len(in))
ctr.XORKeyStream(plain, in)
if out := tt.in[0:len(in)]; !bytes.Equal(out, plain) {
t.Errorf("%s/%d: CTRReader\nhave %x\nwant %x", test, len(out), plain, out)
}
}
if t.Failed() {
break
}
}
}
示例7: TestUnarchiveRepo
func TestUnarchiveRepo(t *testing.T) {
temp, err := ioutil.TempDir("", "unarchive-repo-test")
clonePath := "go/src/github.com/baz/foo.bar"
cloned := filepath.Join(temp, clonePath)
wd, _ := os.Getwd()
file := fmt.Sprintf("%s/test_data/TestUnarchiveRepo/baz-foo.bar-v4.0.3-44-fasdfadsflkjlkjlkjlkjlkjlkjlj.tar.gz", wd)
unpacked, err := unarchiveRepo(file, temp, clonePath, testBuildtimeout)
if err != nil {
t.Errorf("|%v|", err)
}
if unpacked != cloned {
t.Errorf("Should have been %s was %s", cloned, unpacked)
}
files, err := ioutil.ReadDir(cloned)
if err != nil {
t.Errorf("|%v|", err)
}
if len(files) != 2 {
t.Errorf("Directory %s had %v files.", cloned, len(files))
}
if !t.Failed() {
//only remove output on success
os.RemoveAll(temp)
}
}
示例8: TestOneHostVlan_regress
func TestOneHostVlan_regress(t *testing.T) {
defer func() {
utils.ConfigCleanupCommon(t, testbed.GetNodes())
utils.StopOnError(t.Failed())
}()
cfgFile := utils.GetCfgFile("one_host_vlan")
jsonCfg, err := ioutil.ReadFile(cfgFile)
if err != nil {
t.Fatalf("failed to read config file %s \n", err)
}
utils.ConfigSetupCommon(t, string(jsonCfg), testbed.GetNodes())
node1 := testbed.GetNodes()[0]
utils.StartServer(t, node1, "myContainer1")
defer func() {
utils.DockerCleanup(t, node1, "myContainer1")
}()
ipAddress := utils.GetIPAddress(t, node1, "orange-myContainer1", u.EtcdNameStr)
utils.StartClient(t, node1, "myContainer2", ipAddress)
defer func() {
utils.DockerCleanup(t, node1, "myContainer2")
}()
}
示例9: TestIntegrationInsert
func TestIntegrationInsert(t *testing.T) {
db := setUpDatabase(t)
defer tearDownDatabase(db, t)
// Add new document
doc := &Person{Name: "Peter", Height: 185, Alive: true}
err := db.Insert(doc)
if err != nil {
t.Fatal("Inserted new document, error:", err)
}
if doc.ID == "" {
t.Error("Inserted new document, should have ID set. Doc:", doc)
}
if doc.Rev == "" {
t.Error("Inserted new document, should have Rev set. Doc:", doc)
}
if t.Failed() {
t.FailNow()
}
// Edit existing
oldID, oldRev := doc.ID, doc.Rev
doc.Alive = false
err = db.Insert(doc)
if doc.Rev == oldRev {
t.Error("Edited existing document, should have different rev. Doc:", doc)
}
if doc.ID != oldID {
t.Error("Edited existing document, should have same id. Old:", oldID, "New:", doc.ID, doc)
}
if err != nil {
t.Fatal("Edited existing document, error:", err)
}
}
示例10: TestRefuteNil
func TestRefuteNil(t *testing.T) {
T := new(testing.T) // Stub
Go(T).RefuteNil(1, "should refute nil on int")
if T.Failed() {
t.Error("RefuteNil should not have failed.")
}
T = new(testing.T) // Stub
Go(T).RefuteNil("a", "should refute nil on string")
if T.Failed() {
t.Error("RefuteNil should not have failed.")
}
T = new(testing.T) // Stub
arr := []string{"a", "b"}
Go(T).RefuteNil(arr, "should refute nil on array")
if T.Failed() {
t.Error("RefuteNil should not have failed.")
}
T = new(testing.T) // Stub
var iface interface{}
iface = "a"
Go(T).RefuteNil(iface, "should refute nil on interface")
if T.Failed() {
t.Error("RefuteNil should not have failed.")
}
T = new(testing.T) // Stub
Go(T).RefuteNil(nil, "should refute nil on int")
if !T.Failed() {
t.Error("RefuteNil should have failed.")
}
}
示例11: TestStorage_create
func TestStorage_create(t *testing.T) {
_, err := NewStorage("tests.db", true)
if err != nil {
t.Failed()
}
}
示例12: TestAssertDeepEqual
func TestAssertDeepEqual(t *testing.T) {
T := new(testing.T) // Stub
Go(T).AssertDeepEqual(1, 1, "should assert deep equal int")
if T.Failed() {
t.Error("AssertDeepEqual should not have failed.")
}
T = new(testing.T) // Stub
Go(T).AssertDeepEqual(1.0, 1.0)
if T.Failed() {
t.Error("AssertDeepEqual should not have failed.")
}
T = new(testing.T) // Stub
m1 := map[string]string{"a": "a"}
m2 := map[string]string{"a": "a"}
Go(T).AssertDeepEqual(m1, m2, "should assert deep equal map")
if T.Failed() {
t.Error("AssertDeepEqual should not have failed.")
}
T = new(testing.T) // Stub
a1 := []string{"a", "b"}
a2 := []string{"a", "b"}
Go(T).AssertDeepEqual(a1, a2, "should assert deep equal array")
if T.Failed() {
t.Error("AssertDeepEqual should not have failed.")
}
T = new(testing.T) // Stub
Go(T).AssertDeepEqual(1, 2, "should assert deep equal int")
if !T.Failed() {
t.Error("AssertDeepEqual should have failed.")
}
}
示例13: TestNestedBeforeEach
func TestNestedBeforeEach(t *testing.T) {
fakeTest := testing.T{}
g := Goblin(&fakeTest)
g.Describe("Numbers", func() {
before := 0
g.BeforeEach(func() {
before++
})
g.Describe("Addition", func() {
g.BeforeEach(func() {
before++
})
g.It("Should have called all the registered beforeEach", func() {
g.Assert(before).Equal(2)
})
g.It("Should have called all the registered beforeEach also for this one", func() {
g.Assert(before).Equal(4)
})
})
})
if fakeTest.Failed() {
t.Fatal("Failed")
}
}
示例14: main
func main() {
// catch errors
var tst testing.T
defer func() {
if mpi.Rank() == 0 {
if err := recover(); err != nil {
io.PfRed("ERROR: %v\n", err)
}
if tst.Failed() {
io.PfRed("test failed\n")
}
}
mpi.Stop(false)
}()
mpi.Start(false)
// start global variables and log
analysis := fem.NewFEM("data/bh16.sim", "", true, true, false, true, true, 0)
// run simulation
err := analysis.Run()
if err != nil {
tst.Error("Run failed\n")
return
}
// check
skipK := true
tolK := 1e-12
tolu := 1e-15
tols := 1e-12
fem.TestingCompareResultsU(&tst, "data/bh16.sim", "cmp/bh16.cmp", "", tolK, tolu, tols, skipK, true)
}
示例15: TestBlock
func TestBlock(t *testing.T) {
if err := bakupIptables(); err != nil {
t.Fatalf("Backup iptables error [%s]\n", err)
}
if err := restoreTp(RULETP, ACCEPT); err != nil {
t.Fatalf("Restore iptables template error [%s]\n", err)
}
rules, err := FetchAll()
if err != nil {
t.Fatalf("Fetch all rules error [%s]\n", err)
}
for id, _ := range rules {
Block(id)
}
if err := Update(); err != nil {
t.Fatalf("Update rules error [%s]\n", err)
}
rules, err = FetchAll()
if err != nil {
t.Fatalf("Fetch all rules again error [%s]\n", err)
}
for id, rule := range rules {
if rule.Status == ACCEPT {
t.Errorf("Container [%s] is not blocked", id)
}
}
restoreIptables(originalRule)
if !t.Failed() {
t.Log("Block Passed")
}
return
}