DATA-DOG / go-sqlmock

Sql mock driver for golang to test database interactions
Other
6.09k stars 408 forks source link

Breaking change in v1.5.1 #330

Closed Gilthoniel closed 9 months ago

Gilthoniel commented 9 months ago

The latest release changes the way arguments are matched which is causing a breaking behavior compared to previous versions.

See https://github.com/DATA-DOG/go-sqlmock/pull/295.

Operating system and Go Version

Ubuntu 22.04 and Go v1.21.1

Issue

Arguments must now always be provided otherwise it does not match anymore.

Reproduction steps

func TestExample(t *testing.T) {
    db, mockDB, err := sqlmock.New()
    require.NoError(t, err)

    mockDB.ExpectExec(`UPDATE "foo" SET "bar" .*`).WillReturnResult(sqlmock.NewResult(0, 1))

    _, err = db.Exec(`UPDATE "foo" SET "bar" = $1`, 42)
    require.NoError(t, err)
}

Expected Result

Instead of introducing a breaking change, the behavior should be enabled explicitly by the developer. Here an error is returned.

Actual Result

It should not return an error.

IvoGoman commented 9 months ago

Opened https://github.com/DATA-DOG/go-sqlmock/pull/329 to make this stricter args checking an opt-in.

razor-1 commented 9 months ago

This change should have only been done in a new major version. Definitely not a patch version.

jcburley commented 9 months ago

Besides doing this, it might be nice to offer .WithAnyArgs() for cases where no matching is desired but the default is, otherwise, to expect arg-matching to be declared.

razor-1 commented 9 months ago

@filikos is this going to be corrected/reverted in some way, or does the community need to create a fork in which patch versions don't incorporate backwards-incompatible changes?

filikos commented 9 months ago

Breaking change fix was merged https://github.com/DATA-DOG/go-sqlmock/pull/329 Thanks for the efforts @IvoGoman The breaking change was not intentional and fatigued by the amount of changes that we're pending to be released. https://github.com/DATA-DOG/go-sqlmock/releases/tag/v1.5.1 Will keep this in mind for upcoming releases.

Release: https://github.com/DATA-DOG/go-sqlmock/releases/tag/v1.5.2