Example #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"),
	)
}
Example #2
0
func TestPostJsonBodyIsNil(t *testing.T) {
	ts := startServer(200, `{"field": "value"}`)
	defer ts.Close()

	resp := &S{}
	err, _ := (&client.Http{}).PostJson(ts.URL, nil, resp)
	test.Error(t,
		test.Nil(err, "error"),
		test.Equal(1, httpCallsCount, "calls to http server"),
		test.Equal("value", resp.Field, "response"),
	)
}
Example #3
0
func TestPostJsonResponseIsNil(t *testing.T) {
	ts := startServer(200, ``)
	defer ts.Close()

	s := &S{
		Field: "value",
	}
	err, _ := (&client.Http{}).PostJson(ts.URL, s, nil)
	test.Error(t,
		test.Nil(err, "error"),
		test.Equal(1, httpCallsCount, "calls to http server"),
	)
}
Example #4
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"),
	)
}
Example #5
0
func TestGetJson(t *testing.T) {
	ts := startServer(200, `{"field": "value"}`)
	defer ts.Close()

	s := &S{}
	err, code := (&client.Http{}).GetJson(ts.URL, s)

	test.Error(t,
		test.Nil(err, "error"),
		test.Equal(1, httpCallsCount, "calls to http server"),
		test.Equal(200, code, "code"),
		test.Equal("value", s.Field, "response"),
	)
}