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


Golang T.FailNow方法代码示例

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


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

示例1: compareFiles

func compareFiles(t *testing.T, expectedFN string, actualFN string) {
	var expectedBytes []byte
	var actualBytes []byte
	var err error

	expectedBytes, err = ioutil.ReadFile(expectedFN)
	if err != nil {
		t.Logf("Failed to open for compare: %s\n", err.Error())
		t.Fail()
		return
	}

	actualBytes, err = ioutil.ReadFile(actualFN)
	if err != nil {
		t.Logf("Failed to open for compare: %s\n", err.Error())
		t.FailNow()
		return
	}

	if len(expectedBytes) != len(actualBytes) {
		t.Logf("%s and %s differ in size\n", expectedFN, actualFN)
		t.Fail()
		return
	}

	if 0 != bytes.Compare(actualBytes, expectedBytes) {
		t.Logf("%s and %s differ\n", expectedFN, actualFN)
		t.Fail()
		return
	}
}
开发者ID:jsummers,项目名称:gobmp,代码行数:31,代码来源:gobmp_test.go

示例2: TestSecureSecretoxKey

func TestSecureSecretoxKey(t *testing.T) {
	key1, ok := secretbox.GenerateKey()
	if !ok {
		fmt.Println("pwkey: failed to generate test key")
		t.FailNow()
	}

	skey, ok := SecureSecretboxKey(testPass, key1)
	if !ok {
		fmt.Println("pwkey: failed to secure secretbox key")
		t.FailNow()
	}

	key, ok := RecoverSecretboxKey(testPass, skey)
	if !ok {
		fmt.Println("pwkey: failed to recover box private key")
		t.FailNow()
	}

	if !bytes.Equal(key[:], key1[:]) {
		fmt.Println("pwkey: recovered  key doesn't match original")
		t.FailNow()
	}

	if _, ok = RecoverBoxKey([]byte("Password"), skey); ok {
		fmt.Println("pwkey: recover should fail with bad password")
		t.FailNow()
	}
}
开发者ID:postfix,项目名称:cryptobox-ng,代码行数:29,代码来源:pwkey_test.go

示例3: TestVersion

func TestVersion(t *testing.T) {
	v := new(Version)
	v.Version = uint16(1)
	v.Timestamp = time.Unix(0, 0)
	v.IpAddress = net.ParseIP("1.2.3.4")
	v.Port = uint16(4444)
	v.UserAgent = "Hello World!"

	verBytes := v.GetBytes()
	if len(verBytes) != verLen+12 {
		fmt.Println("Incorrect Byte Length: ", verBytes)
		t.Fail()
	}

	v2 := new(Version)
	err := v2.FromBytes(verBytes)
	if err != nil {
		fmt.Println("Error Decoding: ", err)
		t.FailNow()
	}

	if v2.Version != 1 || v2.Timestamp != time.Unix(0, 0) || v2.IpAddress.String() != "1.2.3.4" || v2.Port != 4444 || v2.UserAgent != "Hello World!" {
		fmt.Println("Incorrect decoded version: ", v2)
		t.Fail()
	}
}
开发者ID:msecret,项目名称:emp,代码行数:26,代码来源:objects_test.go

示例4: TestDockerCommandBuildCancel

func TestDockerCommandBuildCancel(t *testing.T) {
	if helpers.SkipIntegrationTests(t, "docker", "info") {
		return
	}

	build := &common.Build{
		GetBuildResponse: common.LongRunningBuild,
		Runner: &common.RunnerConfig{
			RunnerSettings: common.RunnerSettings{
				Executor: "docker",
				Docker: &common.DockerConfig{
					Image: "alpine",
				},
			},
		},
	}

	trace := &common.Trace{Writer: os.Stdout, Abort: make(chan interface{}, 1)}

	abortTimer := time.AfterFunc(time.Second, func() {
		t.Log("Interrupt")
		trace.Abort <- true
	})
	defer abortTimer.Stop()

	timeoutTimer := time.AfterFunc(time.Minute, func() {
		t.Log("Timedout")
		t.FailNow()
	})
	defer timeoutTimer.Stop()

	err := build.Run(&common.Config{}, trace)
	assert.IsType(t, err, &common.BuildError{})
	assert.EqualError(t, err, "canceled")
}
开发者ID:bssthu,项目名称:gitlab-ci-multi-runner,代码行数:35,代码来源:executor_docker_command_test.go

示例5: TestQueue_EvenNumberOfPushesAndPops_GivesZeroFinalLength

func TestQueue_EvenNumberOfPushesAndPops_GivesZeroFinalLength(t *testing.T) {
	underTest := NewQueue("Test")
	numberOfRounds := 200

	for i := 0; i < numberOfRounds; i++ {
		dummyMessagePayLoad := []byte{byte(i)}
		dummyMessage := message.NewHeaderlessMessage(&dummyMessagePayLoad)
		underTest.InputChannel <- dummyMessage
	}

	gomega.Eventually(func() int {
		return underTest.length
	}).Should(gomega.Equal(numberOfRounds))

	for i := 0; i < numberOfRounds; i++ {
		message := <-underTest.OutputChannel
		if int((*message.Body)[0]) != i {
			t.Logf("Expected %d, got %d", i, int((*message.Body)[0]))
			t.FailNow()
		}
	}

	gomega.Eventually(func() int {
		return underTest.length
	}).Should(gomega.Equal(0))
}
开发者ID:FireEater64,项目名称:gamq,代码行数:26,代码来源:queue_test.go

示例6: TestSharedKey

// Validate the ECDH component.
func TestSharedKey(t *testing.T) {
	prv1, err := GenerateKey(rand.Reader, DefaultCurve, nil)
	if err != nil {
		fmt.Println(err.Error())
		t.FailNow()
	}
	skLen = MaxSharedKeyLength(&prv1.PublicKey) / 2

	prv2, err := GenerateKey(rand.Reader, DefaultCurve, nil)
	if err != nil {
		fmt.Println(err.Error())
		t.FailNow()
	}

	sk1, err := prv1.GenerateShared(&prv2.PublicKey, skLen, skLen)
	if err != nil {
		fmt.Println(err.Error())
		t.FailNow()
	}

	sk2, err := prv2.GenerateShared(&prv1.PublicKey, skLen, skLen)
	if err != nil {
		fmt.Println(err.Error())
		t.FailNow()
	}

	if !bytes.Equal(sk1, sk2) {
		fmt.Println(ErrBadSharedKeys.Error())
		t.FailNow()
	}
}
开发者ID:CedarLogic,项目名称:go-ethereum,代码行数:32,代码来源:ecies_test.go

示例7: TestListen_available1

func TestListen_available1(t *testing.T) {
	pm := newPortManager(portLow, portLow)

	l1, err := pm.listen()
	if err != nil {
		t.Fatal(err)
	}
	if l1.port() != portLow {
		t.Logf("Expected port %d, got port %d", portLow, l1.port())
		l1.Close()
		t.FailNow()
	}

	l2, err := pm.listen()
	if err == nil {
		l1.Close()
		l2.Close()
		t.Fatal("Expected error when too many ports opened")
	}

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

	l3, err := pm.listen()
	if err != nil {
		t.Fatal(err)
	}
	if l3.port() != portLow {
		t.Logf("Expected port %d, got port %d", portLow, l3.port())
	}
	l3.Close()
}
开发者ID:jacobmarble,项目名称:cloud-print-connector,代码行数:34,代码来源:portmanager_test.go

示例8: Test_BrHtmlTag

