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


Golang T.Errorf方法代码示例

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


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

示例1: TestEventerOnce

func TestEventerOnce(t *testing.T) {
	e := NewEventer()
	e.AddEvent("test")

	sem := make(chan bool)
	e.Once("test", func(data interface{}) {
		sem <- true
	})

	go func() {
		e.Publish("test", true)
	}()

	select {
	case <-sem:
	case <-time.After(10 * time.Millisecond):
		t.Errorf("Once was not called")
	}

	go func() {
		e.Publish("test", true)
	}()

	select {
	case <-sem:
		t.Errorf("Once was called twice")
	case <-time.After(10 * time.Millisecond):
	}
}
开发者ID:ympons,项目名称:gobot,代码行数:29,代码来源:eventer_test.go

示例2: TestDumper

func TestDumper(t *testing.T) {
	var in [40]byte
	for i := range in {
		in[i] = byte(i + 30)
	}

	for stride := 1; stride < len(in); stride++ {
		var out bytes.Buffer
		dumper := Dumper(&out)
		done := 0
		for done < len(in) {
			todo := done + stride
			if todo > len(in) {
				todo = len(in)
			}
			dumper.Write(in[done:todo])
			done = todo
		}

		dumper.Close()
		if !bytes.Equal(out.Bytes(), expectedHexDump) {
			t.Errorf("stride: %d failed. got:\n%s\nwant:\n%s", stride, out.Bytes(), expectedHexDump)
		}
	}
}
开发者ID:anuvazhayil,项目名称:HelloWorld_32bitOS,代码行数:25,代码来源:hex_test.go

示例3: TestValidateResponse

func TestValidateResponse(t *testing.T) {
	valid := &http.Response{
		Request:    &http.Request{},
		StatusCode: http.StatusOK,
		Body:       ioutil.NopCloser(strings.NewReader("OK")),
	}

	if err := validateResponse(valid); err != nil {
		t.Errorf("ValidateResponse with valid response returned error %+v", err)
	}

	invalid := &http.Response{
		Request:    &http.Request{},
		StatusCode: http.StatusBadRequest,
		Body: ioutil.NopCloser(strings.NewReader(`{
			"error" : {
				"statuscode": 400,
				"statusdesc": "Bad Request",
				"errormessage": "This is an error"
			}
		}`)),
	}

	want := &PingdomError{400, "Bad Request", "This is an error"}
	if err := validateResponse(invalid); !reflect.DeepEqual(err, want) {
		t.Errorf("ValidateResponse with invalid response returned %+v, want %+v", err, want)
	}

}
开发者ID:russellcardullo,项目名称:go-pingdom,代码行数:29,代码来源:pingdom_test.go

示例4: TestOverloadWithNoArgsOverloadsDotEnv

func TestOverloadWithNoArgsOverloadsDotEnv(t *testing.T) {
	err := Overload()
	pathError := err.(*os.PathError)
	if pathError == nil || pathError.Op != "open" || pathError.Path != ".env" {
		t.Errorf("Didn't try and open .env by default")
	}
}
开发者ID:ansel1,项目名称:godotenv,代码行数:7,代码来源:godotenv_test.go

示例5: TestConnQueryEncoder

func TestConnQueryEncoder(t *testing.T) {
	t.Parallel()

	conn := mustConnect(t, *defaultConnConfig)
	defer closeConn(t, conn)

	n := pgx.NullInt64{Int64: 1, Valid: true}

	rows, err := conn.Query("select $1::int8", &n)
	if err != nil {
		t.Fatalf("conn.Query failed: ", err)
	}

	ok := rows.Next()
	if !ok {
		t.Fatal("rows.Next terminated early")
	}

	var m pgx.NullInt64
	err = rows.Scan(&m)
	if err != nil {
		t.Fatalf("rows.Scan failed: ", err)
	}
	rows.Close()

	if !m.Valid {
		t.Error("m should be valid, but it wasn't")
	}

	if m.Int64 != 1 {
		t.Errorf("m.Int64 should have been 1, but it was %v", m.Int64)
	}

	ensureConnValid(t, conn)
}
开发者ID:benbjohnson,项目名称:flannel,代码行数:35,代码来源:query_test.go

示例6: TestServerURLNoListener

func TestServerURLNoListener(t *testing.T) {
	server := DockerServer{}
	url := server.URL()
	if url != "" {
		t.Errorf("DockerServer.URL(): Expected empty URL on handler mode, got %q.", url)
	}
}
开发者ID:jigish,项目名称:go-dockerclient,代码行数:7,代码来源:server_test.go

