Skip to content

Is it possible to throw all expectations were already fulfilled error only on mock.ExpectationsWereMet() call? #251

@JanPetr

Description

@JanPetr

Hello there! I have rather question than an issue. I have code similar to this one:

func (a *Smt) Bar() (string, error) {
    f, err := a.foo(id)
    if err != nil {
	    originalErr := err
    
	    err = a.DB.UpdateError(id, "operation foo failed")
	    if err != nil {
		    return "", fmt.Errorf("update err: %w", err)
	    }
    
	    return "", fmt.Errorf("foo: %w", originalErr)
    }
    // ...
}

I'd like to test that if the foo fails, the DB update passes correctly and I get an error from Bar() method.

However, if I don't specify mock.ExpectExec for the err = a.DB.UpdateError(id, "operation foo failed") line I get error all expectations were already fulfilled thrown by return "", fmt.Errorf("update err: %w", err) line. Considering that my test is correctly expecting error thrown by return "", fmt.Errorf("foo: %w", originalErr) line I get a false positive test pass.

Is it possible to configure sqlmock to not to throw error on performing unexpected query and then return error on mock.ExpectationsWereMet() call saying there was an unexpected query performed?

Thank you and thanks for all your work!

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions