go-sqlmock icon indicating copy to clipboard operation
go-sqlmock copied to clipboard

test a call to a procedure

Open kowiste opened this issue 1 year ago • 0 comments
trafficstars

I have to test one function where there is a call to a procedure like this

	if err = DB.WithContext(ctx).Raw("call x_get_number_by_id( ?)", id).Scan(&n).Error; err != nil {
		return n, err
	}

in the test i'm trying this

mockDB.ExpectExec("call x_get_number_by_id( ?)").WithArgs(2).WillReturnError(errors.New("test"))

and I have this error

2023/11/23 09:45:45 number.go:96 call to Query 'call x_get_number_by_id( ?)' with args [{Name: Ordinal:1 Value:2}], was not expected, next expectation is: ExpectedExec => expecting Exec or ExecContext which:
  - matches sql: 'call x_get_number_by_id( ?)'
  - is with arguments:
    0 - 2
  - should return error: 
[0.123ms] [rows:-] call x_get_number_by_id( 2)

There is not any other previous call to a database

kowiste avatar Nov 23 '23 09:11 kowiste