@@ -43,13 +43,13 @@ func TestErrorsStrictIgnoreNotes(t *testing.T) {
4343}
4444
4545func TestMySQLErrIs (t * testing.T ) {
46- infraErr := & MySQLError {1234 , "the server is on fire" }
47- otherInfraErr := & MySQLError {1234 , "the datacenter is flooded" }
46+ infraErr := & MySQLError {Number : 1234 , Message : "the server is on fire" }
47+ otherInfraErr := & MySQLError {Number : 1234 , Message : "the datacenter is flooded" }
4848 if ! errors .Is (infraErr , otherInfraErr ) {
4949 t .Errorf ("expected errors to be the same: %+v %+v" , infraErr , otherInfraErr )
5050 }
5151
52- differentCodeErr := & MySQLError {5678 , "the server is on fire" }
52+ differentCodeErr := & MySQLError {Number : 5678 , Message : "the server is on fire" }
5353 if errors .Is (infraErr , differentCodeErr ) {
5454 t .Fatalf ("expected errors to be different: %+v %+v" , infraErr , differentCodeErr )
5555 }
@@ -59,3 +59,22 @@ func TestMySQLErrIs(t *testing.T) {
5959 t .Fatalf ("expected errors to be different: %+v %+v" , infraErr , nonMysqlErr )
6060 }
6161}
62+
63+ func TestMySQLErrIsWithSQLState (t * testing.T ) {
64+ toState := func (s string ) [5 ]byte {
65+ var b [5 ]byte
66+ copy (b [:], s )
67+ return b
68+ }
69+
70+ infraErr := & MySQLError {Number : 1234 , SQLState : toState ("HY000" ), Message : "the server is on fire" }
71+ otherInfraErr := & MySQLError {Number : 1234 , SQLState : toState ("HY000" ), Message : "the datacenter is flooded" }
72+ if ! infraErr .IsWithSQLState (otherInfraErr ) {
73+ t .Errorf ("expected errors to be the same: %+v %+v" , infraErr , otherInfraErr )
74+ }
75+
76+ differentStateErr := & MySQLError {Number : 1234 , SQLState : toState ("45000" ), Message : "the server is on fire" }
77+ if infraErr .IsWithSQLState (differentStateErr ) {
78+ t .Fatalf ("expected errors to be different: %+v %+v" , infraErr , differentStateErr )
79+ }
80+ }
0 commit comments