本文整理汇总了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):
}
}
示例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)
}
}
}
示例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)
}
}
示例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")
}
}
示例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)
}
示例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)
}
}
示例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
}
示例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)
}
}
}
示例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)
}
}
}
示例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)
}
}
示例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)
}
}
示例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)
}
}
示例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)
}
}
示例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)
}
}
示例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" +
"&%22\\",
CSS(`a[href =~ "//example.com"]#foo`),
HTML(`Hello, <b>World</b> &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)
}
}
}
}
}