func Test_BrHtmlTag(t *testing.T) {
	tests := testutils.ConversionTests{
		{
			In: `a<br/>
			b<br/>
			c`,
			Want: `a \\ 
			b \\ 
			c`,
		},
		{
			In: `a<br>
			b<br>
			c`,
			Want: `a \\ 
			b \\ 
			c`,
		},
	}

	for _, test := range tests {
		got := BrHtmlTagToLatexLinebreak(test.In)
		if !reflect.DeepEqual(test.Want, got) {
			_, file, line, _ := runtime.Caller(0)
			fmt.Printf("%s:%d:\n\ncall BrHtmlTag(%#v)\n\texp: %#v\n\n\tgot: %#v\n\n",
				filepath.Base(file), line, test.In, test.Want, got)
			t.FailNow()
		}
	}
	testutils.Cleanup()

}
开发者ID:frankMilde,项目名称:rol,代码行数:32,代码来源:strtrans_test.go

示例9: TestSymbolTable

func TestSymbolTable(t *testing.T) {
	o := vm.NewObject()
	o.AddSymbol("foo", vm.DATA, uint16(0xabcd))
	o.AddSymbol("bar", vm.TEXT, uint16(0x1234))

	b := o.SymTab.Bytes()
	expect := []byte{
		0xab, 0xcd, byte(vm.DATA), 0x3, 'f', 'o', 'o',
		0x12, 0x34, byte(vm.TEXT), 0x3, 'b', 'a', 'r',
	}

	if !bytes.Equal(b, expect) {
		t.Log("expected:", expect, "got:", b)
		t.FailNow()
	}

	o2 := vm.NewObject()
	o2.ScanSymbolTable(b)
	for i, s := range o2.SymTab {
		if s != o.SymTab[i] {
			t.Log("expected:", o.SymTab, "got:", o2.SymTab)
			t.FailNow()
		}
	}
}
开发者ID:rthornton128,项目名称:vm,代码行数:25,代码来源:obj_test.go

示例10: TestLinkNew

func TestLinkNew(t *testing.T) {
	ports := make(nat.PortSet)
	ports[nat.Port("6379/tcp")] = struct{}{}

	link, err := NewLink("172.0.17.3", "172.0.17.2", "/db/docker", nil, ports, nil)
	if err != nil {
		t.Fatal(err)
	}

	if link == nil {
		t.FailNow()
	}
	if link.Name != "/db/docker" {
		t.Fail()
	}
	if link.Alias() != "docker" {
		t.Fail()
	}
	if link.ParentIP != "172.0.17.3" {
		t.Fail()
	}
	if link.ChildIP != "172.0.17.2" {
		t.Fail()
	}
	for _, p := range link.Ports {
		if p != nat.Port("6379/tcp") {
			t.Fail()
		}
	}
}
开发者ID:Gandi,项目名称:docker,代码行数:30,代码来源:links_test.go

示例11: TestLinkNaming

func TestLinkNaming(t *testing.T) {
	ports := make(nat.PortSet)
	ports[nat.Port("6379/tcp")] = struct{}{}

	link, err := NewLink("172.0.17.3", "172.0.17.2", "/db/docker-1", nil, ports, nil)
	if err != nil {
		t.Fatal(err)
	}

	rawEnv := link.ToEnv()
	env := make(map[string]string, len(rawEnv))
	for _, e := range rawEnv {
		parts := strings.Split(e, "=")
		if len(parts) != 2 {
			t.FailNow()
		}
		env[parts[0]] = parts[1]
	}

	value, ok := env["DOCKER_1_PORT"]

	if !ok {
		t.Fatalf("DOCKER_1_PORT not found in env")
	}

	if value != "tcp://172.0.17.2:6379" {
		t.Fatalf("Expected 172.0.17.2:6379, got %s", env["DOCKER_1_PORT"])
	}
}
开发者ID:Gandi,项目名称:docker,代码行数:29,代码来源:links_test.go

示例12: RequestOneAttempt

// RequestOneAttempt gets a single attempt from the test's worker, or
// fails the test immediately if not exactly one attempt was returned.
func (sts *SimpleTestSetup) RequestOneAttempt(t *testing.T) coordinate.Attempt {
	attempts, err := sts.Worker.RequestAttempts(coordinate.AttemptRequest{})
	if !(assert.NoError(t, err) && assert.Len(t, attempts, 1)) {
		t.FailNow()
	}
	return attempts[0]
}
开发者ID:diffeo,项目名称:go-coordinate,代码行数:9,代码来源:helpers.go

示例13: TestServer

func TestServer(t *testing.T) {
	out := make(chan *Message)
	svr, err := NewServer(":7686", out)
	if err != nil {
		t.Log(err)
		t.FailNow()
		return
	}
	lis := Lis{svr, t}
	svr.Run()
	for !stop {
		select {
		case msg := <-out:
			switch msg.Type {
			case Type_connect:
				lis.OnConnect(msg.Id)
			case Type_message:
				lis.OnMessage(msg.Id, msg.Data)
			case Type_close:
				lis.OnClose(msg.Id, msg.Err)
			default:
				println("UNKONW MESSAGE", msg)
			}
		}
	}
	fmt.Println(stop)
	svr.Close()
	svr.Wait()
}
开发者ID:wodconf,项目名称:go_svr_test,代码行数:29,代码来源:server_test.go

示例14: parseProfile

func parseProfile(t *testing.T, bytes []byte, f func(uintptr, []uintptr)) {
	// Convert []byte to []uintptr.
	l := len(bytes) / int(unsafe.Sizeof(uintptr(0)))
	val := *(*[]uintptr)(unsafe.Pointer(&bytes))
	val = val[:l]

	// 5 for the header, 2 for the per-sample header on at least one sample, 3 for the trailer.
	if l < 5+2+3 {
		t.Logf("profile too short: %#x", val)
		if badOS[runtime.GOOS] {
			t.Skipf("ignoring failure on %s; see golang.org/issue/6047", runtime.GOOS)
			return
		}
		t.FailNow()
	}

	hd, val, tl := val[:5], val[5:l-3], val[l-3:]
	if hd[0] != 0 || hd[1] != 3 || hd[2] != 0 || hd[3] != 1e6/100 || hd[4] != 0 {
		t.Fatalf("unexpected header %#x", hd)
	}

	if tl[0] != 0 || tl[1] != 1 || tl[2] != 0 {
		t.Fatalf("malformed end-of-data marker %#x", tl)
	}

	for len(val) > 0 {
		if len(val) < 2 || val[0] < 1 || val[1] < 1 || uintptr(len(val)) < 2+val[1] {
			t.Fatalf("malformed profile.  leftover: %#x", val)
		}
		f(val[0], val[2:2+val[1]])
		val = val[2+val[1]:]
	}
}
开发者ID:amitarya,项目名称:gcc,代码行数:33,代码来源:pprof_test.go

示例15: TestSectionTable

func TestSectionTable(t *testing.T) {
	st := vm.SectionTable{
		vm.TEXT: []byte{0x1, 0x2, 0x3, 0x4, 0x5},
		vm.DATA: []byte{0xa, 0xb, 0xc, 0xd, 0xe, 0xf},
	}
	b := st.Bytes()
	expect := []byte{0x2,
		byte(vm.TEXT), 0x0, 0xb, 0x0, 0x5,
		byte(vm.DATA), 0x0, 0x10, 0x0, 0x6,
		0x1, 0x2, 0x3, 0x4, 0x5,
		0xa, 0xb, 0xc, 0xd, 0xe, 0xf,
	}
	if !bytes.Equal(b, expect) {
		t.Log("expected:", expect, "got:", b)
		t.FailNow()
	}

	o := vm.NewObject()
	o.ScanSectionTable(b)
	for i, sec := range o.SecTab {
		if !bytes.Equal(st[i], sec) {
			t.Log("expected:", st[i], "got:", sec)
			t.FailNow()
		}
	}
}
开发者ID:rthornton128,项目名称:vm,代码行数:26,代码来源:obj_test.go


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