示例7: expectEventPid

func expectEventPid(t *testing.T, name string, expect int, pid int) bool {
	if expect != pid {
		t.Errorf("Expected %s pid=%d, received=%d", name, expect, pid)
		return false
	}
	return true
}
开发者ID:BarthV,项目名称:gosigar,代码行数:7,代码来源:psnotify_test.go

示例8: TestMatchFn

func TestMatchFn(t *testing.T) {
	tests := []matchTest{
		matchTest{
			[]OpCode{PUSH1, PUSH1, MSTORE, JUMP},
			[]OpCode{PUSH1, MSTORE},
			1,
		},
		matchTest{
			[]OpCode{PUSH1, PUSH1, MSTORE, JUMP},
			[]OpCode{PUSH1, MSTORE, PUSH1},
			0,
		},
		matchTest{
			[]OpCode{},
			[]OpCode{PUSH1},
			0,
		},
	}

	for i, test := range tests {
		var matchCount int
		MatchFn(test.input, test.match, func(i int) bool {
			matchCount++
			return true
		})
		if matchCount != test.matches {
			t.Errorf("match count failed on test[%d]: expected %d matches, got %d", i, test.matches, matchCount)
		}
	}
}
开发者ID:j4ustin,项目名称:go-ethereum,代码行数:30,代码来源:jit_util_test.go

示例9: TestIsRequestPresignedSignatureV4

// TestIsRequestPresignedSignatureV4 - Test validates the logic for presign signature verision v4 detection.
func TestIsRequestPresignedSignatureV4(t *testing.T) {
	testCases := []struct {
		inputQueryKey   string
		inputQueryValue string
		expectedResult  bool
	}{
		// Test case - 1.
		// Test case with query key ""X-Amz-Credential" set.
		{"", "", false},
		// Test case - 2.
		{"X-Amz-Credential", "", true},
		// Test case - 3.
		{"X-Amz-Content-Sha256", "", false},
	}

	for i, testCase := range testCases {
		// creating an input HTTP request.
		// Only the query parameters are relevant for this particular test.
		inputReq, err := http.NewRequest("GET", "http://example.com", nil)
		if err != nil {
			t.Fatalf("Error initializing input HTTP request: %v", err)
		}
		q := inputReq.URL.Query()
		q.Add(testCase.inputQueryKey, testCase.inputQueryValue)
		inputReq.URL.RawQuery = q.Encode()

		actualResult := isRequestPresignedSignatureV4(inputReq)
		if testCase.expectedResult != actualResult {
			t.Errorf("Test %d: Expected the result to `%v`, but instead got `%v`", i+1, testCase.expectedResult, actualResult)
		}
	}
}
开发者ID:hackintoshrao,项目名称:minio,代码行数:33,代码来源:auth-handler_test.go

示例10: TestCreateExecContainer

func TestCreateExecContainer(t *testing.T) {
	server := DockerServer{}
	addContainers(&server, 2)
	server.buildMuxer()
	recorder := httptest.NewRecorder()
	body := `{"Cmd": ["bash", "-c", "ls"]}`
	path := fmt.Sprintf("/containers/%s/exec", server.containers[0].ID)
	request, _ := http.NewRequest("POST", path, strings.NewReader(body))
	server.ServeHTTP(recorder, request)
	if recorder.Code != http.StatusOK {
		t.Fatalf("CreateExec: wrong status. Want %d. Got %d.", http.StatusOK, recorder.Code)
	}
	serverExec := server.execs[0]
	var got docker.Exec
	err := json.NewDecoder(recorder.Body).Decode(&got)
	if err != nil {
		t.Fatal(err)
	}
	if got.ID != serverExec.ID {
		t.Errorf("CreateExec: wrong value. Want %#v. Got %#v.", serverExec.ID, got.ID)
	}
	expected := docker.ExecInspect{
		ID: got.ID,
		ProcessConfig: docker.ExecProcessConfig{
			EntryPoint: "bash",
			Arguments:  []string{"-c", "ls"},
		},
		Container: *server.containers[0],
	}
	if !reflect.DeepEqual(*serverExec, expected) {
		t.Errorf("InspectContainer: wrong value. Want:\n%#v\nGot:\n%#v\n", expected, *serverExec)
	}
}
开发者ID:jgatkinsn,项目名称:os,代码行数:33,代码来源:server_test.go

示例11: Validate

