Exemple #1
0
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"),
	)
}
Exemple #2
0
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"),
	)
}
Exemple #3
0
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"),
	)
}
Exemple #4
0
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"),
	)
}
Exemple #5
0
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"),
	)
}
Exemple #6
0
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"),
	)
}
Exemple #7
0
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"),
	)
}