func TestError(t *testing.T) { var nilPtr *int var nilErr error notNilErr := errors.New("Err") i := 5 test.Error(t, test.Equal(1, 1, "apples"), test.NotEqual(1, 2, "oranges"), test.NotNil(&i, "i"), test.Nil(nilPtr, "pointer"), test.Nil(nilErr, "error"), test.NotNil(notNilErr, "error"), ) }
func TestPostJsonUrlIsEmpty(t *testing.T) { ts := startServer(200, `{"field": "value"}`) defer ts.Close() err, _ := (&client.Http{}).PostJson("", nil, nil) test.Error(t, test.NotNil(err, "error"), test.Equal(0, httpCallsCount, "calls to http server"), ) }
func TestGetJsonTargetIsNil(t *testing.T) { ts := startServer(200, `{"field": "value"}`) defer ts.Close() err, _ := (&client.Http{}).GetJson(ts.URL, nil) test.Error(t, test.NotNil(err, "error"), test.Equal(0, httpCallsCount, "calls to http server"), ) }
func TestGetJsonInvalidJson(t *testing.T) { ts := startServer(200, "That's not a json.") defer ts.Close() err, _ := (&client.Http{}).GetJson(ts.URL, &S{}) test.Error(t, test.NotNil(err, "error"), test.Equal(1, httpCallsCount, "calls to http server"), ) }
func TestGetJsonErrorResponse(t *testing.T) { ts := startServer(404, "Not found") defer ts.Close() err, _ := (&client.Http{}).GetJson(ts.URL, &S{}) test.Error(t, test.NotNil(err, "error"), test.Equal(1, httpCallsCount, "calls to http server"), ) }
func ExampleError() { var t = new(testing.T) test.Error(t, //Error message will be: Expected [1] apples but got [6] test.Equal(1, 6, "apples"), //Error message will be: Expected price to be not equal to 2.99 test.NotEqual(2.99, 2.99, "price"), //Error message will be: Expected error to be nil test.Nil(errors.New("ERROR"), "error"), //Error message will be: Expected student name to not be nil test.NotNil(nil, "student name"), ) }
func TestPostJsonErrorResponse(t *testing.T) { ts := startServer(500, `Error response`) defer ts.Close() resp := &S{} s := &S{ Field: "value", } err, code := (&client.Http{}).PostJson(ts.URL, s, resp) test.Error(t, test.NotNil(err, "error"), test.Equal(500, code, "response status code"), test.Equal(1, httpCallsCount, "calls to http server"), ) }