func (c *testClient) Validate(t *testing.T, received runtime.Object, err error) {
	c.ValidateCommon(t, err)

	if c.Response.Body != nil && !api.Semantic.DeepDerivative(c.Response.Body, received) {
		t.Errorf("bad response for request %#v: expected %#v, got %#v", c.Request, c.Response.Body, received)
	}
}
开发者ID:Juniper,项目名称:kubernetes,代码行数:7,代码来源:client_test.go

示例12: TestGetServerVersion

func TestGetServerVersion(t *testing.T) {
	expect := version.Info{
		Major:     "foo",
		Minor:     "bar",
		GitCommit: "baz",
	}
	server := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, req *http.Request) {
		output, err := json.Marshal(expect)
		if err != nil {
			t.Errorf("unexpected encoding error: %v", err)
			return
		}
		w.Header().Set("Content-Type", "application/json")
		w.WriteHeader(http.StatusOK)
		w.Write(output)
	}))
	client := NewOrDie(&Config{Host: server.URL})

	got, err := client.ServerVersion()
	if err != nil {
		t.Fatalf("unexpected encoding error: %v", err)
	}
	if e, a := expect, *got; !reflect.DeepEqual(e, a) {
		t.Errorf("expected %v, got %v", e, a)
	}
}
开发者ID:Juniper,项目名称:kubernetes,代码行数:26,代码来源:client_test.go

示例13: ValidateRaw

func (c *testClient) ValidateRaw(t *testing.T, received []byte, err error) {
	c.ValidateCommon(t, err)

	if c.Response.Body != nil && !reflect.DeepEqual(c.Response.Body, received) {
		t.Errorf("bad response for request %#v: expected %#v, got %#v", c.Request, c.Response.Body, received)
	}
}
开发者ID:Juniper,项目名称:kubernetes,代码行数:7,代码来源:client_test.go

示例14: TestTaskHashEqual

func TestTaskHashEqual(t *testing.T) {
	tp1 := new(TestMethodState)
	tp2 := new(TestMethodState)

	// Test that the same hash is generated for methods on values and pointers
	// who share equal state and parameters

	equalState := "SOME STATE"
	equalParam1 := "SOME PARAM"
	equalParam2 := "SOME"

	tp1.State = equalState
	tp2.State = equalState

	hash1, err := HashTask(tp1, "MethodOnPointer", []interface{}{equalParam1, equalParam2})
	hash2, err := HashTask(tp2, "MethodOnPointer", []interface{}{equalParam1, equalParam2})

	if err != nil {
		t.Errorf("Failed to generate hashes \n")
	}

	if hash1 != hash2 {
		t.Errorf("Hashes %s and %s don't match \n", hash1, hash2)
	}
}
开发者ID:kzvezdarov,项目名称:alexander,代码行数:25,代码来源:util_test.go

示例15: TestRedundantFuncs

func TestRedundantFuncs(t *testing.T) {
	inputs := []interface{}{
		"\x00\x01\x02\x03\x04\x05\x06\x07\x08\t\n\x0b\x0c\r\x0e\x0f" +
			"\x10\x11\x12\x13\x14\x15\x16\x17\x18\x19\x1a\x1b\x1c\x1d\x1e\x1f" +
			` !"#$%&'()*+,-./` +
			`0123456789:;<=>?` +
			`@ABCDEFGHIJKLMNO` +
			`PQRSTUVWXYZ[\]^_` +
			"`abcdefghijklmno" +
			"pqrstuvwxyz{|}~\x7f" +
			"\u00A0\u0100\u2028\u2029\ufeff\ufdec\ufffd\uffff\U0001D11E" +
			"&amp;%22\\",
		CSS(`a[href =~ "//example.com"]#foo`),
		HTML(`Hello, <b>World</b> &amp;tc!`),
		HTMLAttr(` dir="ltr"`),
		JS(`c && alert("Hello, World!");`),
		JSStr(`Hello, World & O'Reilly\x21`),
		URL(`greeting=H%69&addressee=(World)`),
	}

	for n0, m := range redundantFuncs {
		f0 := funcMap[n0].(func(...interface{}) string)
		for n1 := range m {
			f1 := funcMap[n1].(func(...interface{}) string)
			for _, input := range inputs {
				want := f0(input)
				if got := f1(want); want != got {
					t.Errorf("%s %s with %T %q: want\n\t%q,\ngot\n\t%q", n0, n1, input, input, want, got)
				}
			}
		}
	}
}
开发者ID:bibbyflyaway,项目名称:go,代码行数:33,代码来源:escape_test.go


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