DATA-DOG / go-sqlmock

Sql mock driver for golang to test database interactions
Other
6.05k stars 406 forks source link

Mock aggregate functions #213

Closed lavasudevan closed 4 years ago

lavasudevan commented 4 years ago

trying to run a mock for count() function in sqlite returns "couldnt match acqual sql". Since we are using regex.MatchString in query.go. Any suggestion? Here is the sample program that fails to match the actual sql to reproduce

===== package main

import ( "fmt" "regexp" )

func main() { actual := "select studentId, count() from dept group by studentId" expect := "select studentId, count() from dept group by studentId" re, err := regexp.Compile(expect) if err != nil { fmt.Printf(" err %s \n", err) } if !re.MatchString(actual) { fmt.Printf(` could not match actual sql: "%s" with expected regexp "%s"`, actual, re.String()) } }

lavasudevan commented 4 years ago

never mind. I figured out to use sqlmock.QueryMatcherEqual in sqlmock.New

ziranl16 commented 3 years ago

Hi, I wonder if there is any ways to support COUNT(DISTINCT(column)) using the default sqlmock.QueryMatcherRegexp ?