You've already forked go-sqlxmock
							
							
				mirror of
				https://github.com/zhashkevych/go-sqlxmock.git
				synced 2025-10-30 23:27:38 +02:00 
			
		
		
		
	add AnyArg func to provide any kind of argument matcher
This commit is contained in:
		| @@ -188,7 +188,8 @@ It only asserts that argument is of `time.Time` type. | ||||
|  | ||||
| ## Changes | ||||
|  | ||||
|  | ||||
| - **2016-02-23** - added **sqlmock.AnyArg()** function to provide any kind | ||||
|   of argument matcher. | ||||
| - **2016-02-23** - convert expected arguments to driver.Value as natural | ||||
|   driver does, the change may affect time.Time comparison and will be | ||||
|   stricter. See [issue](https://github.com/DATA-DOG/go-sqlmock/issues/31). | ||||
|   | ||||
							
								
								
									
										24
									
								
								argument.go
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										24
									
								
								argument.go
									
									
									
									
									
										Normal file
									
								
							| @@ -0,0 +1,24 @@ | ||||
| package sqlmock | ||||
|  | ||||
| import "database/sql/driver" | ||||
|  | ||||
| // Argument interface allows to match | ||||
| // any argument in specific way when used with | ||||
| // ExpectedQuery and ExpectedExec expectations. | ||||
| type Argument interface { | ||||
| 	Match(driver.Value) bool | ||||
| } | ||||
|  | ||||
| // AnyArg will return an Argument which can | ||||
| // match any kind of arguments. | ||||
| // | ||||
| // Useful for time.Time or similar kinds of arguments. | ||||
| func AnyArg() Argument { | ||||
| 	return anyArgument{} | ||||
| } | ||||
|  | ||||
| type anyArgument struct{} | ||||
|  | ||||
| func (a anyArgument) Match(_ driver.Value) bool { | ||||
| 	return true | ||||
| } | ||||
| @@ -8,13 +8,6 @@ import ( | ||||
| 	"sync" | ||||
| ) | ||||
|  | ||||
| // Argument interface allows to match | ||||
| // any argument in specific way when used with | ||||
| // ExpectedQuery and ExpectedExec expectations. | ||||
| type Argument interface { | ||||
| 	Match(driver.Value) bool | ||||
| } | ||||
|  | ||||
| // an expectation interface | ||||
| type expectation interface { | ||||
| 	fulfilled() bool | ||||
|   | ||||
| @@ -8,13 +8,6 @@ import ( | ||||
| 	"time" | ||||
| ) | ||||
|  | ||||
| type matcher struct { | ||||
| } | ||||
|  | ||||
| func (m matcher) Match(driver.Value) bool { | ||||
| 	return true | ||||
| } | ||||
|  | ||||
| func TestQueryExpectationArgComparison(t *testing.T) { | ||||
| 	e := &queryBasedExpectation{} | ||||
| 	against := []driver.Value{int64(5)} | ||||
| @@ -53,7 +46,7 @@ func TestQueryExpectationArgComparison(t *testing.T) { | ||||
| 		t.Error("arguments should match, but it did not") | ||||
| 	} | ||||
|  | ||||
| 	e.args = []driver.Value{5, matcher{}} | ||||
| 	e.args = []driver.Value{5, AnyArg()} | ||||
| 	if err := e.argsMatches(against); err != nil { | ||||
| 		t.Errorf("arguments should match, but it did not: %s", err) | ||||
| 	} | ||||
|   | ||||
		Reference in New Issue
	
	Block a user