Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

ExpectePrepare does not work as documented #50

Closed
luistm opened this issue Nov 2, 2016 · 2 comments
Closed

ExpectePrepare does not work as documented #50

luistm opened this issue Nov 2, 2016 · 2 comments

Comments

@luistm
Copy link

luistm commented Nov 2, 2016

Hi everyone!
First, thanks for the excellent work with sqlmock.

I'm writing some test code with the help of go sqlmock.

The following code does not validates if the prepared statement has the correct query.

// main.go
package main

import "database/sql"

func testFunction(db *sql.DB) {
	db.Prepare("SELECT")
}

func main() {}
// main_test.go
package main

import (
	"testing"

	"github.com/stretchr/testify/assert"
	sqlmock "gopkg.in/DATA-DOG/go-sqlmock.v1"
)

func TestPrepare(t *testing.T) {
	db, mock, mErr := sqlmock.New()
	assert.NoError(t, mErr)
	defer db.Close()

	mock.ExpectPrepare("^BADSELECT$")

	testFunction(db)

	if err := mock.ExpectationsWereMet(); err != nil {
		t.Errorf("there were unfulfilled expections: %s", err)
	}

}

As far as i know, the test should fail, but it does't. What i'm i doing wrong?
I'm using GO 1.7/macOS 10.12.1.

Thanks

@l3pp4rd
Copy link
Member

l3pp4rd commented Nov 2, 2016

Hi, yes indeed, for some reason it was not validating the sql query on prepare. looks like everyone was using that statement for Exec or Query and that was validating it.

@l3pp4rd l3pp4rd closed this as completed in d4cd2ca Nov 2, 2016
@l3pp4rd
Copy link
Member

l3pp4rd commented Nov 2, 2016

thanks for reporting it ;)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants