當前位置: 首頁>>代碼示例>>Golang>>正文


Golang T.Failed方法代碼示例

本文整理匯總了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()
	}
}
開發者ID:tychofreeman,項目名稱:Linear,代碼行數:7,代碼來源:util_test.go

示例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
	}
}
開發者ID:Xmagicer,項目名稱:origin,代碼行數:26,代碼來源:etcd.go

示例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
		}
	}
}
開發者ID:2thetop,項目名稱:go,代碼行數:35,代碼來源:ofb_test.go

示例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")
	}
}
開發者ID:lukaszb,項目名稱:goblin,代碼行數:25,代碼來源:describe_test.go

示例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")
	}
}
開發者ID:lukaszb,項目名稱:goblin,代碼行數:25,代碼來源:describe_test.go

示例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
		}
	}
}
開發者ID:Greentor,項目名稱:go,代碼行數:35,代碼來源:ctr_aes_test.go

示例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)
	}

}
開發者ID:jhannah,項目名稱:grim,代碼行數:32,代碼來源:github_archive_test.go

示例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")
	}()
}
開發者ID:balajisiva,項目名稱:netplugin,代碼行數:26,代碼來源:regression_test.go

示例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)
	}
}
開發者ID:edwardoid,項目名稱:couch,代碼行數:35,代碼來源:couch_test.go

示例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.")
	}
}
開發者ID:jmervine,項目名稱:env,代碼行數:34,代碼來源:got_test.go

示例11: TestStorage_create

func TestStorage_create(t *testing.T) {
	_, err := NewStorage("tests.db", true)
	if err != nil {
		t.Failed()
	}

}
開發者ID:ObjectIsAdvantag,項目名稱:answering-machine,代碼行數:7,代碼來源:storage_test.go

示例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.")
	}
}
開發者ID:jmervine,項目名稱:env,代碼行數:35,代碼來源:got_test.go

示例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")
	}
}
開發者ID:lukaszb,項目名稱:goblin,代碼行數:32,代碼來源:it_test.go

示例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)
}
開發者ID:PaddySchmidt,項目名稱:gofem,代碼行數:34,代碼來源:t_bh16_main.go

示例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
}
開發者ID:hayatoshimizuBSKYB,項目名稱:vcap-services,代碼行數:32,代碼來源:iptablesrun_test.go


注:本文中的testing.T.Failed方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。