You've already forked go-sqlmock
							
							
				mirror of
				https://github.com/DATA-DOG/go-sqlmock.git
				synced 2025-10-30 23:47:46 +02:00 
			
		
		
		
	add bool type to query arg matcher
This commit is contained in:
		| @@ -358,6 +358,10 @@ func (e *queryBasedExpectation) argsMatches(args []driver.Value) bool { | ||||
| 			if vi.String() != ai.String() { | ||||
| 				return false | ||||
| 			} | ||||
| 		case reflect.Bool: | ||||
| 			if vi.Bool() != ai.Bool() { | ||||
| 				return false | ||||
| 			} | ||||
| 		default: | ||||
| 			// compare types like time.Time based on type only | ||||
| 			if vi.Kind() != ai.Kind() { | ||||
|   | ||||
| @@ -60,8 +60,37 @@ func TestQueryExpectationArgComparison(t *testing.T) { | ||||
| 	} | ||||
| } | ||||
|  | ||||
| func TestQueryExpectationArgComparisonBool(t *testing.T) { | ||||
| 	var e *queryBasedExpectation | ||||
|  | ||||
| 	e = &queryBasedExpectation{args: []driver.Value{true}} | ||||
| 	against := []driver.Value{true} | ||||
| 	if !e.argsMatches(against) { | ||||
| 		t.Error("arguments should match, since arguments are the same") | ||||
| 	} | ||||
|  | ||||
| 	e = &queryBasedExpectation{args: []driver.Value{false}} | ||||
| 	against = []driver.Value{false} | ||||
| 	if !e.argsMatches(against) { | ||||
| 		t.Error("arguments should match, since argument are the same") | ||||
| 	} | ||||
|  | ||||
| 	e = &queryBasedExpectation{args: []driver.Value{true}} | ||||
| 	against = []driver.Value{false} | ||||
| 	if e.argsMatches(against) { | ||||
| 		t.Error("arguments should not match, since argument is different") | ||||
| 	} | ||||
|  | ||||
| 	e = &queryBasedExpectation{args: []driver.Value{false}} | ||||
| 	against = []driver.Value{true} | ||||
| 	if e.argsMatches(against) { | ||||
| 		t.Error("arguments should not match, since argument is different") | ||||
| 	} | ||||
| } | ||||
|  | ||||
| func TestQueryExpectationSqlMatch(t *testing.T) { | ||||
| 	e := &ExpectedExec{} | ||||
|  | ||||
| 	e.sqlRegex = regexp.MustCompile("SELECT x FROM") | ||||
| 	if !e.queryMatches("SELECT x FROM someting") { | ||||
| 		t.Errorf("Sql must have matched the query") | ||||
|   | ||||
		Reference in New Issue
	
	Block a user