예제 #1
0
// NotError asserts err is not MySql error.
// Applicable only to github.com/ziutek/mymysql/mysql package.
func NotError(t assert.Tester, err error, args ...interface{}) {
	nesting, failFast, errorMsg := assert.DecodeArgs(args...)
	fn := func() {
		t.Errorf("Did not expect MySQL error: %s", err.Error())
		if len(errorMsg) > 0 {
			t.Error("!", " -", errorMsg)
		}
	}
	_, ok := err.(*mysql.Error)
	assert.Assert(t, !ok, nesting, failFast, fn)
}
예제 #2
0
// Error asserts err is MySql error.
// Applicable only to github.com/ziutek/mymysql/mysql package.
func Error(t assert.Tester, err error, args ...interface{}) {
	nesting, failFast, errorMsg := assert.DecodeArgs(args...)
	fn := func() {
		t.Error("Expected MySQL error.")
		if len(errorMsg) > 0 {
			t.Error("!", " -", errorMsg)
		}
	}
	_, ok := err.(*mysql.Error)
	assert.Assert(t, ok, nesting+1, failFast, fn)
}
예제 #3
0
// ErrorCode asserts err is *mysql.Error and has code.
// Applicable only to github.com/ziutek/mymysql/mysql package.
func ErrorCode(t assert.Tester, err error, errorCode uint16) {
	assert.Error(t, err, assert.NESTING_2, assert.FAIL_SLOW, "Expected error but got nil.")

	merr := GetMySqlErorr(err)
	fn := func() {
		t.Error("Expected MySQL error but got some other error.")
		if err == nil {
			t.Errorf("Got error: nil")
		} else {
			t.Errorf("Got error: %s", err.Error())
		}
	}
	_, ok := err.(*mysql.Error)
	assert.Assert(t, ok, assert.NESTING_2, assert.FAIL_FAST, fn)
	assert.Equal(t, errorCode, merr.Code, assert.NESTING_2, "Expected error code %d got %d.", errorCode, merr.Code)
}